forall a (Ord a => a-> a) -> Int is an illegal type???

Brian Hulley brianh at metamilk.com
Thu Feb 9 19:04:10 EST 2006


Ben Rudiak-Gould wrote:
> Brian Hulley wrote:
>> I'm puzzled why GHC chooses to create illegal types instead  of
>> finding the innermost quantification point ie I would think that
>>
>>         (Ord a=> a->a) -> Int
>>
>> should then "obviously" be shorthand for
>>
>>          (forall a. Ord a=> a->a) -> Int
>>
>> and surely this could easily be implemented by just prepending
>> "forall a b c" onto any context restricting a b c... (?)
>
> I agree that it's strange to add an implicit quantifier and then
> complain that it's in the wrong place. I suspect Simon would change
> this behavior if you complained about it. My preferred behavior,
> though, would be to reject any type that has a forall-less type class
> constraint anywhere but at the very beginning. I don't think it's a
> good idea to expand implicit quantification. Also, the rule would not
> be quite as simple as you make it out to be, since
>
>     forall a. (forall b. Foo a b => a -> b) -> Int
>
> is a legal type, for example.

This is what I still don't understand: how the above could be a legal type. 
Surely it introduces 'a' to be anything, and then later retricts 'a' to be 
related to 'b' via the typeclass 'Foo' ?

I would have thought only the following would be legal:

        f :: (forall a b. Foo a b => a->b) -> Int

In other words, in:

       f :: forall a. (forall b. Foo a b => a->b) -> Int
       f g = ...

how can 'f' pass the dictionary 'Foo a b' to g when 'f' can only choose 'b' 
but doesn't know anything about 'a'? Where does it get this dictionary from?

Regards, Brian. 



More information about the Glasgow-haskell-users mailing list