Language.Haskell.Parser and layout rules

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Tue Feb 22 06:14:22 EST 2005


> >                                        A    B    C   D
> > ghc                                   yes  no   no  yes
> > hugs                                  yes  no   no  no
> > nhc98                                 yes  yes  no  yes
> > Language.Haskell.Parser.parseModule   no   yes  yes no
> > report                                no   no   no  no

... but I beg to differ with the row for the "report".  Looking
carefully at code examples A and B, notice the extra single space
indentation on the second line:

> > ** A:
> > g xs = do ys <- workM xs
> >            if null ys then return [] else do
> >            zs <- workM ys
> >            return zs

I believe nhc98 is correct in parsing this as:

    g xs = do ys <- workM xs (if null ys then return [] else do
                                 zs <- workM ys
                                 return zs)

> > ** B:
> > g xs = do ys <- workM xs
> >            if null ys then return [] else do
> >            zs <- workM ys
> >             return zs

Likewise, isn't the following parse correct?:

    g xs = do ys <- workM xs (if null ys then return [] else do
                                       zs <- workM ys (return zs))

> > ** C:
> > f xs = case xs of
> >           y:ys -> case ys of
> >           z:zs -> zs

We all agree that this is a parse error.

> > ** D:
> > f x = case x of
> >           False -> do
> >      { return x; }

Although it is technically wrong to accept this, Simon and I believe
it would be reasonable, because it is unambiguous.

Regards,
    Malcolm


More information about the Libraries mailing list