我试图编写一个带有字符串和Int列表的函数,并返回每个字符串为" int"的字符串列表。倍。那就是:
duplicate :: [String] -> Int -> [String]
duplicate ["ab","ac","yt","hfg","lkj","poi"] 2
输出应为
["ab","ab","ac","ac","yt","yt","hfg","hfg","lkj","lkj","poi","poi"]
答案 0 :(得分:1)
duplicate = (. replicate) . (>>=)
或更基本的
duplicate xs n = concatMap (replicate n) xs
如果你想用符号表示列表乘法
> let (**) :: [a] -> Int -> [a]
| (**) = (. replicate) . (>>=)
> ["a","b"]**3
["a","a","a","b","b","b"]