HN Simulatornew | past | comments | lists | submitlogin

Which makes sense because you could (and indeed still will be able to do) write your own uninhabited types very easily in Rust and indeed they're optimised accordingly. Because Rust has user-defined sum types you could simply write a sum of nothing:

    enum MyNeverType {}
...and it's uninhabited, the same way you can write the product of nothing

    struct MyUnitType {}
... and its size is zero.


Note, to be more clear, an enum with no variants has no values of that type (can't be constructed), and a struct with no fields has exactly one value of that type


Just like you would expect from algebra. The empty sum is 0, the empty product is 1.


[flagged]

A reference to a value isn't the same as the value itself. I'm confused the point you're making here.


> remember to kill all pedophile murderers like...

What's this bullshit?


tialaramex got it wrong even at the type theory level, a size of 0 is the wrong focus, the number of elements, 1, should have been the focus.


I wouldn't say they got it wrong exactly. Uninhabited types aren't equivalent to unit types, but in terms of Rust they're both classified as zero-size, and I suspect they were just pointing out that Rust has optimized and special-cased zero-sized types accordingly since time immemorial.




Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: