Reputation: 624
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
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