3 ms·
Wait so in Rust you can’t have an Option<Option<T>>? That’s really bad!
by chongli 3y ago
Wait so in Rust you can’t have an Option<Option<T>>? That’s really bad!
- nyanpasu64 3y agoIn Rust you can, in Python an Optional[Optional[int]] is the same as an Optional[int].
- gemstones 3y agoYou can have this, I’ve used it in Rust before.
- rtpg 3y agoYou can, because Rust doesn’t support first class Union, and uses ADTs. Something like Typescript allows you to write “(T | null) | null)” but that is not the same thing as a double-Option’d type.
- ratmice 3y agoRust actually does have an untagged union type, but it generally requires some unsafe to use it, doesn't seem to get much use beyond c/ffi.
- agrover 3y agoIt was added specifically for c/ffi, so this is cool.
- rtpg 3y agobut the untagged union is still an aggregate at the type level right? Your data is a union at runtime, but at the type level it's a distinct thing, yeah? TS in particular is offering bespoke anonymous unions, which is a different sort of beast.
- ratmice 3y agoOf course, rust being nominally typed it is a distinct thing, while TS is structural. But that aspect should affect much more than just unions, (that said I personally know very little about typescript so talk my opinions here with a grain of salt).
- lmm 3y ago> Wait so in Rust you can’t have an Option<Option<T>>? You can, Rust has sum types rather than union types. > That’s really bad! I agree, but some people seem to like union types for some reason.