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

Brian Hulley brianh at metamilk.com
Thu Feb 9 03:22:55 EST 2006


Bulat Ziganshin wrote:
> Hello Brian,
>
> Thursday, February 09, 2006, 9:38:35 AM, you wrote:
>
>>> the past few months (!) and still can't understand why the following
>>> is an illegal type:
>>>
>>> forall a. ((Ord a => a-> a) -> Int)
>
> i don't know right answer burt may be because "Ord a" restriction and
> "forall a" )"dseclaration" of type variable) should be at the same
> "level". imagine the following declaration:
>
> forall a. (Int -> (Ord a => a)) -> Int)
>
> it is not good to write restriction on some deep level instead of
> right together with "declaration"

Thanks! If I understand you correctly, I should think of the "Ord" as being 
part of the "forall" quantifier, so that

       forall a. Ord a =>

is really to be thought of as something like:

      forall_that_is_Ord a =>

and of course quantifiers can't be split up into pieces that are distributed 
all over the place...

If so, then I think I understand it all now, though 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... (?)

Regards, Brian. 



More information about the Glasgow-haskell-users mailing list