Rust: When Empty Isn't Bottom

7 points by ettolrach


hc

maybe i'm thinking about this in a way that type theorists don't

but i think of the bottom type in rust (and other languages) as being a subtype of every other type whether you have subtyping or not, because you can write an infinite loop that the compiler can't tell is infinite. or you can unplug it during execution. so, "never returns" is an outcome for every type

but the named empty type (!), or the multiple named types that are empty (in rust, any enum with no cases), are not necessarily subtypes of every type

for structural typing, they'd be the same thing. any uninhabited type is structurally identical

mond

Excellent post, thank you.

Is it generally true that type coercion only works at "the top level", i.e. has no support for variance? Maybe even "the difference between subtyping and type coercion is that subtyping has to support variance"?

That's probably completely wrong, I just always found it hard to explain (on a technical level) why these two concepts are different from each other.

gignico

The Haskell example makes use of laziness but what if I use strictness annotations? If I have an enum with !Void as the payload, do I still have to pattern match on that variant or does it behave like Rust where the variant is considered impossible?