2 ms·
"I'm not quite sure what you're trying to express, because all I'm reading in your comment is "you can get none of the benefits today with no changes", which do
by jerf 5y ago
"I'm not quite sure what you're trying to express, because all I'm reading in your comment is "you can get none of the benefits today with no changes", which doesn't seem like a very interesting statement?"
You can get some of the benefits today with no changes to Go. You can create a package-level sealed interface: http://www.jerf.org/iri/post/2917 http://www.jerf.org/iri/post/2917
"I don't understand why you insist on quoting "sum types" when literally just mentioning them."
Because they aren't literally sum types, in that they have every feature that everyone associates with sum types, and people are very sensitive about that. So I don't need anyone replying with "but those aren't really sum types", either for my previous HN post or the blog post I just linked. Yes, I know they don't check every check box. But they do check a few of them, and, arguably the most essential one which is that you can indeed implement
type ASumType interface {
unexportedMethod()
}
func SomeFunction(thing ASumType) { ... }
and ASumType can be any of several types, closed and limited at compile time to only be things defined in this particular package in a way that can not be extended by any other external package.