I watched a video recently on how you could come up with the IO monad, the talk was in scala. I am actually wondering what the point of having functions return IO[A] out of them
The benefit of using the IO monad is having pure programs. You do not push the side-effects higher up the chain, but eliminate them. If you have an impure function like the following:
def greet {
println("What is your name?")
val name = readLine
println(s"Hello, $name!")
}
You can remove the side-effect by rewriting it to:
def greet: IO[Unit] = for {
_ <- putStrLn("What is your name?")
name <- readLn
_ <- putStrLn(s"Hello, $name!")
} yield ()
The second function is referentially transparent.
A very good explanation why using the IO monads leads to pure programs can be found in Rúnar Bjarnason's slides from scala.io (video can be found here).