# Is lazy evaluation required for do-notation?

Do-notation is most famous by Haskell, which is also famous for having lazy evaluation.

But is lazy evaluation a requirement for implementing do-notation?

In principle, could do-notation be added to imperative languages, such as Java and C++?

• For the benefit of people who don't know Haskell, what is "do-notation"? It feels like a Java/C/whatever expert who doesn't know Haskell might be able to answer your question, if you explain what "do-notation" is. Mar 4 '19 at 15:35
• @DavidRicherby I added a link, but I think to answer this question it would be best to already know Haskell (or FP) and Java / C++. Mar 4 '19 at 15:57
• OK -- that sounds reasonable. Thanks! Mar 4 '19 at 15:58
• C#'s LINQ syntax and Scala's for-comprehensions are actual examples of do-notation equivalents in mainstream eager, imperative languages. Mar 5 '19 at 8:17

It is not required that the language is lazy. The do notation exists in SML family of languages (for instance OCaml), which are eager. In these languages the do-notation is written as the let-notation, that is, instead of writing

do x1 <- e1
x2 <- e2
...
return e


we write

let x1 = e1 in
let x2 = e2 in
...
e


Note however that let in OCaml has a fixed monad (what in Haskell would be the IO monad), whereas the do notation in Haskell works for any monad. There are extensions of OCaml which allow you to use any monad.

Sure, why not? F# is eager (not lazy) and has a sort-of do-notation.

Imperative PLs might add that as well, even if there's less need for monads there, since side effects (including mutating the values of variables) is a key aspect of those languages.

Scala has a for loop which resembles a monadic comprehension, so it's quite close to a do-block.