Parsing error
Sigbjorn Finne
sigbjorn_finne@hotmail.com
Thu, 29 Mar 2001 18:29:11 +0200
Ralf Hinze ralf@cs.uu.nl writes:
>
> the version of hugs in the repository stumbles over the following
> program (which the february 2001 version compiles without problems):
>
....
> > instance Num Dir where
> > a + b = toEnum (fromEnum a + fromEnum b)
> > a - b = toEnum (fromEnum a - fromEnum b)
>
>
> Parsing
> ERROR error.lhs:6 - Syntax error in declaration (unexpected `-')
Sorry, my fault - the use of infix (-) was wrongly disallowed as part
of the patch which permitted the use of qualified method names in
instance decls.
My proposed fix is to add the following rule to parser.y
qvarop_mipl : QVAROP {$$ = $1;}
| '-' {$$ = gc1(varMinus);}
| '`' QVARID '`' {$$ = gc3($2);}
| varop_mi {$$ = $1;}
;
and change the last alternative for the rule 'qfunlhs0' from
| var qvarop_mi pat0 {$$ = gc3(ap2($2,$1,$3));}
to
| var qvarop_mipl pat0 {$$ = gc3(ap2($2,$1,$3));}
Many thanks for reporting this, you can get the above code
to work if you parenthesise the operator (which is what the
Hugs Prelude consistently does, which is why this didn't show
up before now.)
--sigbjorn