[Haskell-cafe] record update
Henning Thielemann
schlepptop at henning-thielemann.de
Sat Sep 11 13:53:28 EDT 2010
Jonathan Geddes schrieb:
> I know that record updates is a topic that has become a bit of a dead
> horse, but here I go anyway:
>
> I find that most of the record updates I read and write take the form
>
>> someUpdate :: MyRecord -> MyRecord
>> someUpdate myRecord = myRecord
>> { field1 = f $ field1 myRecord
>> , field2 = g $ field2 myRecord
>> , field3 = h $ filed3 myRecord
>> }
>
> I find myself wishing I could write something more like
>
>> someUpdate :: MyRecord -> MyRecord
>> someUpdate myRecord = myRecord
>> { field1 => f
>> , field2 => g
>> , field3 => h
>> }
data-accessor and similar packages may become your friends.
data-accessor allows you to write:
someUpdate =
(field1 ^: f) .
(field2 ^: g) .
(field3 ^: h)
More information about the Haskell-Cafe
mailing list