[Haskell-cafe] Re: OPPS, missing attachment (was Re: howto mix <- within do?

Daniel Fischer daniel.is.fischer at web.de
Fri Oct 17 12:25:44 EDT 2008


Am Freitag, 17. Oktober 2008 17:56 schrieb Larry Evans:
> On 10/17/08 08:12, Daniel Fischer wrote:
>
> At first, the |let v = e| combination looked best (less typing).
> However, my actual e0 was more complicated:
>
>        array_complete
>        [ Expr   <== Op0 GramOne
>        , Term   <== Op0 GramOne
>        , Factor <== Op0 GramOne
>        ]
>
> where <== was a binary operator which just produced a tuple pair.
> I wanted to keep the expression on multiple lines because it's
> easier to read.  The <== was defined to make the expression
> look more like grammar productions (the Op0 GramOne is not
> the final rhs.  That's only for testing purposes.).
>
> Unfortunately, using let with the multiline rhs failed to
> compile (due, I guess, to some layout rules, which I find
> difficult to fathom).

It would be no problem if you used only layout. The problem is that you used 
braces and semicolons for the do-block, but not for the let.
You would have to write it like

do { let { v0 = e0 }
   ; print v0
   }
, i.e. also use braces for the let block.
If you write
do { let v0 = e0
   ; print v0
   }
it would be parsed as

do { let { v0 = e0
         ; print v0
         }
   }

Either braces and semicolons everywhere or all layout, anything else invites 
misparsings.

HTH,
Daniel


More information about the Haskell-Cafe mailing list