Exhaustive compile time checking of dispatch statements is a wonderful thing, sorely missing from the languages that decided "sum types" are a bit weird and niche.
fredrikholm•4mo ago
They make it near impossible to extend from the outside.
I can pass a Reader interface to your function, but I cannot (easily) add a
> | UnusualProtocol(Socket)
as a third party consumer.
Other than that, sum types are the better abstraction. With exhaustive first class pattern matching (eg. with proper matching on destructuring), nothing comes close in terms of ergonomics.
hermanradtke•4mo ago
That is a feature. Compose instead of extending.
Yoric•4mo ago
OCaml has extensible sum types. They work very nicely for some ranges of problems.
swiftcoder•4mo ago
Elm <-> Rust
Best buds on this front
gitroom•4mo ago
Tbh, missing those checks in other languages bugs me so much - it's like why leave me hanging?
JonChesterfield•4mo ago
fredrikholm•4mo ago
I can pass a Reader interface to your function, but I cannot (easily) add a
> | UnusualProtocol(Socket)
as a third party consumer.
Other than that, sum types are the better abstraction. With exhaustive first class pattern matching (eg. with proper matching on destructuring), nothing comes close in terms of ergonomics.
hermanradtke•4mo ago
Yoric•4mo ago