Daniel Carrera wrote:
>
> 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.
>
Integral division is spelled "div"...
http://www.zvon.org/other/haskell/Outputprelude/div_f.html
...the slash, "/", is for fractional numbers (Doubles, Rationals, etc.).
Try one of...
> choose :: Int -> Int -> Int
> choose n k = div (fac n) (fac(k) * fac(n-k))
-- or, as an infix function --
> choose :: Int -> Int -> Int
> choose n k = (fac n) `div` (fac(k) * fac(n-k))
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe