Quantcast
Viewing all articles
Browse latest Browse all 8

Answer by Romildo for Should do-notation be avoided in Haskell?

The do notation is expanded to an expression using the functions (>>=) and (>>), and the let expression. So it is not part of the core of the language.

(>>=) and (>>) are used to combine actions sequentially and they are essential when the result of an action changes the structure of the following actions.

In the example given in the question this is not apparent as there is only one IO action, therefore no sequencing is needed.

Consider for example the expression

do x <- getLine   print (length x)   y <- getLine   return (x ++ y)

which is translated to

getLine >>= \x ->print (length x) >>getLine >>= \y ->return (x ++ y)

In this example the do notation (or the (>>=) and (>>) functions) is needed for sequencing the IO actions.

So soon or later the programmer will need it.


Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>