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

David Roundy droundy at abridgegame.org
Fri Jan 6 08:03:55 EST 2006

On Thu, Jan 05, 2006 at 11:14:18PM -0800, oleg at pobox.com wrote:
> David Roundy wrote:
> > The only solution I can imagine would be to implement a class for each
> > field name.  i.e. the only reasonble type of f I can imagine is
> > something like
> >
> > f :: Integral i, RecordHasField_foo i r => r -> r
> >
> > But that's a very complicated solution, and once one implemented that
> > solution, one would no longer need to remove the accessor functions
> > (since they could be stuck in the class), which would obsolete this
> > whole idea...
> There is no need to speak of this solution in subjunctive mood. It
> *has* been implemented. If you wish, you can try at right now, with the
> existing GHC (e.g., 6.2, 6.4 or 6.4.1), using the Cabal distribution
> of HList/OOHaskell very kindly made by Einar Karttunen. Here's an example:

I guess I meant to say that it hadn't been implemented for "real" records,
and there doesn't seem to be a consensus that it's the best approach.

> > accessor r f = r # f
> 	*Test> :t accessor
> 	accessor :: (HasField l r v) => r -> l -> v
> Couldn't be any simpler...

Except that this type doesn't allow the accessor to have the same name as
the field, since fields share the function namespace.  Not that we have
much choice here, but it means that this precise approach can't be made
compatible with Haskell 98 as far as I can tell.
David Roundy

More information about the Haskell mailing list