我有以下Haskell程序:
catlines = unlines . zipWith (\(n,l) -> show n ++ l) [0..]
main = putStrLn $ catlines ["A", "B"]
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,GHC给出以下错误:
catlines.hs:1:41:
Couldn't match expected type `b0 -> String' with actual type `[a0]'
In the expression: show n ++ l
In the first argument of `zipWith', namely
`(\ (n, l) -> show n ++ l)'
In the second argument of `(.)', namely
`zipWith (\ (n, l) -> show n ++ l) [0 .. ]'
Run Code Online (Sandbox Code Playgroud)
据我所知,这应该编译.我不知道出了什么问题.
问题是传递给的函数zipWith应该采用两个参数,而不是元组.试试这样:
zipWith (\n l -> show n ++ l)
Run Code Online (Sandbox Code Playgroud)