I'm learning scalaz and now I'm trying to understand the point of IO monad. I read this article about IO monads and trying to run the simplest example myself:
val io = println("test").pure[IO]
println("before")
io.unsafePerformIO()
Yes, it works as expected. It prints
before
test
But I cannot catch the gist of the IO monad. What is the trick? Except "maintains substitution" as specified in the article I referenced.
The substitution does not seem too useful too me now. Could you please explain?
From what I can think. Imagine I have some traits:
trait Reader{
def read(): List[Int]
}
trait Writer[T]{
def write(t: T): Unit
}
So I have a reader which can read monadic values (List in my case). And then I need to write all values from the container somewhere else, performing some transfomation on them. Can IO monad be useful in that case?