duplicate instance declarations

Simon Peyton-Jones simonpj@microsoft.com
Thu, 9 May 2002 00:48:17 -0700


Two instances are duplicates if their 'head' (the part after the =3D>) =
is
identical,
modulo alpha renaming.

Even with overlapping instances allowed, GHC never makes an arbitrary
choice between two instance decls.  It choses one over the other only if
its head is more specific (i.e. a substitution instance).  This will
never happen
in the case of duplicate instance decls, so GHC rejects duplicates up
front.

GHC's resolution of overlapping instances does not use backtracking, so
it is quite weak.  For example
=09
	instance C a =3D> X a where ...
	instance D a =3D> X a where ...

You might think that if a type T is an instance of C but not D, then it
would
be clear which of these two instances to use to resolve the constraint
(X T),
but GHC does not spot that.  It uses only the instance head.

I hope this clarifies a bit. =20

Simon

| -----Original Message-----
| From: Hal Daume III [mailto:hdaume@ISI.EDU]=20
| Sent: 03 May 2002 18:33
| To: C T McBride
| Cc: Haskell Mailing List
| Subject: Re: duplicate instance declarations
|=20
|=20
| Cool, thanks, that made sense.
|=20
| > [lots of stuff snipped]
|=20
| What's the difference, then, between "duplicate instances"=20
| and "overlapping" instances?  It seems that even with=20
| -fallow-overlapping-instances and even=20
| -fallow-undecidable-instances ghc still rejects the code I had.
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20