Hi everyone,

There's consensus that `@` (imported from Haskell) is a bad binding operator for patterns, because it leads to the confusing-looking `@@` in, for example:

    struct Foo {
        field: int
    }

    ...

    match foo {
        foo@@Foo { field: x } => ...
    }

However, there is not consensus as to what to change it to. Suggestions are `=` and `as`.

The problem with `=` is that, if implemented naively, it makes our grammar ambiguous:

    let x = y = 3; // is x the result of evaluating `y = 3` (i.e. unit)
                   // or are x and y bound to 3?

The easiest way to fix this problem is to forbid `=` in irrefutable patterns, such as those introduced by `let`. However, this bifurcates the pattern grammar into the irrefutable-pattern grammar and the refutable-pattern grammar, with some conceptually-ugly overlap.

The alternative is `as`, like OCaml. However, this conflicts with `as` in the expression grammar. A subset of the expression grammar is part of the pattern grammar in order to permit matching against constants. Removing `as` expressions from the subset of expression productions permitted in patterns would mean that this would no longer do what you expect:

    match 22.0f32 / 7.0f32 {
        math::PI as f32 => println("Good grief!"),
        _ => {}
    }

So both `=` and `as` have drawbacks.

I don't really have any preference at all; I just need to know what to implement. Opinions?

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

Reply via email to