I'm learning to use input and output in Haskell. I'm trying to generate a random number and output it to another file. The problem is that the random number seems to be returning an IO Int, something that I can't convert to a String using show.
Could someone give me a pointer here?
It's helpful if you show us the code you've written that isn't working.
Anyway, you are in a
doblock and have written something like this, yes?You should instead do something like this:
The
<-operator binds the result of theIO Intvalue on the right to theInt-valued variable on the left. (Yes, you can also use this to bind the result of anIO Stringvalue to aString-valued variable, etc.)This syntax is only valid inside a
doblock. It's important to note that thedoblock will itself result in an IO value --- you can't launder away the IO-ness.