3 ms·
but golang already have a sum type: multiple return values
by stevefan1999 5y ago
but golang already have a sum type: multiple return values
- saghm 5y agoMultiple 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.
- eksapsy 5y agoThis 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.