[Haskell] Re: (small) records proposal for Haskell '06

David Roundy droundy at abridgegame.org
Wed Jan 4 10:40:12 EST 2006

On Wed, Jan 04, 2006 at 02:17:27PM +0000, John Goerzen wrote:
> On 2006-01-02, David Roundy <droundy at abridgegame.org> wrote:
> > My proposal is simply to remove the automatic declaration of accessor
> > functions.  In Haskell 98,
> >
> > data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }
> I would find this to be incredibly annoying.  The fact that these
> accessor functions exist automatically is, IMHO, one of the very nice
> things about Haskell records.  I have nightmares of manually coding up
> hundreds of get* and set* functions in Java from your proposal ;-)

Haskell 98 already requires you to code up set* functions (provided you
want them), so I'd only be doubling the amount of work you need to do.  If
you can get by with the existing non-function update syntax, then you can
also get by with pattern matching to access record contents.

> I also would consider it a bug to have something so annoying that a
> code-generation tool is required to work with it sanely.

That's why it would only be good as an interim measure, and why you'd need
the pragma to revert to Haskell 98 behavior for records defined in a given

> Perhaps there is another approach.  In your example, perhaps we could
> have:
> class FooClass a where
>     foo :: a -> Int
> instance FooClass Foo where
>    foo (Foo x) = x
> instance FooClas FooBar where
>    foo (FooBar x) = x
> I don't know if compilers can do this automatically, but by importing
> modules qualified, you can do this in Haskell today.

This is one of the proposed solutions that I'd like to make possible
(although I've forgotten who proposed this particular one).  The problem is
that it's not compatible with Haskell 98, and noone seems interested in
actually coding up an incompatible language dialect to experiment with
improvements to the records system.
David Roundy

More information about the Haskell mailing list