haskell - Error on comparing IO Int inside of a lambda -
I have a small section of code here that I want to use in a statement. Code
getRandomInt :: (Int, Int) - & gt; IO Int getRandomInt (A, B) = GG & lt; - newStdGen return. Fst $ randomR (a, b) g
then forward down ...
if ((getRandomInt (0,1)) gt; & gt; ; = (\ X -> x == 1))
Under my understanding, it should be compiled at randomInt == 1
and one If the statement is usable within the statement; I get this error:
word.hs: 30: 21: The actual type 'IOB' with the expected type 'Bull' could not be matched with expression: ((getRandomInt (0, 1)) & gt; & gt; = (\ x - & gt; x == 1)) In a STM of a 'do' block: if ((getRandomInt (0, 1)) gt; & gt; ; = (\ X -> X == 1)) Get the getendord: getWord $ len-1 and get the derANDindex: getWord $ len-1 in expression: do {if (getRandomInt (0, 1 ))> Gt;> = (\ x -> X == 1) getRandomVowel: (getWord $ len - 1) and get Rendendum alert A: Sorry for any clear misconceptions, I just yesterday
-text "itemprop =" text ">
type (& gt; & gt; =)
is Monad M => I'm a - & gt; (A -> Mb) - & gt; MB
In this case M = Io
.
Then you have two problems:
First of all, \ x -> X == 1
a bool
will not return, it will not be a IO bool
, so it (>>> =)
.
You can decide that it should be \ x -> Returns (x == 1)
, but this is not a very clear solution and then you feel that the result is Bool
instead of IO Bool
/ P>
This is the error that is telling you - if
requires a Bool
argument but got it IO something
.
The perfect solution getRandomInt
is a separate & lt; -
To lift in line:
x
Comments
Post a Comment