Haskell语言Prelude模块中函数map的用法及代码示例。
用法类型:
(a -> b) -> [a] -> [b]
返回通过将函数(第一个参数)应用到作为第二个参数传递的列表中的所有项而构造的列表
示例1:
输入:
map abs [-1,-3,4,-12]
输出:
[1,3,4,12]
示例2:
输入:
map reverse ["abc","cda","1234"]
输出:
["cba","adc","4321"]
示例3:
输入:
map (3*) [1,2,3,4]
输出:
[3,6,9,12]
示例4:
输入:
map (recip . negate) [1,4,-5,0.1]
输出:
[-1.0,-0.25,0.2,-10.0]
示例5:
输入:
map (print) [1,3,5,6,7]
输出:
[<<IO action>>,<<IO action>>,<<IO action>>,<<IO action>>,<<IO action>>]
注:本文由纯净天空筛选整理自 haskell map。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。