我試圖讓這片Haskell代碼的工作,但我不斷收到此錯誤信息:類型錯誤
> ERROR file:.\4.hs:9 - Type error in application
> Expression : fact n div (fact m * fact (n - m))
> Term : fact
> Type : Int -> Int
> Does not match : a -> b -> c -> d
下面的代碼:
fact :: Int -> Int
fact q
| q == 1 = 1
| otherwise = q * fact(q-1)
comb :: Int -> Int -> Int
comb n m
| n < m = error "undefined as n < m"
| otherwise = ((fact n) div ((fact m) * (fact (n - m))))
任何想法如何要解決這個問題?
你可以寫'fact'短,例如'事實n =產品[1..n]'。 – Landei