开发者

Haskell list comprehension to map

I am new to hask开发者_如何学Goell . 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] ]


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜