The type switch operator is inspired by the ? operator in Rust. Some points:
- The
? operator is inextricably linked with std::error::Error and is used for error propagation.
- For Whiley, a more general version of it is desirable.
In particular, since we have union types in Whiley, the ? operator should work with them. For example:
function test() -> (int|bool r):
int x = other()?
return x + 1
function other() -> (int|bool r):
1
What's happening here is that, by exploiting forward type information from x the ? operator attempts to resolve by pulling out the desired item, otherwise return what is left from the enclosing function. For that to type check, what's left must fit into the return type.
This then allows us to encode exceptional control flow roughly as is done in Rust.
The type switch operator is inspired by the
?operator in Rust. Some points:?operator is inextricably linked withstd::error::Errorand is used for error propagation.In particular, since we have union types in Whiley, the
?operator should work with them. For example:What's happening here is that, by exploiting forward type information from
xthe?operator attempts to resolve by pulling out the desired item, otherwisereturnwhat is left from the enclosingfunction. For that to type check, what's left must fit into the return type.This then allows us to encode exceptional control flow roughly as is done in Rust.