[Haskell-cafe] Fwd: Is there any way to parametrize a value update using record syntax?
David Barbour
dmbarbour at gmail.com
Tue Sep 6 23:55:22 CEST 2011
forgot to CC list.
---------- Forwarded message ----------
From: David Barbour <dmbarbour at gmail.com>
Date: 2011/9/6
Subject: Re: [Haskell-cafe] Is there any way to parametrize a value update
using record syntax?
To: Poprádi Árpád <popradi_arpad at freemail.hu>
2011/9/6 Poprádi Árpád <popradi_arpad at freemail.hu>
> But it's ugly. Always the same, only the record selector has another
> name. Is it possible to generalize it?
>
You can generalize using template haskell. I believe Oleg's HList already
provides such mechanisms, so you don't need to do this yourself. If you're
doing this a lot, try the HList package. (If not, just do the
Also, I would say you've too tightly coupled your BigData to the MonadicEnv.
I suggest you reduce it instead to:
setX :: X -> BigData -> BigData
setX x' bd = bd { dataX = x' }
updX :: (X -> X) -> BigData -> BigData
updX fx bd = bd { dataX = fx (dataX bd) }
Then in your state monad you can use:
modify (setX x')
gets dataX
And use of 'updX' is much more composable.
That aside, from personal experience, I'm usually okay just using:
modify (\ s -> s { dataX = x' })
in the few places I need it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110906/48e73a98/attachment.htm>
More information about the Haskell-Cafe
mailing list