| Is the following legal Haskell?
| 
| > infixr 0 `foo`
| > infixr 0 `bar`
| > ...
| > dubious a b c = a `foo` b `bar` c
| 
| According to the grammar in the Haskell report, I don't think it is.
| However, ghc-0.24 (ancient, I know) and Hugs 1.3 both accept it without
| complaint.

I believe that it is legal, and attach an (inverted) parse tree below to
justify that claim:
                                b :: exp10                    c :: exp10
                                ----------                    ----------
  a :: exp10                       .                             .
  ----------                       .                             .
     .                          ---------                     ---------
     .                          b :: exp1  `bar` :: qop(r,0)  c :: exp1
  ----------                    ---------------------------------------
  a :: exp1   `foo` :: qop(r,0)   (b `bar` c) :: rexp0
  ----------------------------------------------------
       (a `foo` (b `bar` c)) :: rexp0
       ------------------------------
       (a `foo` (b `bar` c)) :: exp0
       -----------------------------
       (a `foo` (b `bar` c)) :: exp

However, in return, perhaps somebody can supply me with parse trees for
the following:

    - - 1                                (accepted by nhc and hbc)
    (- 1 `n6` 1)   where infix  6 `n6`   (accepted by nhc, hbc, ghc)
    (- 1 `r6` 1)   where infixr 6 `r6`   (accepted by nhc, hbc, ghc)

As I read the grammar (for 1.3), all of these should be illegal.  In
fact, the compilers don't even give consistent answers for the last
example:  ghc and nhc treat it as (-(1 `r6` 1)) while hbc treats it
as ((-1) `r6` 1).

The Hugs and Gofer parsers have always treated unary minus (incorrectly,
if you use the Haskell report as your bible) as having a higher
precedence than any operator, so Hugs and Gofer don't parse the above
correctly either.  It was while I was modifying the next release of Hugs
to give the behaviour specified in the Haskell report that I noticed
these discrepancies.  (Disclaimer:  The above results were obtained with
the versions of each compiler that I have to hand, and not necessarily
the most recent versions.)

All the best,
Mark

--------------------------------------------------------------------------
`Joy, Happiness, and Banana Mochas all round'
                                -- The JavaBeans(TM) 1.0 API specification
--------------------------------------------------------------------------



Reply via email to