List Comprehensions
There is an alternative way to define map and filter, which is to use list comprehension.
map f xs = [f x | x <- xs]
filter p xs = [x | x <- xs, p x]
With list comprehension we can also do things like:
> [x + y | x <- [1..2], y<- [1..3]]
[2,3,4,3,4,5]
-- .. is syntax sugar for range
> [1..10]
[1,2,3,4,5,6,7,8,9,10]
> ['a' .. 'z']
"abcdefghijklmnopqrstuvwxyz"
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .