[Haskell-cafe] Help with division

Daniel Carrera daniel.carrera at zmsl.com
Mon Dec 19 16:24:38 EST 2005


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.
    /


More information about the Haskell-Cafe mailing list