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

MR K P SCHUPKE k.schupke at imperial.ac.uk
Thu Aug 12 06:48:17 EDT 2004

>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.

But there are many ways to do this... and besides this doesn't really make sense...
consider the following:

module A
        defines class X

module B imports class X defines some instances

module C imports A & B

Now, you can add any instance you like to module C and it
is never seen by modules A and B... In other words even
if you assume closed classes you cannot break an existing
module without editing that module or one imported by 
it (in which case you can break _anything_ by deleting
a function)

If you don't allow overlapping instances none of this makes
any difference anyway - closed or open ... (instance selection
cannot change if no instances are allowed to overlap)

Finally if you allow overlapping instances you can break
existing code (without the closed assumption) just by
putting in a more specific instance in a module included
in some module using the more general instance.

Thoughts? What is the problem with assuming all classes are
closed within the available context (imported modules)


More information about the Haskell-Cafe mailing list