Better Records was Re: [Haskell-cafe] Type Directed Name Resolution

Erik Hesselink hesselink at gmail.com
Sat Nov 13 06:14:05 EST 2010


On Fri, Nov 12, 2010 at 22:48, Jonathan Geddes
<geddes.jonathan at gmail.com> wrote:
>> Records do leave quite a bit to be desired. But does anybody actually have a
>> concrete alternative proposal yet?
>
> A few months ago I proposed a couple of extensions [1] on -cafe.

[snip]

>  Consider what this would do for nested updates:
>
>>UpdateTripleInner :: (Inner->Inner) -> MyTriplyNestedRecord -> MyTriplyNestedRecord
>>UpdateTripleInner f = \{inner1 => \{inner2 => \{inner3 => f }}}
>
> I cringe to imagine what the equivalent is in current Haskell syntax.
> Anyone want to try it? Not me!

You can do this very conveniently already using the fclabels package:

updateTrippleInner = modL (inner3 . inner2 . inner1)

Here, inner1/2/3 are not record fields, but Lenses. You have to
construct the lenses themselves, but this is very easy, and can be
automated using Template Haskell.

Other packages like data-accessor have similar functionality.

Erik


More information about the Haskell-Cafe mailing list