ich die Typdeklaration deklariert, indem es von GHCI Überprüfung aber Laden des Moduls gibt Fehler:Könnte erwarteten Typ nicht überein ‚a‘ mit den tatsächlichen Typ ‚Double‘:
even-fibbanaci-sum.hs:7:12: error:
Couldn't match expected type ‘a’ with actual type ‘Double’
‘a’ is a rigid type variable bound by
the type signature for:
getFib :: forall b a. (Integral b, Floating a) => b -> a
at even-fibbanaci-sum.hs:4:12
In the expression: ((phi^n) - (minusphi^n))/sqrt 5
In an equation for ‘getFib’:
getFib n = ((phi^n) - (minusphi^n))/sqrt 5 • Relevant bindings include
getFib :: b -> a (bound at even-fibbanaci-sum.hs:5:1)
Hier ist mein Code
phi = (1 + sqrt 5)/2
minusphi = (1 - sqrt 5)/2
getFib :: (Integral b,Floating a) => b -> a
getFib n = ((phi^n) - (minusphi^n))/sqrt 5
fibSum :: (Integral b,Floating a) => b -> a
fibSum x =sum $ map getFib [2,5..x]
aber wenn es in Ghci funktioniert es gut.