
Magicloud Magiclouds wrote
In OOP, when I inherit a class, I also got the members of it. But in haskell, how to inherit a "data"?
Although any OOP system has by definition, objects, not all of them have classes. The best example of a classless (also called 1-level, or prototype-based) OO system is Self, which is still alive. An object is essentially a record of data members. An extended object (an object of an extended class, for a class-based OOP) is an extended record. They could be quite convenient: we can add a new field to an existing record without re-writing the complete declaration and re-using lots of the functions that dealt with the old records. The old code would just work on extended records, ignoring the added field. (I am simplifying a bit.) Lots has been written about extensible records in Haskell; some techniques (such as parameterizing a record type by a tail) have been rediscovered several times. Still a good survey of many various ways to implement extensible records in Haskell is Section 3 of http://homepages.cwi.nl/~ralf/OOHaskell/paper.pdf It is long, as everything else in that paper.