forgot to CC list. <div><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Barbour</b> <span dir="ltr">&lt;<a href="mailto:dmbarbour@gmail.com">dmbarbour@gmail.com</a>&gt;</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 &lt;<a href="mailto:popradi_arpad@freemail.hu">popradi_arpad@freemail.hu</a>&gt;<br><br>
<br><div class="gmail_quote"><div class="im">2011/9/6 Poprádi Árpád <span dir="ltr">&lt;<a href="mailto:popradi_arpad@freemail.hu" target="_blank">popradi_arpad@freemail.hu</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

But it&#39;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&#39;s HList already provides such mechanisms, so you don&#39;t need to do this yourself. If you&#39;re doing this a lot, try the HList package. (If not, just do the </div>

<div><br></div><div>Also, I would say you&#39;ve too tightly coupled your BigData to the MonadicEnv. I suggest you reduce it instead to:</div><div><br></div><div>  setX :: X -&gt; BigData -&gt; BigData</div><div>  setX x&#39; bd = bd { dataX = x&#39; }</div>

<div><br></div><div>  updX :: (X -&gt; X) -&gt; BigData -&gt; 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&#39;)</div>

<div>  gets dataX</div><div><br></div><div>And use of &#39;updX&#39; is much more composable. </div><div><br></div><div>That aside, from personal experience, I&#39;m usually okay just using:</div><div>  modify (\ s -&gt; s { dataX = x&#39; })</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>