I'm trying to do some basic arithmetic code (in fact it calculates the 
probability of a birthday clash given year length and group size), and GHC and 
Hugs are both not liking the code:

[EMAIL PROTECTED] ~]$ ghci burthday.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.4, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.
Compiling Main             ( burthday.hs, interpreted )

burthday.hs:14:37:
    No instance for (Fractional Integer)
      arising from use of `/' at burthday.hs:14:37
    Probable fix: add an instance declaration for (Fractional Integer)
    In the definition of `pnorep':
        pnorep days n = (numeratorex days n) / (denominatorex days n)
Failed, modules loaded: none.
Prelude> :reload
Compiling Main             ( burthday.hs, interpreted )
Ok, modules loaded: Main.
*Main> pnorep 365 30

<interactive>:1:0:
    Ambiguous type variable `a' in the constraints:
      `Fractional a' arising from use of `pnorep' at <interactive>:1:0-5
      `Integral a' arising from use of `pnorep' at <interactive>:1:0-5
    Probable fix: add a type signature that fixes these type variable(s)
*Main> 

The first time is with the type annotations, the second without:

import Ratio
import Numeric

numeratorex days n = (numdays days n) - (subtractex days n) -- :: Rational 
numdays days n = days * n
--numdays :: Integer -> Integer -> Integer
subtractex days n = (days * (days - 1)) / 2 --:: Rational
denominatorex days n = (days^n) 
-- denominatorex :: Integer -> Integer -> Integer
pnorep days n = (numeratorex days n) / (denominatorex days n)

Help!

Thanks!
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to