
Good evening, Doing some calculations in ghci, I encountered a difficulty which I cannot resolve. Here's a distilled version, prepared for the command line: let i = 2 in (-1)^i/(2^(10*i)) * (-2^5/(4*i+1)) gives the following error messages ghci: Ambiguous type variable `b' in these top-level constraints: `Fractional b' arising from use of `/' at <interactive>:1 `Integral b' arising from use of `^' at <interactive>:1 hugs: ERROR - Unresolved overloading *** Type : (Integral a, Fractional a) => a *** Expression : let {...} in (-1) ^ i / 2 ^ (10 * i) * negate (2 ^ 5 / (4 * i + 1)) However, if I substitute i = 2 in the last fraction, then the transformed expression let i = 2 in (-1)^i/(2^(10*i)) * (-2^5/(4*2+1)) is accepted. Note that both let i=2 in (-1)^i/(2^(10*i)) and let i=2 in (-2^5/(4*i+1)) are accepted. Why? Thank you in advance. Marc Charpentier

On Tue, Nov 02, 2004 at 09:53:28PM +0100, Marc Charpentier wrote:
Good evening,
Doing some calculations in ghci, I encountered a difficulty which I cannot resolve.
Here's a distilled version, prepared for the command line:
let i = 2 in (-1)^i/(2^(10*i)) * (-2^5/(4*i+1))
Monomorphism restriction. Try let { i :: Num a => a; i = 2 } in (-1)^i/(2^(10*i)) * (-2^5/(4*i+1)) Best regards, Tom -- .signature: Too many levels of symbolic links

On Tue, 2 Nov 2004, Marc Charpentier wrote:
Doing some calculations in ghci, I encountered a difficulty which I cannot resolve.
Here's a distilled version, prepared for the command line:
let i = 2 in (-1)^i/(2^(10*i)) * (-2^5/(4*i+1))
Monomorphism was the short answer, the long one is: Written this way 'i' must have the same type at each occurence. But (^i) requires some Integral type for i and (/i) requires some fractional type for i, I guess there is no such type. You can resolve this problem also by an explicit conversion: (-2^5/(4 * fromIntegral i + 1)) But this still leaves the interpreter uncertain, what Integral type to use, so you might want to give an explicit signature: let i = 2 :: Integer in ...
participants (3)
-
Henning Thielemann
-
Marc Charpentier
-
Tomasz Zielonka