[m-dev.] proposal: require_switch_arms_{det,semi,...}
Zoltan Somogyi
zoltan.somogyi at runbox.com
Thu Nov 13 13:49:20 AEDT 2014
A while ago I added require_complete_switch to the language.
This requires the switch arms to cover all possible cases, but
allows them to have any determinism. I think it would be
a good idea to add another construct that is the opposite:
it would allow some function symbols in the type of the
switched-on variable not to be covered, but would require
each switch arm to have at least the specified determinism
(so you could allow a det arm in a require_switch_arms_semi
scope, but not a semidet arm in a require_switch_arms_det
scope).
The motivation is some code I will soon post for review,
which does parsing of string.format specifier strings. In the
presence of unicode, you cannot have a complete switch
on characters, but for each character that *is* a specifier,
you want to handle it with det code, since you want to guarantee
that you get back either a description of the specifier or an
error message.
You can get this effect now by wrapping each arm in a
require_det scope, but (a) this is ugly, and (b) it allows
bugs in which some switch arms are not so wrapped to go
undetected.
Any opinions?
Zoltan.
More information about the developers
mailing list