Skip to content

arrow syntax example can't be parsed

This example from section 7.6 of the user guide can't be 
parsed by the compiler:

expr' = proc x ->
                returnA -< x
        <+> do
                symbol Plus -< ()
                y <- term -< ()
                expr' -< x + y
        <+> do
                symbol Minus -< ()
                y <- term -< ()
                expr' -< x - y

The reason is that the first <+> is wrongly parsed as 
part of the previous expression (x <+> ...) rather than 
as a command operator. The fix is either to enclose the 
first command (returnA -< x) in parentheses, or precede 
it with do so that the layout rule terminates the 
command before the <+>. (The second use of <+> is OK 
precisely because the layout rule terminates the 
previous command before it).

Apart from fixing the example, I think it would be worth 
commenting the problem -- this is a syntax "gotcha" 
that is easy to stumble over. Maybe add this just after 
the example above:

"Note that a command operator risks being interpreted 
as a part of the expression at the end of the preceding 
command. To prevent this, such a command should 
either be enclosed in parentheses, or terminated by the 
layout rule before the operator. The example above 
would be parsed wrongly if the do before the returnA 
were omitted."

This assumes it's fixed by inserting a do, of course!

John
Trac metadata
Trac field Value
Version 6.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedFixed
Component Documentation
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information