accumulate :: (a -> a) -> a -> (a -> a) -> a -> (a -> a) -> a
accumulate combiner null_value term x next n = iter x null_value
where iter x result = if x > n
then result
else iter (next x) (combiner (term x) result)
This runs perfectly without the type signature, but with the type signature, I keep running into this error:
Couldn't match expected type `a' with actual type `a -> a'
`a' is a rigid type variable bound by
the type signature for
accumulate :: (a -> a) -> a -> (a -> a) -> a -> (a -> a) -> a
at haskell-sicp/chapter1.hs:131:15
In the expression: iter x null_value
In an equation for `accumulate':
accumulate combiner null_value term x next n
= iter x null_value
where
iter x result
= if x > n then
result
else
iter (next x) (combiner (term x) result)
I'm new to haskell, but I don't understand what is wrong with my type signature?
:t) and then try to understand how it fits there.>you will need anOrdconstraint.