我有一份清单清单:
[[5,1,0,0,5,5,0,0],[0,0,1,4,2,0,6,1],[1,1,6,3,0,1,0,0],[1,5,0,0,0,1,1,6]]
Run Code Online (Sandbox Code Playgroud)
和一个字符串"wxyz"
我想:1)
w: 5 1 0 0 5 5 0 0
x: 0 0 1 4 2 0 6 1
y: 1 1 6 3 0 1 0 0
z: 1 5 0 0 0 1 1 6
Run Code Online (Sandbox Code Playgroud)
我写:
f c xs = putStrLn (c : ':' : ' ' : concat (intersperse " " $ map show xs))
Run Code Online (Sandbox Code Playgroud)
写一行
和2)
g xxs c = mapM_ (f c) xxs
Run Code Online (Sandbox Code Playgroud)
如何修改2)循环字符串"wxyz"才能拥有1)?
相反的mapM_,你可以使用zipWithM_从Control.Monad:
g xss cs = zipWithM_ f cs xss
Run Code Online (Sandbox Code Playgroud)
或者,如果您更改任一参数的顺序f或g匹配,您可以使用较少的"点数"来执行此操作:
g = zipWithM_ f
Run Code Online (Sandbox Code Playgroud)
另外,concat (intersperse " " ...)也称为unwords ....