Re:A rough proposal for sum types in Go (2018)
by stevefan1999 on Monday November 15, 2021 @07:08PM
(#29234777)
but golang already have a sum type: multiple return values
[ Parent
| on HN ]
Re:A rough proposal for sum types in Go (2018)
by saghm on Monday November 15, 2021 @07:50PM
(#29235131)
Multiple returns are a product, not a sum; in the case of (*Foo, error), you could return nil for both, or neither, which gives you four possible combinations (nil and nil, nil and an error, Foo and nil, and Foo and an error). A sum type would not let you return both a Foo and an error, just one or the other.
Re:A rough proposal for sum types in Go (2018)
by eksapsy on Tuesday November 16, 2021 @04:35AM
(#29238631)
This is a huge misunderstanding of what Sum types are. Someone already answered why multiple return types are completely different from sum types, I will also mention that a type is usually something that you define for variable types like int and string and structs, not only for what a function returns.