Saket Choudhary
Saket Choudhary

Reputation: 624

Haskell list comprehension to map

I am new to haskell . I was wondering If I can do the following thing using just map and concat ?

                 [ (x,y+z) | x<-[1..10], y<-[1..x], z<-[1..y] ]

Upvotes: 3

Views: 844

Answers (1)

Sjoerd Visscher
Sjoerd Visscher

Reputation: 12000

Yes:

concat $ concat $ map (\x -> map (\y -> map (\z -> (x,y+z)) [1..y]) [1..x]) [1..10]

Although the official translation uses concatMap:

concatMap (\x -> concatMap (\y -> concatMap (\z -> [(x,y+z)]) [1..y]) [1..x]) [1..10]

Upvotes: 7

Related Questions