2
其他問題和問題雖然相似,但並不完全像這樣。在這個特定的編譯器錯誤中,Haskell GHC不會編譯下面的代碼,原因如下。我完全不理解 - 代碼非常簡單。沒有使用`>'引起的(Ord int)的實例,Haskell
--factorial
fact :: int -> int
fact 0 = 1
fact n | n > 0 = n * fact(n - 1)
main = print (fact 10)
(錯誤:)
No instance for (Ord int) arising from a use of `>'
Possible fix:
add (Ord int) to the context of
the type signature for fact :: int -> int
In the expression: n > 0
In a stmt of a pattern guard for
an equation for `fact':
n > 0
In an equation for `fact': fact n | n > 0 = n * fact (n - 1)
你能解釋一下這個問題給我嗎?
爲什麼'Num int => int - > int'? :) – Yuras
@Yuras嗯,這更好 - 我寧願'積分',但很好的提示! –
* facepalm *謝謝。這是我用Haskell編寫和編譯的第一個程序(包含一個函數)。 – bimmo