Records in Haskell

Simon Peyton-Jones simonpj at
Wed Jan 18 14:24:07 CET 2012

| > Has *is* a type class. It can be used and abused like any other.
| > Record members with the same key ought to have the same semantics; the
| > programmer must ensure this, not just call them all "x" or the like.
| >
| > Weak types these are not. The selector type is well-defined. The value
| > type is well-defined. The record type is well-defined, but of course
| > we define a type-class to let it be polymorphic.

I want to mention that the issue Greg raises here is tackled under "Representation hiding".  

The way we currently prevent random clients of a data type from selecting its "foo" field is by hiding the record selector "foo". Similarly for its data constructors. This is Haskell's way of doing data abstraction; it may not be the best way, but it's Haskell's way.

The trouble with instance declarations is that they are *always* exported.  No hiding.

Under "Representation hiding" I suggest that 

* If the record selector "foo" is in scope (by any name), 
  then the corresponding Has instance is in scope too
  and vice versa.

That would match up with Haskell's hiding mechanisms precisely, albeit at the cost of having an ad-hoc rule for "Has" instances.


More information about the Glasgow-haskell-users mailing list