
27 Oct
2006
27 Oct
'06
1:41 p.m.
Greg Buchholz wrote:
I'm not quite sure why this is illegal...
foo :: Integer -> (forall a. Show a => a) foo 2 = ["foo"] foo x = x
...while this is just fine...
bar :: Integer -> (forall a. Show a => a->b) -> b bar 2 k = k ["bar"] bar x k = k x
The way to think about it is that foralls are extra function arguments. Your first example is like foo :: Integer -> (a::Type -> Show a -> a) so a is chosen by the caller, not by you. The second case is like bar :: Integer -> (a::Type -> Show a -> a -> b) -> b In order for the first case to work as you expect, you'd need the type foo :: Integer -> (a::Type, Show a, a) which is traditionally written foo :: Integer -> (exists a. Show a => a) -- Ben