Walter Bright:

Oh come on. That's called a "user defined type."

This D code compiles and it throws an "Enforcement failed" Exception at runtime:

import std.typecons: Nullable;
void main() {
    Nullable!int x;
    int y = x;
}


With a different type system the compiler makes sure at compile-time that x is not empty (this means the compiler makes sure in no code paths x is used before testing it contains something), avoiding the run-time exception.

Bye,
bearophile

Reply via email to