[Haskell-cafe] Capitalization and associated type families

Brian Hulley brianh at metamilk.com
Tue Aug 5 15:22:23 EDT 2008


Tillmann Rendel wrote:
> Brian Hulley wrote:
> 
>>     class Foo a where
>>
>>         f :: a -> b -> (a, b)
>>
>> Here there is no capitalization distinction in the type of (f) but the 
>> implementation can still insert the "forall b." since (a) is already 
>> in scope. Therefore similarly, if type constructors like "List" were 
>> instead written using lowercase, since they would already be in scope 
>> it would be clear even without explicit quantifiers that (a) and (b), 
>> but not (list), were to be quantified in the type of (map) (assuming 
>> of course that there was no top level data decl for (a) or (b)).
> 
> So adding b to the export list of an imported module would change the 
> type of f?

Yes, if the module in which the above class decl were defined imported a 
data type (b) from some other module (or defined it elsewhere in the 
same module) then (f)'s type would change. (Of course at the moment this 
can't happen because (b) is lowercase so it can't be introduced by 
data/type decls or imported/exported.)

The type of (f) would also change if Haskell were extended to support 
nested classes:

	class Bar b where
		class Foo a where
			f :: a -> b -> (a, b)

But as Jonathan pointed out this behaviour is not really all that ideal 
since even in Haskell at the moment a simple spelling mistake could 
cause silent quantification instead of an error (which is perhaps the 
main justification for why constructors introduced by data/type decls 
must currently be capitalized -- unfortunately there is no corresponding 
protection when writing types inside class decls):

	class Zap aaaaa where
		g :: aaaaa -> aaaa
				^ oops!
Cheers -
Brian.


More information about the Haskell-Cafe mailing list