I have a custom data type Flist
containing functions. In the next step I would like to use the Flist myFunctions
in apply
.
Note: This is an exercise, so I have to use a custom list
data Flist a = Nil | Cons (a -> a) (Flist a)
myFunctions :: Flist (Integer -> Integer)
myFunctions = (Cons (\y x -> x + 1) ( Cons (\x w -> w + 1) (Nil)))
apply :: Flist (a -> a) -> b -> b
apply Nil b = b
apply (f `Cons` xs) b = apply xs (f b)
The call should look like that: apply myFunctions 1
returns 3
I get the error:
- No instance for (Num (Integer -> Integer)) arising from the literal `2' (maybe you haven't applied a function to enough arguments?)
- In the second argument of 'apply', namely '2' In the expression: apply myFunctions 2 In an equation for 'it': it = apply myFunctions 2
Question: I do not see my mistake. Why should I have applied not enough arguments to the function? I pass a Flist with functions that get an Int and return an Int. Additionally another Int is passed and that should be it. What is still missing here?
Flist a
containsa -> a
functions, what doesFlist (x->y)
contain? Regardless... you shouldn't have run into the error you quote, you should have earlier run into a clearer to understand error when compilingapply
. Let me guess: you didn't compile it with the type signature? Bad idea... – leftaroundabout