[Haskell-beginners] cleanest way to unwrap a list?

Christopher Howard christopher.howard at frigidcode.com
Mon Aug 13 07:21:59 CEST 2012

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

After reading about the list monad, I was rather excited, because I
(mistakenly) thought something like this would work:

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:

*Main> a

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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 554 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120812/24df4551/attachment.pgp>

More information about the Beginners mailing list