
31 Mar
2007
31 Mar
'07
5:04 a.m.
I have written this code in Haskell which gives an unresolved overloading error. The function bernoulli should give the probability of j successes occuring in n trials, if each trial has a probability of p.
fac 0 = 1 fac n = n * fac(n - 1)
binom n j = (fac n)/((fac j)*(fac (n - j)))
bernoulli n p j = (binom n j)*(p ^ j) * ((1 - p)^(n - j))
However, bernoulli 6 0.5 3 gives the error: ERROR - Unresolved overloading *** Type : (Fractional a, Integral a) => a *** Expression : bernoulli 6 0.5 3 Why doesn't Haskell infer the types? What kind of type casting or type definition can I use to fix the error? Send instant messages to your online friends http://au.messenger.yahoo.com