I declared the type declaration by checking it from ghci but loading the module gives error:
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)
Here is my 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]
but when it in ghci it works fine.