Fwd: Is there any way to parametrize a value update using record syntax?

forgot to CC list.
---------- Forwarded message ----------
From: David Barbour
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.

Hi David, thank You for your suggestions but the usage of fclabes is much better for me (otherwise it uses template haskell inside too). Some benefits: - It has a nice example for usage. - Not even a little wrapper is needed to make a get (or set) with a record field. You can use the field name directly for both direction (get and set). - It's prepared for usage in a state monad. - A record field is represented with a value (and a type) so you can easily compose it (one of the main problem with haskell's original record field syntax). Thanks, Árpád On Tue, 2011-09-06 at 14:55 -0700, David Barbour wrote:
forgot to CC list.
---------- Forwarded message ---------- From: David Barbour
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 2011/9/6 Poprádi Árpád
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (2)
-
David Barbour
-
Poprádi Árpád