[Haskell-cafe] Is there any way to parametrize a value update using record syntax?

Brandon Allbery allbery.b at gmail.com
Tue Sep 6 22:56:40 CEST 2011


2011/9/6 Poprádi Árpád <popradi_arpad at freemail.hu>

> updateData1 :: X -> MonadicEnv()
> updateData1 d = do; env <- get; put env {data1 = d}
>

> updateData1 d = modify (\r -> r {data1 = d})

But there is, sadly, no eta-reduced version of record update to make the "\r
-> r ..." boilerplate go away; recognition of the syntax requires an
expression before the braces.  (Consider the ambiguity of the eta-reduced
expression "modify {data1 = d}".)  Also, and much more annoyingly, "data1"
must be constant.

If you can decipher the documentation, there are several alternative record
packages on Hackage based on functional lenses.  Also there are packages
which use Template Haskell to automate the above.

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110906/4ef360de/attachment.htm>


More information about the Haskell-Cafe mailing list