6 ms·
Sum types are indeed great. That's why they're in Go 1.18. Pipe syntax and all.
by pie_flavor 5y ago
Sum types are indeed great. That's why they're in Go 1.18. Pipe syntax and all.
- jchw 5y agoAs far as I know, that’s only for interfaces, and it’s more like a union and not a sum type. I’m talking about sum types for structs, like Rust has with enum. (I realize I’m replying ridiculous fast here, but I just happen to click over to Comments on the first minute. Dumb luck.) Of course, I could just use Rust, but it’s much harder to make idiomatic Rust libraries than it is idiomatic Go libraries, and I think that fact stunts the ecosystem a bit. Go may encourage you to use a map to an empty struct for a set, or a weird if statement syntax that contains a full statement instead of a more elegant looking match or for expression, but I find its little quirks to be manageable and without a terrible amount of consequence. Generics will probably bring some good, like the end of needing weird slice tricks, but I’m still concerned it won’t be overall worth it.
- dragonwriter 5y agoGo has (untagged) union types, not sum (tagged union) types.