<div dir="ltr">Hi Erik,<div><br></div><div>I'll take a look into it. Thanks for the help! </div><div><br></div><div>Best,</div><div>Grant</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 11, 2014 at 11:39 PM, Erik Rantapaa <span dir="ltr"><<a href="mailto:erantapaa@gmail.com" target="_blank">erantapaa@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><div class="h5">On Friday, July 11, 2014 10:01:38 AM UTC-5, gbwey9 wrote:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Hi Cafe,</div><div><br></div><div><div>I've got some code where a user can provide a filter to subscribe to a particular type of event.  The events come in as xml and are parsed using the toEvent method.</div>

<div>The code works fine but is repetitive since each event record potentially has the information needed to parse the xml using the field names and types. </div><div><br></div><div>So is there a way to get rid of the repetition and streamline the code? Should I be using TH or lenses or something else entirely?</div>

<div><br></div></div><div>Here is the paste. <br></div><a href="http://www.google.com/url?q=http%3A%2F%2Flpaste.net%2F107338&sa=D&sntz=1&usg=AFQjCNGI_2_sqb7wOrLNKJBuTeDzCpLLBQ" target="_blank">http://lpaste.net/107338</a><br>
<div><br></div><div>Thanks for any pointers!</div><div>Grant</div></div></blockquote><div><br></div></div></div><div>Regarding how the defining the toEvent instances can be simplified, have a look at the FromJSON type class works in the aeson package. One technique they use is to define FromJSON instances for even the primitive types (e.g. Int, String, DateTime, etc.) so that the FromJSON instances of records can be entirely type-directed removing the need to reference specific deserialization functions (e.g.  getint, getbool, etc.)</div>
<div><br></div><div>One example of a package which uses aeson (of which there are many) is the github package:<br><br><a href="https://github.com/jwiegley/github/blob/master/Github/Data.hs" target="_blank">https://github.com/jwiegley/github/blob/master/Github/Data.hs</a><br>
<br></div></div></blockquote></div><br></div>