Records in Haskell
strake888 at gmail.com
Thu Jan 19 04:35:40 CET 2012
On 18/01/2012, Simon Peyton-Jones <simonpj at microsoft.com> wrote:
> | > 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.
Yes. This is a fault.
I found a document, "Controlling the scope of instances in Haskell",
by Gontijo and Camarão, whose goal is to solve this very problem.
The link seems broken, but if so, and anyone should want a copy, feel
free to tell me and I shall send it. The size is 244 KB.
> 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