Hacker News new | ask | show | jobs
by jasdfasd 596 days ago
disjoint 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/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-fo...

I believe Java's checked exceptions behave somewhat like union types.

1 comments

What’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.
disjoint 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.