Hello all,

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 )

test.hs:13:20:
    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.

Does anyone know what I'm missing?

Cheers,
Daniel.
--
     /\/`) http://oooauthors.org
    /\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/    I am not over-weight, I am under-tall.
   /
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to