【发布时间】:2018-09-06 05:11:56
【问题描述】:
我有两个抛出相同错误的代码 sn-ps:
Prelude> sum' [] = 0
Prelude> sum' (x:xs) = x + sum' xs
Prelude> sum' [1,2,3,4,5]
*** Exception: <interactive>:142:1-25: Non-exhaustive patterns in function sum'
以及以下内容:
Prelude> prod [] = 1
Prelude> prod (x:xs) = x * (prod xs)
Prelude> prod [1,2,3,4,5]
*** Exception: <interactive>:139:1-27: Non-exhaustive patterns in function prod
我一定错过了一个模式,但它是什么?另外,我该如何处理这样的错误?在使用模式匹配定义函数时我应该怎么想? (我要求一种方法/技术)
【问题讨论】:
-
你在这里定义两个
sum's
标签: list haskell pattern-matching