forgot to CC list. <div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Barbour</b> <span dir="ltr"><<a href="mailto:dmbarbour@gmail.com">dmbarbour@gmail.com</a>></span><br>
Date: 2011/9/6<br>Subject: Re: [Haskell-cafe] Is there any way to parametrize a value update using record syntax?<br>To: Poprádi Árpád <<a href="mailto:popradi_arpad@freemail.hu">popradi_arpad@freemail.hu</a>><br><br>
<br><div class="gmail_quote"><div class="im">2011/9/6 Poprádi Árpád <span dir="ltr"><<a href="mailto:popradi_arpad@freemail.hu" target="_blank">popradi_arpad@freemail.hu</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But it's ugly. Always the same, only the record selector has another<br>
name. Is it possible to generalize it?<br></blockquote><div><br></div></div><div>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 </div>
<div><br></div><div>Also, I would say you've too tightly coupled your BigData to the MonadicEnv. I suggest you reduce it instead to:</div><div><br></div><div> setX :: X -> BigData -> BigData</div><div> setX x' bd = bd { dataX = x' }</div>
<div><br></div><div> updX :: (X -> X) -> BigData -> BigData</div><div> updX fx bd = bd { dataX = fx (dataX bd) }</div><div><br></div><div>Then in your state monad you can use:</div><div> modify (setX x')</div>
<div> gets dataX</div><div><br></div><div>And use of 'updX' is much more composable. </div><div><br></div><div>That aside, from personal experience, I'm usually okay just using:</div><div> modify (\ s -> s { dataX = x' })</div>
<div><br></div><div>in the few places I need it. </div><div><br></div><div><br></div><div><br></div></div>
</div><br></div>