【发布时间】:2015-07-14 15:26:24
【问题描述】:
如果我运行以下文件:
ll [] = 0
ll (x:xs) = 1 + ll xs
main = putStrLn (show (ll [2,2,2]))
使用 runghc,它可以工作并打印 3。
在 ghci 中,我得到:
ghci> let ll [] = 0
ghci> let ll (x:xs) = 1 + ll xs
ghci> ll [3,4,43,9]
*** Exception: <interactive>:23:5-25: Non-exhaustive patterns in function ll
上面的代码在 ghci 中无法运行的原因是什么?需要进行哪些更改才能使其发挥作用?
【问题讨论】:
标签: haskell