[Haskell] A problem with overlapping instances and super-classes

Claus Reinke claus.reinke at talk21.com
Mon Jun 9 07:35:56 EDT 2008


> This isn't great, but it's not really different than is the case for
> non-overlapping instances.  Suppose module B1 declares 'instance C T',
> and uses that instance; and module B2 declares a *different* 'instance
> C T', and uses that instance; and Main imports B1 and B2, but does not
> use either instance directly.  Then GHC will compile the program
> without complaint, although it is incoherent.

does this bug have a ticket?

> The only way I know to fix this would be to keep a history of all
> instance-decl matches performed during compilation, and check that
> they are still unique matches even when all instance decls in the
> program are taken into account. Or, to put it another (less modular)
> way: first find all instance decls, and only then compile the program.
> But this destroys modular compilation.

why would this destroy modular compilation? compiling each of B1 and B2
on its own is still fine, and compiling Main does not have to report
whether or not B1 or B2 have used their own instances. compiling Main
should report, however, that there are now two instances for C T in
scope. the same applies to overlaps and functional dependencies -
compilation of class instances is accumulative, and compilation of
importing modules might lead to conflict reports in the accumulated
instances.

claus





More information about the Haskell mailing list