<div dir="auto">On my projects at Target, I've had a good experience using DuplicateRecordFields coupled with a library like overloaded-records or generic-lens. This lets us define records that share field names without needing to use prefixes or multiple modules, while still being able to access and modify those fields easily thanks to the OverloadedLabels extension.<div dir="auto"><br></div><div dir="auto">With this approach, you get a lens for every single record field without name conflicts. If you have a bunch of records with a field called id, you'll be able to access them using #id as a lens without running into name conflicts with other records *or* with normal identifiers (like the id function). You can then access fields with `record ^. #fieldName`, set them with the .~ operator and compose them with other lenses and traversals.</div><div dir="auto"><br></div><div dir="auto">When we first out together a system like this I was worried that it would break type inference and cause weird error messages, but it had not caused *any* problems in practice. Haskell's records went from being a royal pain to being at least as convenient as any other language I've used, and sometimes more (eg when combined with traversals).</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 29, 2020, 06:13 Jean Lopes <<a href="mailto:hawu.bnu@gmail.com" target="_blank" rel="noreferrer">hawu.bnu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi!<br><br>I'm trying to encode a domain which is full of simple records, and a lot of field name clashes.<br><br>Here is a simple example, a.k.a. 1:1 with the domain-spec:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace">data C001 {<br></font><font face="monospace">  -- other stuff<br></font><font face="monospace">  indMov :: Bool<br></font><font face="monospace">}</font><font face="monospace"><br></font><font face="monospace">data C170 {<br></font><font face="monospace">  -- other stuff<br></font><font face="monospace">  indMov :: Bool<br></font><font face="monospace">}</font></blockquote><div><br></div><div>There is ~148 records with this field (indMov), all with the same meaning. What are my options to encode this in Haskell?</div><div><br></div><div>- Prefix all record fields to avoid name clashes?</div><div>- Use <span style="color:rgb(0,0,0);font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:16.8px"><i>DuplicateRecordFields</i></span><span style="color:rgb(0,0,0);font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:16.8px">?</span></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif">- Typeclasses???</font></span></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif">- other options I am not aware of?</font></span></div><div><br></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif">which would you prefer? and why of course :)</font></span></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif">Thanks,</font></span></div><div><span style="color:rgb(0,0,0);font-size:16.8px"><font face="arial, sans-serif">Jean Lopes</font></span></div><div><br></div><div><br></div><div> </div></div>
_______________________________________________<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 noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>