<div dir="ltr">Use DeriveGenerics, and <a href="https://github.com/i-am-tom/higgledy">higgledy</a> (or some packages supporting higher kinded data) would help you.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2019年10月4日(金) 5:56 Sebastiaan Joosten <<a href="mailto:sjcjoosten%2Bhaskelcafe@gmail.com">sjcjoosten+haskelcafe@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Hi all,</span><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">I'm writing a lot of code that looks like this:</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><div style="color:rgb(192,192,192);background-color:rgb(32,32,32);font-family:Menlo,Monaco,"Courier New",monospace;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(247,140,108)">instance</span> WhiteSpaced ClassItem <span style="color:rgb(247,140,108)">where</span></div><div> removeWS (Method a b c) <span style="color:rgb(199,146,234)">=</span> Method (removeWS a) (removeWS b) (removeWS c)</div><div> removeWS (Declaration b) <span style="color:rgb(199,146,234)">=</span> Declaration (removeWS b)</div></div></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Typically, all the way at the end there's an instance that deviates (sometimes the deviating instances are somewhere in the middle). I need to do this for a lot of functions, and a lot of data types, and all I'm doing here is rewriting the data-type declaration in a different syntax (except that you do not know the types of a, b and c from the above). For the sake of maintainability, I want to avoid this code-duplication and focus only on the deviating instances.</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">How to do better? I don't see how to use generics (in the hope of only writing 'instance WhiteSpaced ClassItem where' instead of the three lines above) for this: the types for a, b and c are all different here. Would this be easier with Template Haskell? (in the hope of only writing $(''something ClassItem) instead of the three lines above)</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><div>My main concern is maintainability, an ideal solution is either a clear one-liner or a library import (in the same way that aeson allows me to use generics or Template Haskell without needing to know much about them). Other solutions are welcome too.</div></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Best,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Sebastiaan</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" 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><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>山本悠滋<br>twitter: <a href="https://twitter.com/igrep" target="_blank">https://twitter.com/igrep</a><br>GitHub: <a href="https://github.com/igrep" target="_blank">https://github.com/igrep</a></div><div>GitLab: <a href="https://gitlab.com/igrep" target="_blank">https://gitlab.com/igrep</a><br>Facebook: <a href="http://www.facebook.com/igrep" target="_blank">http://www.facebook.com/igrep</a></div></div></div></div></div></div></div>