以下是我的階乘函數:哈斯克爾:什麼是錯的階乘函數
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