这可能是一个非常简单的问题.
给定两个字符串列表,xs和ys,我需要一个列表,其中两个字符串已被预先添加.
例如,
body = ["1", "2"]
suffixes = ["a", "b", "c"]
会给出输出
[["1a", "1b", "1c"], ["2a", "2b", "2c"]]
根据我的理解,haskell使用map其他语言将使用的地方for each,所以我尝试将append函数映射到列表,
map (++"1") suffixes
但我无法弄清楚如何动态应用它["1", "2"]而不是硬编码.
如果您不需要列表边界(一个非常常见的情况):
Control.Applicative> liftA2 (++) ["1", "2"] ["a", "b", "c"]
["1a","1b","1c","2a","2b","2c"]
Run Code Online (Sandbox Code Playgroud)
否则,只需将您的呼叫嵌套到map:
> map (\prefix -> map (prefix++) ["a", "b", "c"]) ["1", "2"]
[["1a","1b","1c"],["2a","2b","2c"]]
Run Code Online (Sandbox Code Playgroud)