[Haskell-cafe] help with some code
erantapaa at gmail.com
Sat Jul 12 03:39:26 UTC 2014
On Friday, July 11, 2014 10:01:38 AM UTC-5, gbwey9 wrote:
> Hi Cafe,
> 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.
> 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
> 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?
> Here is the paste.
> Thanks for any pointers!
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.)
One example of a package which uses aeson (of which there are many) is the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe