Comparing instance heads

Simon Peyton-Jones simonpj at microsoft.com
Thu Nov 19 05:23:56 EST 2009


| To be more precise, I want to know if an HsDecl.InstDecl and an
| InstEnv.Instance represent the same instance.

Sorry David, your msg has been lurking a while in my inbox, because I couldn't figure out exactly what you were asking. Rather than no-oping I should have asked.

Anyway your revised qn is much clearer!  Yes, 
 * the SrcSpan of 
 * the Name of 
 * the is_dfun of
 * an InstEnv.Instance
is definitely supposed to point to the defining instance declaration.

I have not been terribly careful about *exactly* what this SrcSpan is.  Look for 'mkLocalInstance' to see examples.  For a vanilla instance decl, the SrcSpan is the SrcSpan of the type in the instance decl.  Eg if you said
	instance
         Foo a => Foo [a] 
       where ...
I think you'd get the SrcSpan of the "Foo a => Foo [a]" part. 

I was careful not to take the SrcSpan of the entire instance because that seems less precise.

For instances coming from 'deriving' I'm not sure precisely what SrcSpan you get.


The details could easily be changed. Regardless, once you've decided, please add a Note to InstEnv.lhs to say what you rely on about the SrcSpan of a is_dfun.  

Simon



More information about the Cvs-ghc mailing list