4 ms·
> The IO monad and do-notation let you write sequential code It's actually much subtler than that due to lazy evaluation. The 'palindrome' section of http://le
by rkangel 10y ago
> The IO monad and do-notation let you write sequential code
It's actually much subtler than that due to lazy evaluation. The 'palindrome' section of http://learnyouahaskell.com/input-and-output http://learnyouahaskell.com/input-and-output illustrates this.
You basically write code that says: read all input, split lines, do something per line, join result into multiline string, print.
If you did that in Python it would block until EOF on the input and then print the result. In Haskell, due to lazy evaluation you will interactively get the response on a per-line basis.
What Haskell really gives you is a declarative language to describe what you want to happen to some data and then the lazy evaluation sorts everything out. Underneath, it's effectively a load of callbacks processing data streams.
- tome 10y agoYeah but that's lazy IO, and is highly frowned on, even considered a historical mistake.