我正在使用看起来像这样的模式匹配编写一个 Haskell 函数。
printLine :: [Int] -> [String]
printLine [] = error "Lege lijst levert niets op"
printLine [x] = "+" : replicate x "-"
printLine (x:xs) = ('+' : replicate x "-") : printLine xs
基本情况有效,但 GHC 在递归情况下给我一个错误,如下所示:
Couldn't match expected type `Char' with actual type `[Char]'
In the second argument of `replicate', namely `"-"'
In the second argument of `(:)', namely `replicate x "-"'
In the first argument of `(:)', namely `('+' : replicate x "-")'
我究竟做错了什么?请记住,我是 Haskell 和函数式编程的初学者。我希望有人可以帮助我。