0

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?

szimon
  • 662
  • 1
  • 6
  • 10
  • Can not reproduce with GHC 7.10.2. What version of GHC are you using? The MR should be off by default... (in GHCi) – chi Sep 25 '15 at 09:00
  • 3
    @chi The assumption that people are using ghc7.8+ or 7.10+ is generally false. A lot of people install Haskell from the repositories of their distro. AFAIK Ubuntu is still using [haskell platform 2013](http://packages.ubuntu.com/trusty/haskell-platform) which still uses ghc 7.6.x. I believe the MR is off by default only from 7.8+ – Bakuriu Sep 25 '15 at 12:49

0 Answers0