Algebraic data type
An algebraic data type is a composite type whose values are formed from product structures, finite alternatives, or both through type constructors.
Functional Design and Architecture: Examples in Haskell
An algebraic data type is a composite type formed from alternatives, products, or both, with its structure described by type constructors.
- How it is used
- Models domain values and eDSL commands so applications can describe operations separately from their interpretation.
- How deep it goes
- Works through command constructors and a partial interpreter, then develops free-monad wrapping; leaves the full smart-home interpreter unspecified.
- Examples
- Uses a smart-home sensor script, a sandwich-building recipe, and meteor records with different database field types.
- What you can do after
- Build it from scratch: define an ADT-based eDSL, assemble a pure script, and interpret its commands as actions.
Read how Functional Design and Architecture: Examples in Haskell explains algebraic data type →
The Joy of JavaScript
A composite type formed by combining simpler types with sum and product structure to represent a finite set of possibilities.
- How it is used
- Uses composable objects to handle validation, errors, and mutually exclusive outcomes without scattering checks through function pipelines.
- How deep it goes
- Defines immutable composite types, distinguishes records from choices, and works through validation chains and a Promise analogy.
- Examples
- Uses an immutable Pair, success-or-failure validation, a blockchain-checking chain, and Promise states.
- What you can do after
- Build it from scratch as a Validation type and compose checks with flatMap instead of repeated branching.
Read how The Joy of JavaScript explains algebraic data type →
Functional Programming in Scala, Second Edition
An algebraic data type is a data type defined as a sum of one or more data constructors, where each constructor is a product of its arguments.
- How it is used
- Models immutable functional data structures and explicit success-or-failure values for pure, pattern-matched computation.
- How deep it goes
- Defines sums and products, demonstrates Scala encodings, and works through recursive tree and list operations without formal algebraic derivations.
- Examples
- Uses tuples, binary trees, singly linked lists, and error types including Option, Either, Try, and Validated.
- What you can do after
- Build immutable lists and trees, operate on their constructors with pattern matching, and represent errors as composable values.
Read how Functional Programming in Scala, Second Edition explains algebraic data type →
Learn Haskell by Example
An algebraic data type is a user-defined type formed from one or more named constructors, potentially carrying fields.
- How it is used
- Encodes command-line options so parsing and later control-flow decisions operate on named values rather than raw strings.
- How deep it goes
- Defines constructors and applies them in parsing, comparison, and function selection, while deferring a detailed treatment of deriving.
- Examples
- Uses line-numbering options for reversing numbering, skipping empty lines, and left-aligning output.
- What you can do after
- Build command-line option representations and parsers that select different line-numbering behaviors.
Read how Learn Haskell by Example explains algebraic data type →
Write Powerful Rust Macros
An algebraic data type is a composite type formed from product and sum type constructors to represent a defined set of values.
- How it is used
- Frames algebraic data types as a practical foundation for representing success and failure without exceptions.
- How deep it goes
- Defines product and sum types, then demonstrates enum matching and value mapping without developing their full implementation details.
- Examples
- Uses a u8-and-boolean struct, an Either success/failure enum, matching, and a map operation.
- What you can do after
- Apply enums and pattern matching to represent and handle explicit success-or-failure outcomes.
Read how Write Powerful Rust Macros explains algebraic data type →
Related concepts
- Haskellused by · Haskell is a statically typed, purely functional programming language with non-strict, typically lazy evaluation.
- data constructoruses · A data constructor is a named alternative of an algebraic data type that creates values of that type, optionally containing arguments.
- Eitherincludes · Either is a sum type representing one of two alternatives, conventionally called Left and Right and often used for failure and success outcomes.
- optionincludes · An option type is a type that represents either a value of a specified type or its absence, typically as distinct alternatives.
- tupleincludes · A tuple is a finite, ordered collection of elements treated as a single composite value or record.
- union typeincludes · A union type is a type whose values can be any one of several specified alternative types or variants.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




