字符串的 int 元组的 Haskell 列表

ruu*_*bel 2 string haskell tuples

我正在尝试从以下位置写出我的元组列表:

[(8,7),(5,6),(3,3),(9,4),(5,4)]
Run Code Online (Sandbox Code Playgroud)

到:

8 7 5 6 3 3 9 4 5 4
Run Code Online (Sandbox Code Playgroud)

这是我走了多远:(更新)

showTuples :: Board -> String
showTuples = unwords . fmap show . concatMap (\(x,y) -> [x,y])
Run Code Online (Sandbox Code Playgroud)

我知道我想把这个函数映射到我列表的所有元素,但我似乎做对了。

(更新)它有效,但仍然有引号问题

董事会的类型也是:

type Board = [(Int,Int)]
Run Code Online (Sandbox Code Playgroud)

Den*_*ink 5

使用模式匹配:

type Board = [(Int, Int)]

showTuples :: Board -> String
showTuples [] = ""
showTuples (x:[]) = show(fst(x)) ++ " " ++ show(snd(x))
showTuples (x:xs) = show(fst(x)) ++ " " ++ show(snd(x)) ++ " " ++ showTuples xs

main :: IO ()
main = putStrLn . showTuples $ [(8, 7), (5, 6), (3, 3), (9, 4), (5, 4)] -- 8 7 5 6 3 3 9 4 5 4
Run Code Online (Sandbox Code Playgroud)