
On Mon, May 16, 2011 at 01:38:02AM +0200, Christopher Done wrote:
On 15 May 2011 23:20, Magnus Therning
wrote: I wrote down some stuff from my first look at json, maybe it can help you in getting further?
FWIW, rather than:
readJSON (JSObject obj) = let jsonObjAssoc = fromJSObject obj in do para <- mLookup "para" jsonObjAssoc >>= readJSON seeAlso <- mLookup "GlossSeeAlso" jsonObjAssoc >>= readJSON return $ GlossDef { glossDefPara = para , glossDefSeeAlso = seeAlso }
You can just write:
readJSON object = do obj <- readJSON object GlossDef <$> valFromObj "para" obj <*> valFromObj "GlossSeeAlso" obj
FWIW, read the first comment ;-) I still consider the monadic style easier to read than the applicative so that's what I usually start with. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus I invented the term Object-Oriented, and I can tell you I did not have C++ in mind. -- Alan Kay