SMLFamily / Successor-ML

A version of the 1997 SML definition with corrections and some proposed Successor ML features added.
193 stars 10 forks source link

Pattern guards and disjunctive patterns #42

Open ratmice opened 4 years ago

ratmice commented 4 years ago

I didn't see an issue for this, I hope it isn't retreading anything,

the summary of proposed changes contains both disjunctive patterns, and pattern guards. In the (very succinct!) paper ambiguous pattern variables by Scherer et al, from the ML workshop 2016, this combination lead to patterns whose interpretation probably won't match a users naive expectation.

In the case of Ocaml this lead to a new warning, I have yet to look at the proposed semantics for Successor ML to figure out if it is impacted, or if there is an terrible solution such as evaluating the guard twice which would work. As such, not really proposing anything, but thought it should be discussed.

Edit: Initially I had the thought that such cases could be resolved by expanding the pattern guard to evaluate to is_neutral n orelse is_neutral n' after alpha conversion, but this direction seems real misguided so I struck that out.

rossberg commented 4 years ago

Unlike OCaml, Successor ML can nest guards, so you can write a correct version of Scherer et al.'s example:

| (Const n if is_neutral n, a) | (a, Const n if is_neutral n) => a

Of course, that doesn't make the warning they discuss irrelevant.