[Haskell-cafe] Type problems

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>
Subject: Re: [Haskell-cafe] Type problems
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
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:

1 import Control.Monad
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)
Failed, modules loaded:
 none.
Prelude System.Random> 

Or this:

1 import Control.Monad
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)
Failed, modules loaded: none.


How to fix?

Michael








      
_______________________________________________

Haskell-Cafe mailing list

Haskell-Cafe at haskell.org

http://www.haskell.org/mailman/listinfo/haskell-cafe







      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100724/61c95874/attachment.html


More information about the Haskell-Cafe mailing list