[Haskell-cafe] Re: How to simplify this code?

Thomas Davie tom.davie at gmail.com
Fri Jan 16 03:14:00 EST 2009


On 16 Jan 2009, at 02:30, eyal.lotem at gmail.com wrote:

> Very nice series of refactorings!
>
> I'd like to add that it might be a better argument order to replace:
>
> JSON a => MyData -> String -> a -> MyData
>
> with:
>
> JSON a => String -> a -> MyData -> MyData
>
> Just so you can get a (MyData -> MyData) transformer, which is often
> useful.

Following up on this idea:
add m k v = fromJust . fmap (setJSON m . showJSON . toJSObject . ((k,  
showJSON v):) . fromJSObject) . jsObj . json $ m

can now become:
add k v = fromJust . fmap (setJSON m . showJSON . toJSObject . ((k,  
showJSON v):) . fromJSObject) . jsObj . json

if you switch the type around like that, and then it truely does  
become obvious that this is a (MyData -> MyData) transformer.

Bob


More information about the Haskell-Cafe mailing list