[m-dev.] proposal: require_switch_arms_{det,semi,...}

Paul Bone paul at bone.id.au
Thu Nov 13 14:02:28 AEDT 2014

On Thu, Nov 13, 2014 at 01:49:20PM +1100, Zoltan Somogyi wrote:
> 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?

I think this makes sense and your example makes it even clearer that this
feature is desirable.

I also can't think of any reason why I wouldn't want this.

Paul Bone

More information about the developers mailing list