michael rice nowgate at yahoo.com
Sat Jul 24 15:59:11 EDT 2010

```Thanks, Tobias. I figured it was something like that but lack the syntax expertise on where to put it.

MIchael

--- On Sat, 7/24/10, Tobias Brandt <tob.brandt at googlemail.com> wrote:

From: Tobias Brandt <tob.brandt at googlemail.com>
To: "michael rice" <nowgate at yahoo.com>
Date: Saturday, July 24, 2010, 3:50 PM

You have to fix the type of 1 and 6, e.g. by writing
x <- randomRIO (1, 6) :: IO Int
or
x <- randomRIO (1, 6 :: Int)
GHCi defaults integral numbers to Int, that's why it works there.

On 24 July 2010 21:36, michael rice <nowgate at yahoo.com> wrote:

This works:

Prelude System.Random> do { randomRIO (1,6) >>= (\x -> putStrLn \$ "Value = " ++ show x) }

Value = 5

So does this:

Prelude System.Random> do { x <- randomRIO (1,6); putStrLn \$ "Value = " ++ show x }
Value = 2

But not this:

2 import System.Random

3
4 foo :: IO ()
5 foo = do
6   x <- randomRIO (1,6)
7   putStrLn \$ "Value = " ++ show x

foo.hs:6:18:
Ambiguous type variable `t' in the constraints:
`Num t' arising from the literal `1' at foo.hs:6:18

`Random t' arising from a use of `randomRIO' at foo.hs:6:7-21
Probable fix: add a type signature that fixes these type variable(s)
none.
Prelude System.Random>

Or this:

2 import System.Random
3
4 foo :: IO ()
5 foo = randomRIO (1,6) >>= (\x -> putStrLn \$ "Value = " ++ show x)

foo.hs:5:17:
Ambiguous type variable `t' in the constraints:
`Num t' arising from the literal `1' at foo.hs:5:17
`Random t' arising from a use of `randomRIO' at foo.hs:5:6-20

Probable fix: add a type signature that fixes these type variable(s)

How to fix?

Michael

_______________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...