Re:Safer Enums in Go
by morelisp on Saturday May 14, 2022 @09:58AM
(#31377974)
I also like sum types, but I have intense whiplash from "this language is AN ABSTRACT MESS that needs a PhD in type theory to use productively" five years ago, to today's "this language is COMPLETELY USELESS because it doesn't have them".
[ Parent
| on HN ]
Re:Safer Enums in Go
by ravi-delia on Saturday May 14, 2022 @11:41AM
(#31379049)
I don't think anyone ever struggled with sum types (or at least, I hope not), they associated them with things like Haskell's monads, which are less commonly accessible (though they're undeserving of their reputation too). The hate was a little silly, but algebraic data types are clearly just an extension of the concepts everyone already knew.
> I don't think anyone ever struggled with sum types... algebraic data types are clearly just an extension of the concepts everyone already knew.
You're definitely in a bubble.
I can't count the number of C++ codebases I've worked on where either myself or some other engineer implemented an ad-hoc, incomplete "sum type-like" enumeration system, e.g. in linting, pre-compilers, etc. In my case, I've done it without even knowing what these were--my background is physics, not computer science. The concept isn't terribly difficult to understand, even if the jargon name for it isn't widely known, or is associated with more type-theory oriented languages.
Re:Safer Enums in Go
by nyanpasu64 on Saturday May 14, 2022 @12:23PM
(#31379520)
Rust is an abstract mess that needs a PhD (or type theory or guess-and-check) to use productively; it's more to do with overuse of generics and wildcard trait impl and trait resolution and higher-order functions and lifetime HKTs and reverse type inference, than sum types. Rust enums require less generics to use productively than C++ std::variant (which requires std::get_if or std::visit), because enums have language-level `match` and `if let` syntax as a fundamental binding block which can take the place of combinator method chaining (but the community instead sees it as an opportunity to invent and add even more methods).