[Haskell-cafe] do

Isaac Dupree isaacdupree at charter.net
Sat Oct 13 19:56:37 EDT 2007


Luke Palmer wrote:
> Using this you can do more complex actions, like, for instance, adding
> two numbers:
> 
>     readLine >>= (\x -> readLine >>= (\y -> print (x + y)))
> 
> Take a moment to grok that...
> 
> Which you might like to write:
> 
>     do x <- readLine
>        y <- readLine
>        print (x + y)

you can leave out the parentheses and make it similarly readable, still 
without "do" (at least, readable once you get used to the style, which 
might look almost as weird as do-notation)

   readLine >>= \x ->
   readLine >>= \y ->
   print (x + y)

Isaac


More information about the Haskell-Cafe mailing list