开发者

Haskell list comprehension to map

开发者 https://www.devze.com 2023-04-06 20:37 出处:网络
I am new to hask开发者_如何学Goell . I was wondering If I can do the following thing using just map and concat ?

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

精彩评论

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

关注公众号