> I'm not sure why it gets brought up other than language level FOMO.
I think it gets brought up because people see places it would be helpful quite often.
A lot of the Go code I've written has:
switch x {
case ....:
case ....:
default:
panic(fmt.Sprintf("inexhaustive match, please update this switch statement for %v", x))
}
Similarly, go supposedly has good error handling, but I constantly find myself writing:
switch {
case err == nil:
case errors.Is(err, SomeErr):
// handle SomeErr
case errors.Is(err, OtherErr):
// handle OtherErr
case strings.Contains(err.Error(), "tls: unknown certificate authority")):
// handle unexported go stdlib error, XXX fix after https://github.com/golang/go/issues/35234
default:
panic(fmt.Sprintf("unhandled error type: %v: %T", err, err))
}
Like, for being a statically typed language, Go's error handling is really bad, and sum types is the thing that would let me internally at least make error handling feel good.
I could have my own functions return up a non `error`-interface type, not implement the `error` interface intentionally to avoid the nil-typed-interface problem 'err' is otherwise prone to, and then I could actually know when I compiled my codebase that my error handling is good, and know what needs to be updated after adding new error paths.