[Haskell-cafe] known, I know: class contexts and mutual recursion

Ross Paterson ross at soi.city.ac.uk
Mon Dec 4 13:11:31 EST 2006

On Mon, Dec 04, 2006 at 05:21:15PM +0000, Ian Lynagh wrote:
> On Wed, Nov 29, 2006 at 06:14:56PM +0000, Conor McBride wrote:
> > 
> > Mmm.lhs:15:1:
> >   Contexts differ in length
> >   When matching the contexts of the signatures for
> >     foo :: forall (m :: * -> *). (Monad m) => Thing -> m Int
> >     goo :: Thing -> (Maybe Int -> Int) -> Int
> >   The signature contexts in a mutually recursive group should all be 
> > identical
> > 
> > Poking about on the web, I got the impression that this was a known 
> > infelicity in ghc 6.4 (which I'm using), due to be ironed out. However, 
> > an early-adopting colleague with 6.6 alleges that foo-goo is still 
> > poisonous.
> You can compile it with 6.6 if you use -fglasgow-exts. It's not clear to
> me whether this will always work, e.g. if you have higher rank types
> floating around, but if it does then we should add a hint to the error;
> Simon?
> > I'm wondering what the story is. I mean, is there some nasty 
> > problem lurking here which prevents the lifting of this peculiar 
> > restriction?
> I don't know either, but this sounds like a good thing to bring up for
> Haskell' if no-one has already.

Haskell 98 mandates this behaviour: s4.5.2 says the types of all functions
in a dependency group must have the same context, even if they have
explicit signatures.

Haskell' ticket #65 (RelaxedDependencyAnalysis) proposes that dependencies
on variables with explicit signatures should be ignored by the dependency
analysis.  With that change, if you provided signatures for foo or goo,
or both, they'd be in different dependency groups and not required to
have the same context.  One could argue that this change should have
been made when polymorphic recursion was permitted.

More information about the Haskell-Cafe mailing list