Monads not useful in strict languages?

63 Views Asked by At

So Steven F. Lott in his book "Functional Python Programming" (start of chapter 13) writes:

A monad allows us to impose an order on an expression evaluation in an otherwise lenient language. We can use a monad to insist that an expression such as a + b + c is evaluated in left-to-right order. This can interfere with the compiler’s ability to optimize expression evaluation. This is necessary, however, when we want files to have their content read or written in a specific order: a monad is a way to assure that the read() and write() functions are evaluated in a particular order.

Languages that are lenient and have optimizing compilers benefit from monads imposing order on the evaluation of expressions. Python, for the most part, is strict and does not optimize, meaning there are few practical requirements for monads in Python.

Personally, I don't know much about monads. But in Scala, monads, ... I found them more used as a sort of alternative to control structures, sometimes dramatically simplifying the code.

E. g. the Either monad can be used to propagate an unhappy or finished scenario that does not need any further processing, by using a series of flatMaps.

So could someone explain to me what Steven F. Lott is up to here? What does it mean that monads aren't "practically required" in strict languages?

A concrete example in Scala (sadly, don't know any Haskell) would be interesting that shows: When using Scala's lazy features you must use monads, while when remaining strict, they're optional.

0

There are 0 best solutions below