这是两段代码.
工作:
joins :: [String] -> String -> String
joins [] _ = ""
joins [x] _ = x
joins xs d = head xs ++ d ++ (joins (tail xs) d)
Run Code Online (Sandbox Code Playgroud)
不工作:
joins :: [String] -> String -> String
joins [] _ = ""
joins [x] _ = x
joins [x:xs] d = x ++ d ++ (joins xs d)
Run Code Online (Sandbox Code Playgroud)
后者的错误日志是:
test.hs:4:18:
Couldn't match expected type `[Char]' with actual type `Char'
In the first argument of `(++)', namely `x' …Run Code Online (Sandbox Code Playgroud) haskell ×1