[pattern-switch] Opting into totality

Guy Steele guy.steele at oracle.com
Fri Sep 4 02:24:24 UTC 2020

There is currently a fundamental unpleasant asymmetry caused by the arbitrary decision to require that all switch expressions be total but not all switch statements be total.

As we have added other options, the design space still has an unpleasant asymmetry (or lack of orthogonality) because of that original decision.

We have two choices: (a) recant that original decision, or (b) live with the asymmetry.

As I have already pointed out, (a) is certainly possible and completely consistent; all you have to do is return default values for the cases that are not covered.  Then the choice of switch-versus-expression is completely independent of the choice of regular-switch versus total-switch.  The likely result is that authors and IDEs will warn programmers that they should NEVER EVER use a non-total switch expression, so it seems silly to expand the design space to provide a combination of features that should never be used.  (“What, never?”  “Well, hardly ever.”)

The other choice, which is what Rémi and Brian have been discussing for the last week, is not whether to get rid of the asymmetry, but merely debating exactly what its shape should be.

A possibility I don;’t think I have yet seen offered is that we should, as before, require switch expressions to be total, but also, in an incompatible move, require switch expressions to use whatever `total-switch` syntax is adopted.

In such a scenario, perhaps we really are trying to move the world to `snitch` after all, and we’re just arguing about the least disruptive spelling for it.


More information about the amber-spec-experts mailing list