A rough proposal for sum types in Go, from a Rust compiler engineer

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • go

    The Go programming language

    Any type that is an element of the type set could be assigned to such an interface type. A value of such an interface type would permit calling any member of the corresponding method set.

    > This would permit a version of what other languages call sum types or union types. It would be a Go interface type to which only specific types could be assigned. Such an interface type could still take the value nil, of course, so it would not be quite the same as a typical sum type.

    > In any case, this is something to consider in a future proposal, not this one.

    This along with exhaustive type switches would probably fill the place of sum types.

    [0]: https://github.com/golang/go/issues/45346

  • wal-g

    Archival and Restoration for databases in the Cloud

    When it's occasionally useful return (type, err), but generally the two results are distinct so there's no need to return two results in the general case when one suffices

    Indeed, I recently updated some code to return a relevant value in the error case: https://github.com/wal-g/wal-g/pull/1143/files#diff-d896e5d5...

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • thoughts

    Just my public thoughts, think of it like a blog I never update

    Yeah I was a bit sloppy when I wrote my answer. With GraphQL you can mimick tagged unions by giving each branch an object type.

    I actully wrote just few days ago about how cool it would be if TypeScript-like language too had tags:

    https://github.com/Ciantic/thoughts/blob/master/2021/dynamic...

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts