On Sun, Dec 22, 2013 at 7:37 PM, Léo Testard <[email protected]> wrote:

> Hello,
>
> Le 22 déc. 2013 à 18:59, Stefan Plantikow <[email protected]> a
> écrit :
>
> > Hi,
> >
> > Am 22.12.2013 um 16:47 schrieb Gábor Lehel <[email protected]>:
> >
> > This is a nice idea.  At first I thought it wouldn’t work with `if` but
> in expressions `if` requires `else` so the grammar wouldn’t be ambiguous:
> >
>
> No, it doesn't. As long as the if's "true block" returns unit.
> let foo = if ... { }; is perfectly legal, even it doesn't make much sense
> in practice.
>
> Leo
>

Thinking about this, if we say that `else` following a `let` is allowed if
*and only if* the pattern is refutable, then this wouldn't actually be
ambiguous, because something of type `()` can never be refutable. Therefore
`let ... = if { ... } else { ... };` can only be legal if the `else`
belongs to the `if`.

I'm not completely clear on the relationship between grammatic and semantic
ambiguity. Would the grammar still be ambiguous in this case? I would
naively think that you're not allowed to take types and such into account
at the grammar level, but Rust seemingly already does so w.r.t. whether or
not things (such as `if`) return `()`, so I'm a little bit confused. Can
someone explain?



>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to