以下是我的阶乘函数:哈斯克尔:什么是错的阶乘函数
factorial :: Integer -> Integer
factorial n
| n < 0 = -1
| n > 0 = n * factorial (n-1)
| n == 0 = 1
我猜,我涵盖了所有的情况下(+ VE,-ve,0)。当我尝试加载上面的代码时,我收到以下警告。为什么我会收到警告?
Prelude> :load Fact.hs
[1 of 1] Compiling Main (Fact.hs, interpreted)
Fact.hs:2:1: Warning:
Pattern match(es) are non-exhaustive
In an equation for ‘factorial’: Patterns not matched: _
Ok, modules loaded: Main.
也就是说,添加的情况下'|否则=错误“不可能发生。”或者沿着这些线路。 – AJFarmar
我认为保罗意味着处理一个合法的案件与一个全面的案件。我会[如果可能,远离'错误'](http://programmers.stackexchange.com/questions/252977/cleanest-way-to-report-errors-in-haskell)。 – zoul