The Do-Let-Braces problem

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Thu, 15 Feb 2001 11:11:04 +0000


Mark Utting writes:

> fb::IO ()
> fb = 
>     do {
>         putStr "Enter Data: ";
>         line <- getLine;
>         let line2 = line;
>         putStr line2;
>        }
> 
> ERROR "f.hs" (line 13): Syntax error in definition 
>             (unexpected symbol "putStr")  

I find it hard to determine exactly from the Report whether this is
a bug in Haskell, or just a bug in ghc.  For what it's worth, nhc98
parses and accepts your example exactly as you intended.

> Fix 3: I might be happy to put ALL the semicolons at the beginning
>        of lines, which also works, but you are not allowed a semicolon
>        at the beginning of the first brace, so this looks asymmetric.
> f3 = 
>     do {
>         putStr "Enter Data: "
>         ;line <- getLine
>         ;let line2 = line
>         ;putStr line2
>        }

A common style I have seen is

      do { putStr "Enter Data: "
         ; line <- getLine
         ; let line2 = line
         ; putStr line2
         }

which matches nicely what Sebastien Carlier proposed in his message:

> Ideally, I would like an editor be able to draw a pretty square bracket
> (graphically, or with semi-graphic characters) around blocks, a bit like
> this:
> > f3 = 
> >     do |~ putStr "Enter Data: "
> >        |  line <- getLine
> >        |  let line2 = line
> >        |_ putStr line2

Regards,
    Malcolm