by mafalda · 5y ago · 0 comments
But considering the proposal itself. I would approach it much differently.
Sum types could be represented as a closed enum.
type Result enum int{…}
const ( Ok Result = iota{interface{}}, Err Result = iota{string} )
The initialization would be done like: Ok{10}
Err{“Something went wrong”}
The variable itself would act just like and other enum with unpacking being done somewhat close to this: Ok{variableName} := result
Where the variableName would be set to the zero value in case of a bad match.The enum prefix would enforce a single const block and no extension outside the module package.