[Haskell-cafe] Type inference
cgibbard at gmail.com
Thu Feb 9 02:47:16 EST 2006
On 09/02/06, Brian Hulley <brianh at metamilk.com> wrote:
> Brian Hulley wrote:
> > Brian Hulley wrote:
> >> Brian Hulley wrote:
> >>> f :: (forall a m. a -> m a) -> c -> d -> (m c, m d)
> >> The above is wrong - there is no way to quantify m properly. This
> >> must be why intersection types need to be written with "&" after
> >> all....
> > What am I saying! It's right after all, and might be better than the &
> > syntax because it makes the dependency clearer (assuming you can't
> > write a function that is both Int->String and Float->Int)
> Last correction!
> f :: forall m. (forall a. a->m a) -> c -> d -> (m c, m d)
> Sorry for all this confusion.
Of course this type doesn't work on your original example, since (,)
is a type constructor with two parameters, not one, but this type
signature does actually work just fine in GHC.
data Pair x = Pair x x deriving Show
data Id x = Id x deriving Show
f :: forall m c d. (forall a. a -> m a) -> c -> d -> (m c, m d)
f g x y = (g x, g y)
*Main> f (\x -> Pair x x) 3 "hello"
(Pair 3 3,Pair "hello" "hello")
*Main> f (\x -> Id x) 3 "hello"
(Id 3,Id "hello")
More information about the Haskell-Cafe