On Mon, Nov 30, 2009 at 11:12:36AM +0000, Duncan Coutts wrote:
> On Mon, 2009-11-30 at 09:16 +0000, Simon Marlow wrote:
> > On 29/11/2009 19:40, Duncan Coutts wrote:
>
> > > Here's the main one it cannot cope with that bothers me:
> > >
> > > foo x = case bar x of
> > > Pattern1 -> ...
> > > Pattern1 -> ...
> > >
> > > where
> > > baz = ...
> > >
> > > The new layout requires it to be:
> > >
> > > foo x = case bar x of
> > > Pattern1 -> ...
> > > Pattern1 -> ...
> > > where
> > > baz = ...
> >
> > Right. That one isn't fixable, because there's no way for the algorithm
> > to know that the 'where' should close the layout context introduced by
> > the 'case', without knowing more about the syntax.
>
> Hmm, 'where' is a keyword though, so can't that be done at the lexical
> level without having to tangle it with the parsing?
I think it would be possible to have a special rule for this case, but
it would be an odd rule in my opinion. I'm not sure it would be possible
to explain why we had the rule, other than "because Haskell 98 behaved
that way".
I have no idea how common the pattern is in general, so I don't know how
important backwards compatibility is in this case. Hopefully we can do
some hackage testing at some point.
> > The new code isn't really that much simpler, in that it's full of
> > special cases. It is conceptually simpler in the sense that it is an
> > independent pass, rather than a collaboration between the parser and lexer.
>
> I appreciate you want to be able to separate the lexer from the parser.
> If we can do that without uglifying normal cases and only mess up a
> couple very rarely used corner cases then I think that's fine.
Out of interest, without trying it, what do you think this program
should print (the only difference between the 3 functions is the
indentation of the "where" line)?:
main = do print $ f1 1
print $ f2 1
print $ f3 1
f1 x = x + case () of
() -> x
where x = 5
f2 x = x + case () of
() -> x
where x = 5
f3 x = x + case () of
() -> x
where x = 5
Thanks
Ian
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc