4 ms·
Optionals can't be expressed safely in Go. They have a type of `Option<T>` or `Maybe<T>`. Swift just has this notion built as an operator. Traditional enums ar
by TheHydroImpulse 11y ago
Optionals can't be expressed safely in Go. They have a type of `Option<T>` or `Maybe<T>`. Swift just has this notion built as an operator.
Traditional enums aren't particularly interesting. What languages like Rust and Swift have are tagged unions. They let you associate data with each variant.
Moreover, pattern matching is needed to use tagged unions effectively.
Constants are not "basically" tagged unions or even enums. They are not grouped into a parent type. For example, if you have a `Foo` enum with `A` and `B` variants; while matching or accepting this, you can accept a `Foo` which is guaranteed to be either `A` or `B`.
How would Go typed constants achieve this?