[Haskell-cafe] Unresolved overloading error
doolagarl2002 at yahoo.com.au
Sat Mar 31 06:07:15 EDT 2007
It's working now, thank you.
I changed the definition to
> binom n j = div (fac n) ((fac j)*(fac (n - j)))
> bernoulli n p j = fromIntegral(binom n j)*(p ^ j) * ((1 - p)^(n - j))
Lennart Augustsson <lennart at augustsson.net> wrote: The definition of fac forces the result to have the same type as the
Then in binom you use / which forces the type to be Fractional.
And finally you use ^ which forces the type to be Integral.
There is no type that is both Fractional and Integral.
I suggest using div instead of / in binom (binomial coefficients are
integers after all).
And then a fromIntegral applied to the binom call in bernoulli.
On Mar 31, 2007, at 10:04 , Scott Brown wrote:
> 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://
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Send instant messages to your online friends http://au.messenger.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe