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

Henk-Jan van Tuyl hjgtuyl at chello.nl
Mon Aug 13 07:58:40 CEST 2012


On Mon, 13 Aug 2012 07:37:48 +0200, Shakthi Kannan <shakthimaan at gmail.com>  
wrote:

> Hi,
>
> --- On Mon, Aug 13, 2012 at 10:51 AM, Christopher Howard
> <christopher.howard at frigidcode.com> 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]]

Or this?
> map (map (+ 1)) [[1,2], [3,4]]
[[2,3],[4,5]]


Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--



More information about the Beginners mailing list