At 11:27 am 4/2/98, Lennart Augustsson wrote:
>> I think this one should be allowed; I can't remember anything in the
>> Haskell Report that says the lexical scoped must be strictly
>> increasing in indentation.
>No, the report is silent on this issue, as far as I can remember, but
>this means that it is ambiguous.

Isn't it rather that the report doesn't need to say this explicitly,
since it's covered by the general rule noted below (i.e., the
'(' below the case introduces a '}' and a ';', and the case is thus illegal
[or odd!] according to the report).  The expanded parse is

        do { case a of {}; (Just x,_) -> return x; _ -> error "hey"; }

which is illegal because case needs at least one branch, and the arrows
are the wrong way round.

>> f a
>>   = do
>>     case a of
>>     (Just x, _) -> return x
>>     _ -> error "hey"
>
>Since the `(' is at the same level as `case' it should
>generate a semi-colon according to the rules.  There is
>nothing in the report that says that entering a new
>layout should suspend processing the outer one.

And it shouldn't!  Lots of existing programs would go wrong if it did!

>I think it is clear that we want to allow the function
>above so the report should be clarified.

It seems better style to use the indentation, especially in more
complicated expressions.  How about things like

 f a
   = do
     case a of
     (Just x, _) -> return x
     r <- error "hey"
     case b of
     (Just x, _) -> x
     s <- return x

which would be legal if the rule was relaxed I believe.

>Something that Hugs allows, but that is illegal
>according to the report is
>
>> f a
>>   = do
>>     if x then
>>       y
>>     else
>>       z
>
>The `else' generates a semi-colon which makes this
>illegal.  Still, I would like to be able to write this.

This is a reasonable thing to want IMO.  Not sure how
you change the syntax though (allow optional ';' after then branches?!
That rather mixes up the use of ';' as a separator!).

It all sounds a bit like tinkering with syntax, though.

Regards,
Kevin

----------
Division of Computer Science,               Tel: +44-1334 463241 (Direct)
School of Mathematical                      Fax: +44-1334 463278
 and Computational Sciences,                URL:
http://www.dcs.st-and.ac.uk/~kh/kh.html
University of St. Andrews, Fife, KY16 9SS.


Reply via email to