小编Eug*_*ene的帖子

Haskell头/尾与模式匹配

这是两段代码.

工作:

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

0
推荐指数
1
解决办法
635
查看次数

标签 统计

haskell ×1