extra semi-colons

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

extra semi-colons

Johannes Waldmann-2
Dear Cafe,


why does ghc accept the extra semi-colon in

   case () of { () -> (); }

or even

   case ()  of  { ;;; () -> () ;;; }


Yes I understand that semicolons like this
are introduce by the layout rule

   L (<n> : ts) (m : ms) = ;  :  (L ts (m : ms)) if m = n

https://www.haskell.org/onlinereport/haskell2010/haskellch10.html#x17-17800010.3

and it's convenient to ignore extra ones.


But it's not in the grammar?

   alts → alt1 ; … ; altn    (n ≥ 1)

https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13


- J.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: extra semi-colons

Tom Ellis-5
On Tue, Jun 25, 2019 at 12:43:03PM +0200, Johannes Waldmann wrote:
> But it's not in the grammar?
>
>    alts → alt1 ; … ; altn    (n ≥ 1)
>
> https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13

The rule "alt" allows "(empty alternative)"
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: extra semi-colons

Johannes Waldmann-2
In reply to this post by Johannes Waldmann-2
> The rule "alt" allows "(empty alternative)"

Ah, yes. But no? The standard says

> A case expression must have at least one alternative
> and each alternative must have at least one body.

Should this be "each non-empty alternative must have ..."?

I think the intention is to allow

    case () of () | False -> () | True -> ()

(one alternative, two bodies) but to disallow

    case () of ()

(one alternative, no body)

- J.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: extra semi-colons

Brandon Allbery
As of at least recently, empty cases are entirely permitted (and used for e.g. Void / nullary types).

On Wed, Jun 26, 2019 at 3:08 PM Johannes Waldmann <[hidden email]> wrote:
> The rule "alt" allows "(empty alternative)"

Ah, yes. But no? The standard says

> A case expression must have at least one alternative
> and each alternative must have at least one body.

Should this be "each non-empty alternative must have ..."?

I think the intention is to allow

    case () of () | False -> () | True -> ()

(one alternative, two bodies) but to disallow

    case () of ()

(one alternative, no body)

- J.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.


--
brandon s allbery kf8nh

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: extra semi-colons

Johannes Waldmann-2
On 6/26/19 9:09 PM, Brandon Allbery wrote:
> As of at least recently, empty cases are entirely permitted

Yes I know, but this is not about "empty case" (= no alternative?),
but about one (or more) empty alternatives
(that are accepted without -XEmptyCase ).

I admit it's not related to any practical problem.
It came up in the following way: a student
who compared  ghc's  behaviour to that of a purpose-built parser
for case expressions that I wrote for my e-Learning/testing system.

And I thought - well, the Standard certainly should
explain ghc's behaviour, but I have a hard time parsing it.

More nit-picking: while   "case () of { }"
prompts the "Use EmptyCase" hint,
"case () of { ; }" is a parse error (no hint),
with or without -XEmptyCase.

- J
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.