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

John Goerzen jgoerzen at complete.org
Wed Jan 4 11:54:10 EST 2006


On 2006-01-04, David Roundy <droundy at abridgegame.org> wrote:
> On Wed, Jan 04, 2006 at 02:17:27PM +0000, John Goerzen wrote:
> 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 have a lot of code where I rarely need to update records but
frequently need to access them.  For instance:

http://darcs.complete.org/hdbc/doc/Database-HDBC.html

Most of the functions here, such as fetchRow, are
automatically-generated accessor functions.  In the public API, record
is represented by an abstract type.  But in the API exposed to driver
developers:

http://darcs.complete.org/hdbc/doc/Database-HDBC-Types.html

You can see it all at work.

Having all these functions automatically-generated is very helpful here,
and the fact that one can expose the function without the underlying
datatype is also handy.  That means, for instance, that end users need
not know that fetchRow is provided by driver implementors while
fetchAllRows is a generic function implemented in terms of lower-level
ones.  It all looks the same to them.

It also means that this internal detail can be adjusted without breaking
source compatibility with applications.

And it also means that I don't have to waste time writing two dozen
accessor functions, carefully counting the underscores each time.

> 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
> module.

I think that the existing default is a good one, really.  I could see
myself turning on that pragma for everything I write, globally, if it
came to that.

-- John



More information about the Haskell mailing list