layout ambiguity

Sigbjorn Finne sof@galois.com
Fri, 3 May 2002 08:03:49 -0700


Hi,

thanks for the report. The code snippet you give isn't legal Haskell,
so no Haskell system should accept it (*). The CVS repository version
of Hugs correctly flags the layout error, the December 2001
(or earlier) releases don't.

That GHC accepts the code has now been flagged as a front-end bug,
so thanks again for helping us root out yet another layout gremlin.

--sigbjorn

* - it's illegal because when the layout algorithm sees the innermost
     "where", it looks for the indentation of the next lexeme ('y' in
"y=a").
     It is less indented than the enclosing context, so an empty "where"
     clause is emitted. Since 'y' is indented less than its 'new' context,
     the outer "where" clause is closed also, leaving us with the following:

main = print (f "hugs")
     where { f a = y where {}}
          y = a

     which doesn't constitute a legal program.

----- Original Message -----
From: "Edmund GRIMLEY EVANS" <Edmund.Grimley-Evans@arm.com>
To: <hugs-bugs@haskell.org>
Sent: Thursday, May 02, 2002 02:09
Subject: layout ambiguity


> This program gives different answers with Hugs and GHC. I think Hugs
> is wrong here: see section 2.7 of the Report, the sentence containing
> "{}". It wouldn't surprise me if GHC is wrong, too.
>
> You might say it's a bad program, so Hugs and GHC can both do whatever
> they want to, but I'd be a lot happier if at least one of them could
> signal an error. Can someone make Hugs give an error in cases like
> this?
>
> Edmund
>
>
> a = "ghc"
>
> main = print (f "hugs")
>     where f a = y where
>         y = a