Conversation

The gymnastics you have to do in imperative languages to approximate algebraic data types always feels very strange to me.
Quote Tweet
A few weeks ago we made use of Swift's powerful runtime metadata to compute the "tag" of any enum. Then we realized we could leverage that power to provide a huge performance boost to a critical part of the Composable Architecture 🤯 Learn how 👉 pointfree.co/episodes/ep152
Show this thread
Screenshot of code showing how to use Swift's runtime metadata to compute the tag of an enum.
7
73
Algebraic data types are like tagged unions. Abstract data types are modules with associated types that have their internal representation hidden, and some associated operations that can make use of the hidden internals in their implementation.
1
2
Note also that you can model algebraic data types through the use of abstract dataypes (you can even think of them _as_ abstract datatypes in languages that support them) - ie. an abstract type constructor, a bunch of data constructor operations, and a deconstructor operation.
1
2