io monad

Scala: Examples of for-expressions being converted to map and flatMap

Without any explanation, here are a couple of source code examples from my book, Learning Functional Programming in Scala. The only thing I’ll say about this code is that I created it in the process of writing that book, and the examples show how the Scala compiler translates for-expressions into map and flatMap calls behind the scenes.

putStrLn doesn’t print to STDOUT ... it describes how to print to STDOUT alvin June 12, 2017 - 9:57am

putStrLn doesn’t print to standard out, it returns a value — of type IO () — which describes how to print to standard out, but stops short of actually doing it.”

From the article, An IO Monad for Cats.

Researching the use of an IO Monad in Scala

As I was researching who might be using an “IO Monad” in Scala, I found this quote from Martin Odersky in the Google Group titled “scala-debate”:

“The IO monad was a neat trick for combining side effects with lazy evaluation ... there is only one lazily evaluated language in wide usage today and even its creators have said that laziness was probably a mistake. Strict languages don’t need the IO monad, and generally don’t have it, even though they could. Bob Harper’s posts in his ‘existential type’ series are a good explanation on why not.”

Here’s a link to Bob Harper’s The Point of Laziness article.