Pretty Printing列表清单

use*_*747 1 haskell

我有一份清单清单:

[[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)?

Ørj*_*sen 9

相反的mapM_,你可以使用zipWithM_Control.Monad:

g xss cs = zipWithM_ f cs xss
Run Code Online (Sandbox Code Playgroud)

或者,如果您更改任一参数的顺序fg匹配,您可以使用较少的"点数"来执行此操作:

g = zipWithM_ f
Run Code Online (Sandbox Code Playgroud)

另外,concat (intersperse " " ...)也称为unwords ....