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.
_
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
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
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
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
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
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
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
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...
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
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
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
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
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 =
"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
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.
__
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)
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
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
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
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
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.
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
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
24 matches
Mail list logo