在应用程序中键入错误

Yaw*_*awn 0 haskell

我试图让这段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
Run Code Online (Sandbox Code Playgroud)

这是代码:

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))))
Run Code Online (Sandbox Code Playgroud)

知道怎么解决吗?

bzn*_*bzn 5

问题出div在最后一行.

当你想创建一个函数中缀时,你必须在`之间写它.所以,只需将最后一行更改为:

| otherwise = ((fact n) `div` ((fact m) * (fact (n - m))))
Run Code Online (Sandbox Code Playgroud)