|
|
|
|
|
by pdpi
765 days ago
|
|
Take this bit of pseudocode: a = readLine()
b = readLine()
print(b)
print(a)
What order are the lines executed in?In a strict language, the answer is obvious. In a non-strict language, line 4 has a data dependency on line 1 so always executes after it, ditto lines 3 and 2. But how the two groups get interleaved is completely unpredictable, so, if you’re really committed to non-strict evaluation, you need a way to force data dependencies between all four lines such that order of evaluation is forced. Once you achieve that, you have a bunch of ugly-looking machinery that’s peppered across your whole codebase. Monadic IO (and do-notation in particular) gives us a way to write this sort of code without feeling the urge to gouge our eyes out. |
|