[Haskell-cafe] a regressive view of support for imperative programming in Haskell

ok ok at cs.otago.ac.nz
Thu Aug 9 00:02:05 EDT 2007


On 9 Aug 2007, at 8:41 am, David Roundy wrote:
> I may be stating the obvious here, but I strongly prefer the do  
> syntax.
> It's nice to know the other also, but the combination of do 
> +indenting makes
> complicated code much clearer than the nested parentheses that  
> would be
> required with purely >>= syntax.

Er, what nested parentheses would those be?
	do e		=> e

	do e		=> e >>
	   rest		   rest'

	do p <- e	=> e >>= \p ->
	   rest		   rest'

	do let d	=> let d in
	   rest		   rest'

We get extra >>, >>=, \, ->, and "in" tokens, but no new parentheses.

The example in the Report makes this clear:

	do putStr "x: "
	   l <- getLine
	   return (words l)

desugars to

	putStr "x: "     >>
         getLine          >>= \l ->
         return (words l)

with no extra parentheses.
[Not that this actually works in GHC 6; the implied flush isn't done.]




More information about the Haskell-Cafe mailing list