<div dir="ltr">You can use `makeFields` from the `lens` package to get something like:<br><br>someData ^. field1 . field2<br><br>along with modifiers:<br><br>someData & field1 . field2 %~ (* 2)<br><br>and setters:<br><br>someData & field1 . field2 .~ 42<br><br>where `field1` is polymorphic and can apply to many different data types</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Matt Parsons</div></div></div></div>
<br><div class="gmail_quote">On Mon, May 14, 2018 at 6:41 PM, Dennis Raddle <span dir="ltr"><<a href="mailto:dennis.raddle@gmail.com" target="_blank">dennis.raddle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>In my current application, I'm really missing the ability from OO to do things like</div><div><br></div><div>someData.field1.field2 = "foo"</div><div><br></div><div>What's do I mean?<br></div><div><br></div><div>- field selectors are scoped so that names don't clash with each other or global names</div><div><br></div><div>- this way of selecting data can be used both for reading it, and for updating specific fields of some data deep in a data hierarchy (In Haskell, if using immutable data, this would requiring doing a data update on every level). </div><div><br></div><div>Any attempt to do this in Haskell, for me anyway, results in an explosion of names and a lot of boilerplate code and a resulting heavy syntax.</div><div><br></div><div>Is there a way of obtaining OO-like concise syntax, perhaps with Template Haskell?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Dennis</div><div><br></div></font></span></div>
<br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>