Scoped type variables

Olaf Chitil O.Chitil at kent.ac.uk
Sun Dec 19 08:22:33 EST 2004


>I'm not sure I understand the objection raised by Jon; the 'implicit
>declaration' of type variables in type signatures has never bothered
>me, and in fact seems quite similar to how names for values don't have
>to be declared beforehand but are brought into scope by the binding
>(which I also have no problem with).
>  
>

The binding of a variable is the declaration of the variable. In 
contrast, type variables are never declared in Haskell 98, they are only 
used. In my opinion this lack of an explicit type variable quantifier is 
just acceptable, because all type variables are universally quantified 
and their scope is just the type in which they appear. The very moment 
you allow for wider scopes of type variables the disadvantage of the 
lacking type variable quantifier becomes appearant:

When you see
    f :: a -> a
somewhere within an inner "where" clause you do not know at all if this 
means
    f :: forall a. a -> a
or the "a" is actually quantified somewhere outside and hence "f" has a 
far more restricted type (because Haskell does not even require you to 
write a type signature next to its variable binding, you have to search 
the *whole* module to find out).

So scoped type variables do not fit Haskell well anyway, but I think 
when added they should at least be an upward compatible extension; any 
Haskell 98 program should still be correct. Hence I support Jon in that 
ghc should only allow those type variables a wider scope that have been 
explicitly declared with the non-Haskell 98 keyword "forall".

Olaf


More information about the Glasgow-haskell-users mailing list