unfold :: (t -> Bool) -> (t -> a) -> (t -> t) -> t -> [a]
unfold p f g x
| p x = []
| otherwise = f x : unfold p f g (g x)
This is the function I am currently working with. It is basically a function that "unfolds" the argument x and uses two functions and a predicate to determine when the list is supposed to end. Inserting:
unfold (>100) (+6) (+6) 2
>> [8,14,20,26,32,38,44,50,56,62,68,74,80,86,92,98,104]
That output is fine an right. But when I try:
unfold (>100) (+6) (-6) 2
<interactive>:55:1: error:
• Non type-variable argument in the constraint: Num (a -> a)
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a. (Num (a -> a), Num a, Ord a) => [a]
I recieve this error. I tried finding other examples with this error, but those didn't really help me. Do any of you know a solution for that?