Re:Things in Haskell which don't exist elsewhere at all
by bjourne on Tuesday August 13, 2013 @04:35AM
(#6204620)
That's a contrived example and not "real source code." Furthermore you are leaving so many symbols undefined that it is hard to see what is going on. Where does 'traverse' come from? Nevertheless, here is how you would do it in python: https://gist.github.com/bjourne/6219037
Re:Things in Haskell which don't exist elsewhere at all
by tel on Tuesday August 13, 2013 @02:39PM
(#6207440)
It's extracted, not contrived. Updating nested attributes on a tree of objects as a nice one-liner. The most contrived bits were that I didn't use the built in tree type so I had to define more stuff explicitly.
Traverse comes from Data.Traverable but is exported with lens as lens can be seen as a generalization of traverse.
In Haskell you'd want to write a generic traversal over the objects of the tree useful whenever you want even access to the contained elements.
And then here's the finale, the actual lens code specific to the task.