[Haskell-cafe] Strange context reduction with partial application and casting

Wonchan Lee wclee at ropas.snu.ac.kr
Sat Jul 2 20:23:48 CEST 2011


Hi cafe,

I found some strange phenomenon when I was hanging around with GHCi.
Please see the following interaction:

GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> let f a b c d = a == b && c == d
Prelude> :t f
f :: (Eq a, Eq a1) => a -> a -> a1 -> a1 -> Bool
Prelude> let g = f 1
Prelude> :t g
g :: Integer -> () -> () -> Bool

Here I expect that the type of g is (Eq a) => Integer -> a -> a -> Bool.
But suddenly all the context in the type is gone and I have some
strange thing with unit type in it.
I tried another example to get what I expected at the first time:

Prelude> let g = f :: (Eq a) => Int -> Int -> a -> a -> Bool
Prelude> :t g
g :: Int -> Int -> () -> () -> Bool

The resulting type was different from one that I want to cast into.
I know that Haskell tries to reduce the context in the type when
there's sufficient information to do it.
However, this goes too far from what I think normal.

Is this intended behavior or just a bug?



More information about the Haskell-Cafe mailing list