(Re-written somewhat in response to comment)
Your line of code:
((add1 multi2) x)
means: apply the add1
function to the argument multi2
, then apply the resulting function to the argument x
. Since adding 1 to a function doesn't make sense, this won't work, so we get a compile-time type error.
The error is explaining that the compiler cannot find a typeclass instance to make functions work like numbers. Numbers must be part of the Num
typeclass so they can be added, multiplied etc.
No instance for (Num (a0 -> a0)
In other words, the type a0-> a0
(which is a function type) doesn't have a Num
typeclass instance, so adding 1 to it fails. This is a compile-time error; the code is never executed, so GHCi cannot print any output from your function.
The type of your wtf
function is:
wtf :: (Num (a -> a), Num a) => a -> a
which says:
- Given that
a
is a numeric type
- and
a -> a
(function) is a numeric type
- then
wtf
will take a number and return a number
The second condition fails at compile time because there's no defined way to treat a function as a number.