Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What about sum types? During 4 years I've been programming Go professionally I missed sum types more times than I missed generics. Writing yet another

  interface SumType {
      isSumType()
  }
won't kill me, but it does get annoying.


for sure. It would also be lovely to add sum types to Protobufs too, while we're at it. many message protocols are very neatly described with sum types in my opinion.

Also, errors would be way more elegant as a sum type:

instead of:

err, a := x

if err != nil { }

we can do:

switch a { Err(err) -> {}, Ok(a) -> {}, }

and avoid null pointers :) and then "check" is literally just "bind/ try!, flatMap, =<<" or however your language du jour calls it :)


Regarding Protobufs, did you mean something other than `oneof`?

https://developers.google.com/protocol-buffers/docs/proto#on...


Annoying and the performance is terrible, since pretty much every instance ends up being an allocation, and allocations in Go are quite a lot more expensive than in other GC languages. Further, it doesn't quite have the same semantics--if you return one of these interfaces, your caller still doesn't know what all of the permutations they have to check for.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: