Scoped type variables

Andre Pang ozone at
Sat Dec 18 22:55:00 EST 2004

On 18/12/2004, at 4:51 AM, Simon Peyton-Jones wrote:

> This message is about lexically scoped type variables.  I've gradually
> become convinced that if you write
> 	f :: [a] -> [a]
> 	f x = <body>
> then the type variable 'a' should be in scope in <body>.

I don't have a particularly strong opinion about this, but I've always 
thought that your suggestion is the way it should have been done.  I 
actually find it confusing when someone "re-declares" the type 
variables in the function body; e.g. in your example of ...

> 	f :: [a] -> [a]
> 	f x = my_id x
> 	   where
> 	       my_id :: a -> a
> 	       my_id y = y

I would be very much inclined to use a type signature of "my_id :: b -> 
b", which makes it 100% obvious that it's using a fresh type variable.  
Considering that normal variables are lexically scoped, it seems 
intuitive to me that type variables should also be lexically scoped.

% Andre Pang :

More information about the Glasgow-haskell-users mailing list