forgot to CC list. ---------- Forwarded message ---------- From: David Barbour <[email protected]> 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 <[email protected]>
2011/9/6 Poprádi Árpád <[email protected]> > 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 [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
