[Haskell-cafe] Unresolved overloading error

Lennart Augustsson lennart at augustsson.net
Sat Mar 31 05:25:19 EDT 2007


Actually, I don't know what type you want p to be, so you might not  
need the fromIntegral.

On Mar 31, 2007, at 10:21 , Lennart Augustsson 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list