I am trying to understand the concept of point-free style. I made a function try to add two values using uncurry
.
add = (+) . uncurry
and the result complains:
No instance for (Num ((a0, b0) -> c0))
arising from a use of `+'
Possible fix:
add an instance declaration for (Num ((a0, b0) -> c0))
In the first argument of `(.)', namely `(+)'
In the expression: (+) . uncurry
In an equation for `add': add = (+) . uncurry
Is this a declaration problem? I tried add :: (Int, Int) -> Int
, it is does not work as well.
You should pass (+)
to uncurry
:
add :: (Int, Int) -> Int
add = uncurry (+)
This is because uncurry
is a function that takes a binary function and returns an unary function:
uncurry :: (a -> b -> c) -> ((a, b) -> c)
Your binary function is (+)
which takes two Num
s and sums them up. Therefore uncurry (+)
will transform (+)
into:
(Num, Num) -> Num
which is then restricted by the add
type signature to:
(Int, Int) -> Int