I'm a little confused by types returned by curry
and uncurry
functions:
Prelude> let pairMax (a,b) = if a > b then a else b
Prelude> :t pairMax
pairMax :: Ord a => (a, a) -> a
Prelude> let pairMaxCurried = curry pairMax
Prelude> :t pairMaxCurried
pairMaxCurried :: () -> () -> ()
I don't understand why the curried function's type consists only of Unit types. Trying to apply pairMaxCurried
unsurprisingly results in an error:
Prelude> pairMaxCurried 1 2
<interactive>:10:16:
No instance for (Num ()) arising from the literal `1'
Possible fix: add an instance declaration for (Num ())
In the first argument of `pairMaxCurried', namely `1'
In the expression: pairMaxCurried 1 2
In an equation for `it': it = pairMaxCurried 1 2
while currying and applying in the same line is fine:
Prelude> (curry pairMax) 1 2
2
The same goes for uncurry
:
Prelude> let twoMax a b = if a > b then a else b
Prelude> :t twoMax
twoMax :: Ord a => a -> a -> a
Prelude> let twoMaxUncurried = uncurry twoMax
Prelude> :t twoMaxUncurried
twoMaxUncurried :: ((), ()) -> ()
Declaring explicit type doesn't help:
Prelude> let pairMaxCurried = (curry pairMax) :: Ord a => a -> a -> a
Prelude> :t pairMaxCurried
pairMaxCurried :: () -> () -> ()
Question 1. Why is the type not correctly inferred?
Question 2. Is there a way to bind curried/uncurried function to a name while preserving the correct type?