[Haskell-cafe] closed classes [was: Re: exceptions vs.
Keith.Wansbrough at cl.cam.ac.uk
Thu Aug 12 05:30:08 EDT 2004
> Just wondering, but what exacly is the problem with this open/closed stuff?
> As far as I understand it new instances can be added to classes in Haskell
> (because they are open)... But its not like instances can be added at link
> time, and all the instances that you wish to be considered _must_ be
> imported into the current module!
Sure it's the case that instances are closed in any given build of a
program. But they're not closed over the (maintenance / extension)
lifetime of that program.
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.
This is just an example of a general principle in language / compiler
design - it's not sufficient that the behaviour be specified, it must
behave predictably from the programmer's point of view; in particular,
local changes shouldn't have global effect. This also comes up in
optimisations - you could write a compiler that recognised occurrences
of bubble sort and replaced them with quicksort, for example, but it
wouldn't be a good idea, because a small change to the code might
cause it to no longer recognise it as bubblesort - with a consequent
asymptotic slowdown that bears no relation to the change just made.
More information about the Haskell-Cafe