Given an record (not an instance of the record, the record definition itself) such as:
data Request
= Expand { shortUrl :: [String]
, hash :: [String]
}
| Shorten { longUrl :: String
, domain :: String
}
| LinkEdit { link :: String
, title :: Maybe String
, note :: Maybe String
, private :: Maybe Bool
, user_ts :: Maybe Int
, archived :: Maybe Bool
, edit :: [String]
}
how does one generate code using info from the record definition -- e.g.,:
mkReqUrl :: Request -> String
mkReqUrl (Expand shortUrl hash) = mru "expand" (zr "shortUrl" [shortUrl] ++ zr "hash" [hash])
mkReqUrl (Shorten longUrl domain) = mru "shorten" (zr "longUrl" [longUrl] ++ zr "domain" [domain])
...
I imagine some usage of TemplateHaskell and a generics library (e.g., Uniplate) might do the trick. (I have peaked at the Lens implementation since it deals with record definitions, but I get lost in the code.).