
On 08/12/2012 09:37 PM, Shakthi Kannan wrote:
Hi,
--- On Mon, Aug 13, 2012 at 10:51 AM, Christopher Howard
wrote: | 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]]. \-- Like this?
ghci> let xxs = [[1,2], [3,4]]
ghci> [ [ x+1 | x <- xs] | xs <- xxs ] [[2,3],[4,5]]
SK
Thanks everyone for the responses. I found the list comprehension approach satisfactory, as it allows me to cleanly modify each layer of the nested array as I unwrap it: code: -------- b = [[ x+1 | x <- xs ++ [3] ] | xs <- [[1,2],[3,4]] ] *Main> b [[2,3,4],[4,5,4]] -------- The only downside is that I have to write the layers out in reverse of the way I would normally think of them, but that isn't too big of a challenge. I'm not sure how that would be done with map in a way that would be neat and readable and wouldn't require declaring extra identifiers. I can't give a fair evaluation of the Lens approach because I don't understand enough of the theory yet. -- frigidcode.com indicium.us