6 ms·
annoyingly go can't have proper sum types, as the requirement for a default value for everything doesn't make any sense for sum types
by blueberry87 2y ago
annoyingly go can't have proper sum types, as the requirement for a default value for everything doesn't make any sense for sum types
- andyferris 2y agoYou can just default to the first variant, no?
- throwaway143829 2y agoCouldn't the zero value be nil? I get that some types like int are not nil-able, but the language allows you to assign both nil and int to a value of type any (interface{}), so I wonder why it couldn't work the same for sum types. i.e. they would be a subset of the `any` type.
- randomdata 2y agoSaid "requirement" is only a human construct. The computer doesn't care. If the humans choose to make an exception for that, it can be done. Granted, the planning that has taken place thus far has rejected such an exception, but there is nothing about Go that fundamentally prevents carving out an exception.