Re:A rough proposal for sum types in Go (2018)
by valenterry on Monday November 15, 2021 @10:07PM
(#29236264)
You are seeing it through the lense of an application developer. As a library author the world looks different though - here you cannot know/define the types in advance.
But considering the proposal itself. I would approach it much differently.
Sum types could be represented as a closed enum.
The initialization would be done like: The variable itself would act just like and other enum with unpacking being done somewhat close to this: 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.