On Sat, 11 Sep 2010, Stephen Tetley wrote:

On 11 September 2010 18:21, Jonathan Geddes <geddes.jonat...@gmail.com> 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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to