[Haskell-cafe] closed classes [was: Re: exceptions vs. Either]

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Thu Aug 12 08:47:33 EDT 2004

W liście z czw, 12-08-2004, godz. 10:30 +0100, Keith Wansbrough napisał:

> If the compiler treated instances as closed in this way, then adding a
> new instance to the program could break existing parts of the program.
> This would be a development nightmare.

Well, this is already possible due to conflicting instances.

It implies a guideline that a library should only add instances for
classes it defines itself, or for types it defines itself. With
multiparameter classes it suffices that at least one of the types
from the instance head is new.

All other cases should be carefully examined to see if the instance is
appropriate, in particular if it's indeed the only "right" instance for
this class/types combination. If that's right, the instances should be
clearly announced in the documentation, and preferably defined in a
separate module to be imported optionally.

This increases the chance that anybody wishing to make a similar
instance will know about that module, and if he still wants to make
a separate instance, then both libraries can be linked together.

This is only a guideline, not a hard requirement.

   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/

More information about the Haskell-Cafe mailing list