[PL-sem-jr] Re: type classes experts, help me with SYB/C

Jesse A. Tov tov at ccs.neu.edu
Mon Oct 24 01:53:43 EDT 2005


Felix S Klock II wrote:
>> gmapQ :: Data a => (forall b. Data b => b -> r) -> a -> [r]
> 
> and the first argument to gmapQ "has access to the operations of the  
> Data class (and its supercalsses) but no more", so gsize is not an  
> acceptable argument there.

It's definitely counterintuitive.  Don't put a lot of stock in any of this.

gmapQ has a rank-2 type, which suggests that it's going to use that 
first argument at more than one type.  (In fact it does.)  In each place 
that argument is used, the correct Data dictionary is selected, because 
gmapQ is prepared to do that.  However, gsize is going to need a Size 
dictionary.  gmapQ knows nothing about Size, so it can't provide the 
correct Size dictionary for each use in gmapQ.  Does that make sense?

That's an explanation in terms of the dictionary translation; you might 
also try to understand it by looking at GHC's rules for rank-n types, 
and how they interact with context reduction.  (Peyton Jones and 
Shields, "Practical type inference for arbitrary-rank types," might be 
helpful.)

Jesse



More information about the Pl-sem-jr mailing list