RE: duplicate instance declarations
Two instances are duplicates if their 'head' (the part after the =>) 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 instance C a => X a where ... instance D a => 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. Simon | -----Original Message----- | From: Hal Daume III [mailto:hdaume@ISI.EDU] | Sent: 03 May 2002 18:33 | To: C T McBride | Cc: Haskell Mailing List | Subject: Re: duplicate instance declarations | | | Cool, thanks, that made sense. | | > [lots of stuff snipped] | | What's the difference, then, between "duplicate instances" | and "overlapping" instances? It seems that even with | -fallow-overlapping-instances and even | -fallow-undecidable-instances ghc still rejects the code I had. | | _______________________________________________ | Haskell mailing list | Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell |
participants (1)
-
Simon Peyton-Jones