Keep the present Haskell record system!
waldmann at imn.htwk-leipzig.de
Mon Mar 6 04:13:18 EST 2006
With respect to the discussion on records, let me throw in
my usual warning: all of this seems overly obsessed
with concrete representations of data types.
The representation should not be exposed in the first place:
you don't want to access it (=> make all fields private)
you don't want to extend it (=> implementation inheritance is bad,
interface inheritance is good.) (read e. g. Introduction to
Design Patterns by Gamma et al.)
You think it is a win to be able to write a function
that takes "everything that has a foo :: Foo component"?
I think it is not, since it is not robust design.
It will only take records, and components have to be components.
What if you later change the type's representation from a record to
something else? If you change the component to a function?
If you want a reliable notion of "everything that has a foo :: Foo",
then you need to declare an interface (erm, one parameter type class).
My point is that the OO community has learned all this stuff the hard
way (from software problems arising from naive use of objects and
inheritance), and it has taken them years, if not decades, and now it
looks as if we are going to joyfully repeat this whole process.
An important selling point of the records proposal seems to be
that you don't have to declare a type name for a record type.
While I don't buy this whole idea (we have a declarative programming
language but we want to avoid (type) declarations?) I see a concrete
problem: what if you want to make such a nameless type an instance
of some type class? Then we get all sorts of overlappings.
So with respect to the original post (see the subject of this email)
I tend to agree: leave records as they are. Of course they are
problematic, but the main reason is not missing extensibility.
As I see it, the problem is that the named component notation was added
late and still allows to access the earlier positional notation,
and the component names are in the (module-global) namespace.
This would be more tolerable if we had ad-hoc overloading.
Since we haven't, I'm now basically putting each data declaration
in a separate module and import these qualified.
(This simulates the "per-type" namespace for components.)
-- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
---- http://www.imn.htwk-leipzig.de/~waldmann/ -------
More information about the Haskell-prime