Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Couldn'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.


You can just default to the first variant, no?


Said "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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: