[Haskell-cafe] Unresolved overloading error

Scott Brown 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  
argument.
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.

 -- Lennart

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:// 
> au.messenger.yahoo.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



 Send instant messages to your online friends http://au.messenger.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070331/58abc42d/attachment-0001.htm


More information about the Haskell-Cafe mailing list