3 ms·
I don’t think it is appropriate to say Rust has ‘union types’. Rust has sum types, implemented as Enums and (unsafe) Union types. There is a distinct difference
by throwaway17_17 2y ago
I don’t think it is appropriate to say Rust has ‘union types’. Rust has sum types, implemented as Enums and (unsafe) Union types. There is a distinct difference between sum types and union types from a type theoretic perspective.
- jasdfasd 2y agodisjoint union vs union. Scala3 is the only programming language to implement both AFAIK. C# has a proposal to add both unions and disjoint unions: https://github.com/dotnet/csharplang/blob/main/proposals/TypeUnions.md https://github.com/dotnet/csharplang/blob/main/proposals/Typ... OCaml has polymorphic variants which are open disjoint unions. Kotlin is looking to add union types for errors: https://youtrack.jetbrains.com/issue/KT-68296/Union-Types-for-Errors https://youtrack.jetbrains.com/issue/KT-68296/Union-Types-fo... I believe Java's checked exceptions behave somewhat like union types.
- deleted 2y ago[deleted]
- om2 2y agoWhat’s the difference between a union type and a disjoint union type? In that C# proposal I couldn’t tell which syntax was which branch of your dichotomy.
- noelwelsh 2y agodisjoint union is sum type / enum / algebraic data type. Defined at the point of declaration. Each case is distinct (hence, disjoint) union is what Typescript has. Defined at the point of use. Cases need not be distinct.
- randomdata 2y ago> Rust has sum types, implemented as Enums Do you mean implemented with enums? Enums themselves are not a type. They are a mechanism for value generation, providing automatic numbering (hence enumeration) for constants. Indeed, they, like all values, are ultimately represented by a type, but that type can range from something like a simple integer or something more complex like a tagged union (typically with the generated value being the tag) with different ecosystems favouring different type approaches.
- tubthumper8 2y agoI think they just mean that sum types are defined by the programmer using the `enum` keyword
- randomdata 2y agoLike how subroutines are implemented as Functions. And by Functions you don't mean functions, but rather the letters fn? That is certainly an interesting way to communicate.
- kaba0 2y agoOff topic, but rust really messed up the terminology by using 'enums' for sum types.