Registered: Jun, 2004
Re: Pimp my Library
Posted: Oct 24, 2006 7:32 AM
> But there are things you can't do. For instance if your base library
> produces values of type X you can't make it retroactively produce values
> of some tupe X' which is richer than X, without changing its code (unless
> the library has forseen the extension using factory methods, but that's
> another story).
Depends on what you mean. In SML, assuming you a have module whose signature defines an abstract type X, you can indeed rebind the module with an augmented module that has a richer definition of type X. If you have multiple modules sharing the same abstract types, you can rebind all of them. Of course, such rebinding does not change the meaning of code that refers to the original module.
> > The way I see it, SML is a simple language. Complex or
> > unsafe language features aren't needed to extend libraries.
Perhaps my wording was a bit too strong here.
> Well, I think implicits are neither complex nor unsafe.
Admittedly I don't know Scala (aside from skimming a few papers on it), but I think that combining implicit conversions and mutation is a great way to shoot yourself in the foot. Time will tell.
> Bob Harper, one of the designers of the SML module system, seems to
> agree. He proposes to change the module system in order to allow it to
> simulate Haskell's type classes. The proposal is very close to Scala's
I'm aware of the work. I'm personally not too enthusiastic about it. I think that there are far more important extensions (e.g. higher-order functors, higher-rank polymorphism, polymorphic recursion, ...) that should be considered/added to SML before anything like implicits or type classes that add an additional level of magic to the language. It is a good thing that the behaviour of SML programs can be explained without preprocessing or translating the program to some elaborated from (well, almost). Adding type classes destroys that property (you then need something like the dictionary translation).