Playing around with Haskell... I'm writing a 'choose' function:
fac :: Int -> Int
fac 0 = 1
fac n = n*fac(n-1)
choose :: Int -> Int -> Int
choose n k = fac(n) / (fac(k) * fac(n-k))
I'm having problems with the last line.
Prelude> :l test.hs
Compiling Main ( test.hs, interpreted )
No instance for (Fractional Int)
arising from use of `/' at test.hs:13:20
Probable fix: add an instance declaration for (Fractional Int)
In the definition of `choose':
choose n k = (fac (n)) / ((fac (k)) * (fac (n - k)))
Failed, modules loaded: none.
The problem is that it doesn't like the / sign. For example, if I
replace the / by * the function is compiled just fine.
> Playing around with Haskell... I'm writing a 'choose' function:
> fac :: Int -> Int
> fac 0 = 1
> fac n = n*fac(n-1)
> choose :: Int -> Int -> Int
> choose n k = fac(n) / (fac(k) * fac(n-k))
> I'm having problems with the last line.
Greg Buchholz wrote:
> Integral division is spelled "div"...
Thanks, that worked.
The "course material" on the website uses a "/". See the second link
from the top, English notes. On page 5, right at the bottom. This course
material teaches "Gofer" which it claims is "essentially a subset of
Haskell". I guess that division must be one of the differences between
Gofer and Haskell.