
Maybe this is overkill, but if you want a more generic way for accessing and changing nested immutable data in general, you could check this package out as it is pretty exciting (to me at least): http://hackage.haskell.org/package/lens For more information on exactly what a lens is, read here: http://dl.dropbox.com/u/7810909/media/doc/lenses.pdf Cheers, Ben On Monday, 13 August 2012 at 3:21 PM, Christopher Howard wrote:
Hi. Is the some generic, clean syntax to unwrap a nested list, modify the value, and put it back together? Say, for example, I have the list [[1,2],[3,4]] and want to add 1 to each inner element, resulting in [[2,3],[4,5]].
After reading about the list monad, I was rather excited, because I (mistakenly) thought something like this would work:
code: -------- a = do b <- [[1,2],[3,4]] c <- b return (c + 1) --------
That would be awesome, because I would be able to modify the list at each level of unwrapping, while leaving the code very neat and readable. However, what the above example actually does is produce a /single/ list from the values:
code: -------- *Main> a [2,3,4,5] --------
Obviously wishing won't change how the list monad works, but I thought it might be worth asking if there is some other monad or syntactic trick that does something along the lines of what I am looking for.
-- frigidcode.com (http://frigidcode.com) indicium.us (http://indicium.us)
_______________________________________________ Beginners mailing list Beginners@haskell.org (mailto:Beginners@haskell.org) http://www.haskell.org/mailman/listinfo/beginners