Hacker News new | ask | show | jobs
by maxpow4h 4763 days ago
You may want to try using TemplateHaskell. Where you had:

    data MetaData = MetaData {
      metadataUrl :: String,
      metadataTitle :: String ...
you can use

    import Data.Char
    ...
    upStr n s = toLower (head (drop n s)) : (drop (n+1) s)
    $(deriveJSON (upStr 8) ''MetaData)
This will splice the `metadataUrl` to use the `url` field from JSON. The deriveJSON function takes a function to change the field names.

It's pretty handy.