[Haskell-cafe] How to simplify this code?

Levi Greenspan greenspan.levi at googlemail.com
Fri Jan 16 02:50:54 EST 2009

On Fri, Jan 16, 2009 at 12:52 AM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> Here's a series of refactorings that I feel gets to the essence of the code.

Indeed it does.

> Final result:
>> modifyJSON f m = m { json = f (json m) }
>> add m k v = modifyJSON go m where
>>     go = showJSON . toJSObject . (newEntry :) . fromJSObject . fromJust . jsObj
>>     newEntry = (k, showJSON v)
> Some stylistic choices are debatable (pointless vs. not, inline vs.
> not), but I think this is a lot more readable than the >>= and liftM
> madness you had going.

Definitely. The refactorings you have done are very instructive and
the final result just beautiful. Many many thanks. Exactly the kind of
response I was hoping for.


More information about the Haskell-Cafe mailing list