
11 Sep
2010
11 Sep
'10
3:45 p.m.
On Sat, 11 Sep 2010, Stephen Tetley wrote:
On 11 September 2010 18:21, Jonathan Geddes
wrote: someUpdate :: MyRecord -> MyRecord someUpdate myRecord = myRecord { field1 = f $ field1 myRecord , field2 = g $ field2 myRecord , field3 = h $ filed3 myRecord }
Applicatively, using no additional libraries, is how I do it:
updateAllThree :: MyRecord -> MyRecord updateAllThree = (\s a b c -> s { field1 = f a, field2 = g b, field3 = h c}) <*> field1 <*> field2 <*> field3
Cute!
Note - (<$>) is not used, and the left hand function has one extra argument. This style exploits the fact that (<*>) is the Startling (S) combinator.
It uses the Applicative instance for functions.