[Haskell-cafe] Outstanding context : (Num b, Random b)

2004-02-26 Thread horsh


Hi,

I am very new to haskell.

Could anyone please explain why these two things are not equivalent:

m2 = do  a - (drawInt 1 10)
 print a
drawInt :: Int - Int - IO Int
drawInt x y = getStdRandom (randomR (x,y))

m1 = do b - getStdRandom (randomR (1,10))
print b

the second one produces
*** Binding : m1
*** Outstanding context : (Num b, Random b)

in Hugs.

thanks
horsh

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Outstanding context : (Num b, Random b)

2004-02-26 Thread Glynn Clements

horsh  wrote:

 I am very new to haskell.
 
 Could anyone please explain why these two things are not equivalent:
 
 m2 = do  a - (drawInt 1 10)
print a
 drawInt :: Int - Int - IO Int
 drawInt x y = getStdRandom (randomR (x,y))
   
 m1 = do b - getStdRandom (randomR (1,10))
   print b
 
 the second one produces
 *** Binding : m1
 *** Outstanding context : (Num b, Random b)

In Haskell, numeric literals are overloaded. 1 could be an Int,
Integer, Rational, Float etc. randomR can use any of Int, Integer,
Float or Double, but it needs to know which. Adding an explicit type
signature to one of the literals will eliminate the error, e.g.:

m1 = do b - getStdRandom (randomR (1,10 :: Int))
print b

-- 
Glynn Clements [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Outstanding context : (Num b, Random b)

2004-02-26 Thread Ketil Malde
horsh  [EMAIL PROTECTED] writes:

 Could anyone please explain why these two things are not equivalent:

One of them has a type signature?

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe