6 votes

Representing heterogeneous data

1 comment

  1. ra314
    Link
    Interesting read! I learned a new word (sum type) for a concept that I already knew about. I use protocol buffers (protobuf) a lot in my work, and the oneof type in protobuf behaves the same way....

    Interesting read! I learned a new word (sum type) for a concept that I already knew about. I use protocol buffers (protobuf) a lot in my work, and the oneof type in protobuf behaves the same way. I've only used protobufs in Java, Python and C++ so those are the only languages I can speak for. But it works similar to the way it works in the language the author is developing. You usually have a switch case, and then access the details within the oneof. One difference though is that I don't think that protobufs have compile time validation which prevents you from accessing a oneof field without checking that it is set.

    https://protobuf.dev/programming-guides/proto3/#oneof

    1 vote