My GHC 7.6.1 (on a Mac) compiles this code without any warnings or errors.<div><br></div><div>Do you have some other compilation flags in effect?</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 9, 2012 at 11:09 AM, Roman Cheplyaka <span dir="ltr"><<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For this module<br>
<br>
module Test where<br>
<br>
import System.Random<br>
<br>
data RPS = Rock | Paper | Scissors deriving (Show, Enum)<br>
<br>
instance Random RPS where<br>
random g =<br>
let (x, g') = randomR (0, 2) g<br>
in (toEnum x, g')<br>
randomR = undefined<br>
<br>
ghc (7.4.1 and 7.6.1) reports an error:<br>
<br>
rand.hs:9:9:<br>
No instance for (Random t0) arising from the ambiguity check for g'<br>
The type variable `t0' is ambiguous<br>
Possible fix: add a type signature that fixes these type variable(s)<br>
Note: there are several potential instances:<br>
instance Random RPS -- Defined at rand.hs:7:10<br>
instance Random Bool -- Defined in `System.Random'<br>
instance Random Foreign.C.Types.CChar -- Defined in `System.Random'<br>
...plus 34 others<br>
When checking that g' has the inferred type `g'<br>
Probable cause: the inferred type is ambiguous<br>
In the expression: let (x, g') = randomR (0, 2) g in (toEnum x, g')<br>
In an equation for `random':<br>
random g = let (x, g') = randomR ... g in (toEnum x, g')<br>
Failed, modules loaded: none.<br>
<br>
There should be no ambiguity since 'toEnum' determines the type of x<br>
(Int), and that in turn fixes types of 0 and 2. Interestingly,<br>
annotating 0 or 2 with the type makes the problem go away.<br>
<br>
jhc 0.8.0 compiles this module fine.<br>
<br>
Roman<br>
<br>
_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div><br></div>