Susan Potter

Algebraic Data Types (ADTs)


Algebraic Data Types in TypeScript

Note: the code for the TypeScript (to help you follow along) is available here: Encoding Algebraic Data Types in TypeScript code Background Recently I've been reviewing TypeScript code at work. A common pattern I've observed in pull requests and some open source projects is a type that looks like the following: type FooTag = 'Bar' | 'Baz' | 'Qux'; type Foo<A> = { _tag : FooTag, /* Required for the 'Bar' tagged values of Foo */ …


Algebraic Data Types: For the math(s) inclined

Unlock the mathematical elegance of algebraic data types (ADTs) and revolutionize your understanding of data modeling! Discover how algebraic principles can determine the cardinality of ADTs, allowing you to represent an astonishing number of values. Explore the power of sum types, where you can "sum up" the cardinalities of different data constructors to find the overall cardinality of the type. Dive into practical examples, such as representing colors with RGB and …


Algebraic Data Types

Unlock the power of algebraic data types to revolutionize your programming! Discover the flexibility of sum types, also known as tagged unions, and product types, also called record types. Dive into Scala examples and see how algebraic data types provide exhaustive and type-safe constructions. Explore the hybrid sum-product types and their applications in modeling complex domains like social network notifications. With algebraic data types, you can build robust and expressive …