[Haskell] extensible records using associated types

Manuel M T Chakravarty chak at cse.unsw.edu.au
Tue Jun 20 11:52:25 EDT 2006

Barney Hilken:
> Similarly, it Lacks all the fields which r Lacks, except for N  
> itself. This is where we really need the ordering :<: to ensure that  
> m is not equal to N. There are two cases, m :<: N:
>  >	instance m :<: N, Lacks m r => Lacks m (N a r) where
>  >		type Extend m b (N a r) = N a (Extend m b r)	
>  >		extend mm y (N x t) = N x (extend mm y t)		
> and N :<: m:
>  >	instance N :<: m => Lacks m (N a r) where
>  >		type Extend m b (N a r) = m b (N a r)
>  >		extend mm y (N x t) = mm y (N x t)	

This is problematic as the instance heads are distinguished only by the
context; ie, both instances are for `Lacks m (N a r)'.  Haskell's
instance selection mechanism (with or without associated types) selects
instances purely by looking at the arguments of the class; hence, you
cannot use instance context as a kind of guard to guide instance


More information about the Haskell mailing list