|
|
|
|
|
by tel
4275 days ago
|
|
So there are a few things going on here 1. Focusing on "the subtree" instead of "the value
at the subtree"
2. Working with data types like `{:a {:b {:c 5}}}` is
somewhat uncommon in Haskell (too little information
gets projected into the types)
3. Doing "along the way parsing"
Each of those are fine to do in Haskell and I could work up an example. Perhaps the best domain for this is using the lens-aeson[0] package since your data type is not so different from JSON. Here you can use the _JSON prism to do your "along the way parsing" (the failure mechanism of prisms catches failed parses naturally). You can also focus on whole subtrees naturally (since the JSON Value type is just a sum over subtrees and values all together, so the natural parametricity distinction is lost).So I'd look at [0] for a wealth of examples in that vein. I'd also look into zipper lenses. They were removed in more recent versions (I think anticipating splitting them out into another package) but they're available in the 3.* series [1]. [0] http://hackage.haskell.org/package/lens-aeson
[1] http://hackage.haskell.org/package/lens-3.10.1/docs/Control-... |
|
The existence of zipper lenses catches me by surprise, as I have been frequently directed at a stackoverflow [0] response on the difference between the two...
[0] http://stackoverflow.com/questions/22094971/what-are-the-dif...