其他问题和问题,虽然类似,但不太像这个。在这个特定的编译器错误中,Haskell GHC 不会编译以下代码,原因如下。我完全不明白 - 代码非常简单。
--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)
你能给我解释一下这个问题吗?