[Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread ptrash
Hi, I am using the System.Random method randomRIO. How can I convert its output to an Int? Thanks... -- View this message in context: http://www.nabble.com/Convert-IO-Int-to-Int-tp23940249p23940249.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Tobias Olausson
You can not convert an IO Int to Int, or at least, you shouldn't. However, you can do as follows: test :: IO () test = do int <- randomRIO -- or whatever it is called print $ useInt int useInt :: Int -> Int useInt x = x+10 //Tobias 2009/6/9 ptrash : > > Hi, > > I am using the System.Rando

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Jochem Berndsen
ptrash wrote: > Hi, > > I am using the System.Random method randomRIO. How can I convert its output > to an Int? > > Thanks... You cannot [1], you should read up on monads and I/O in Haskell, for example http://haskell.org/haskellwiki/IO_inside [1] Yes, you can, but no, you don't want to. Rega

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Yusaku Hashimoto
On 2009/06/09, at 19:33, Tobias Olausson wrote: You can not convert an IO Int to Int, or at least, you shouldn't. However, you can do as follows: test :: IO () test = do int <- randomRIO -- or whatever it is called print $ useInt int useInt :: Int -> Int useInt x = x+10 Or, you can li

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread ptrash
Ok, thanks for the information. -- View this message in context: http://www.nabble.com/Convert-IO-Int-to-Int-tp23940249p23942344.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@h

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread ptrash
Hmm...it am not getting through it. I just want to generate a random number and then compare it with other numbers. Something like r = randomRIO (1, 10) if (r > 5) then... else ... -- View this message in context: http://www.nabble.com/Convert-IO-Int-to-Int-tp23940249p23943301.html Sent from th

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Magnus Therning
On Tue, Jun 9, 2009 at 2:52 PM, ptrash wrote: > > Hmm...it am not getting through it. I just want to generate a random number > and then compare it with other numbers. Something like > > r = randomRIO (1, 10) > if (r > 5) then... else ... You have to do it inside the IO monad, something like

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Henning Thielemann
On Tue, 9 Jun 2009, ptrash wrote: I am using the System.Random method randomRIO. How can I convert its output to an Int? in general: http://haskell.org/haskellwiki/How_to_get_rid_of_IO about randomIO: http://haskell.org/haskellwiki/Avoiding_IO#State_monad

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Daniel Fischer
Am Dienstag 09 Juni 2009 15:57:24 schrieb Magnus Therning: > On Tue, Jun 9, 2009 at 2:52 PM, ptrash wrote: > > Hmm...it am not getting through it. I just want to generate a random > > number and then compare it with other numbers. Something like > > > > r = randomRIO (1, 10) > > if (r > 5) then...

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Krzysztof Skrzętnicki
On Tue, Jun 9, 2009 at 16:14, Daniel Fischer wrote: > Am Dienstag 09 Juni 2009 15:57:24 schrieb Magnus Therning: >> On Tue, Jun 9, 2009 at 2:52 PM, ptrash wrote: >> > Hmm...it am not getting through it. I just want to generate a random >> > number and then compare it with other numbers. Something l

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread jerzy . karczmarczuk
Magnus Therning writes: ptrash wrote: ...am not getting through it. I just want to generate a random number and then compare it with other numbers. Something like r = randomRIO (1, 10) if (r > 5) then... else ... You have to do it inside the IO monad, something like myFunc = do

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Jorge Branco Branco Aires
Bulat Ziganshin wrote: Hello jerzy, Tuesday, June 9, 2009, 8:23:04 PM, you wrote: Please, tell him first about random streams, which he can handle without IO. Or, about ergodic functions (hashing contraptions which transform ANY parameter into something unrecognizable). When he says : "I kn

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Luke Palmer
2009/6/9 Krzysztof Skrzętnicki > On Tue, Jun 9, 2009 at 16:14, Daniel Fischer > wrote: > > If you're doing much with random generators, wrap it in a State monad. > > To avoid reinventing the wheel one can use excellent package available > on Hackage: > http://hackage.haskell.org/cgi-bin/hackage-s

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread ptrash
Hi, I have tried on the console to write x <- randomRIO(1,10) :t x Everythings fine and the type of x is x :: Integer Now I have tried to write a Method which gives me a Number of random numbers the same way but it doesn't work. randomList :: Int -> [Integer] randomList 0 = [] randomList n =

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Miguel Mitrofanov
"r <- randomRIO (1,10)" is NOT the source of error. Why do you think it is? ptrash wrote on 10.06.2009 15:55: Hi, I have tried on the console to write x <- randomRIO(1,10) :t x Everythings fine and the type of x is x :: Integer Now I have tried to write a Method which gives me a Number of r

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread ptrash
Hmm...I use the Eclipse Plugin. And this row is marked as error. Then where is the error? -- View this message in context: http://www.nabble.com/Convert-IO-Int-to-Int-tp23940249p23960827.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. __

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Iain Barnett
On 10 Jun 2009, at 12:55 pm, ptrash wrote: Now I have tried to write a Method which gives me a Number of random numbers the same way but it doesn't work. randomList :: Int -> [Integer] randomList 0 = [] randomList n = do r <- randomRIO (1, 10)

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Sebastian Sylvan
On Wed, Jun 10, 2009 at 12:55 PM, ptrash wrote: > > Hi, > > I have tried on the console to write > > x <- randomRIO(1,10) > :t x > > Everythings fine and the type of x is > x :: Integer > The type of x *in the context of an IO computation* is Integer. GHCi is basically an IO computation. Another

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Sebastian Sylvan
On Wed, Jun 10, 2009 at 2:08 PM, Sebastian Sylvan < sebastian.syl...@gmail.com> wrote: > > > randomList :: (RandomGen g) -> Int -> g -> [Integer] > Just spotted this typo, it should be: randomList :: (RandomGen g) = Int -> g -> [Integer] There may be other minor typos as I don't have a compile

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Sebastian Sylvan
On Wed, Jun 10, 2009 at 2:10 PM, Sebastian Sylvan < sebastian.syl...@gmail.com> wrote: > > > On Wed, Jun 10, 2009 at 2:08 PM, Sebastian Sylvan < > sebastian.syl...@gmail.com> wrote: > >> >> >> randomList :: (RandomGen g) -> Int -> g -> [Integer] >> > > Just spotted this typo, it should be: > > r

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread David Leimbach
This stuff is tricky for most newcomers I suspect (it was for me) x <- randomRIO(1,10) is "temporarilly" pulling the Integer you've named "x" out of the IO Integer it came from. You can think of the console as being an input/output stream inside the IO monad, which is why it is allowed there. Th

Re: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread ptrash
Thanks a lot. I have put now everything into the main method and it works. -- View this message in context: http://www.nabble.com/Convert-IO-Int-to-Int-tp23940249p23964365.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Re[2]: [Haskell-cafe] Convert IO Int to Int

2009-06-09 Thread Bulat Ziganshin
Hello jerzy, Tuesday, June 9, 2009, 8:23:04 PM, you wrote: > Please, tell him first about random streams, which he can handle without > IO. Or, about ergodic functions (hashing contraptions which transform ANY > parameter into something unrecognizable). When he says : "I know all that", > THEN hu

Re[2]: [Haskell-cafe] Convert IO Int to Int

2009-06-10 Thread Henning Thielemann
On Tue, 9 Jun 2009, Bulat Ziganshin wrote: Hello jerzy, Tuesday, June 9, 2009, 8:23:04 PM, you wrote: Please, tell him first about random streams, which he can handle without IO. Or, about ergodic functions (hashing contraptions which transform ANY parameter into something unrecognizable). W