4 ms·
Type arguments, union types, and a sound type system: pick any two. For example, imagine the following in an imaginary version of Rust with union types: #
by Nullabillity 4y ago
Type arguments, union types, and a sound type system: pick any two.
For example, imagine the following in an imaginary version of Rust with union types:
#[derive(PartialEq)]
struct Option<T> {
value: T | (),
}
impl<T> Option<T> {
fn some(value: T) -> Self {
Self { value }
}
fn none() -> Self {
Self { value: () }
}
fn is_none(&self) -> bool {
match self.value {
_: () => true,
_: T => false,
}
}
}
What does `Option::some(()).is_none()` return? Is `Option::some(()) == Option::none()`?