Type-Driven Design
Type-driven design, designing with types, and domain modeling with types use the type system as a software-design tool: modeling states, APIs, workflows, errors, invariants, boundaries, and state transitions.
The core idea
A value moves from a weaker type to a stronger one once something about it has been established:
string → Email
string → UserId
number → PositiveQuantity
DTO → ValidatedOrder
AnonymousUser → AuthenticatedUser
DraftOrder → SubmittedOrder
SubmittedOrder → PaidOrderThe type records what has already happened and what operations are legal now.
An analogy is the documents you collect at an airport. Check-in gives you a boarding pass, security stamps it, and the gate asks only for the stamped pass, not for your booking, your passport and proof that you went through security. Each document is evidence that a step happened, and it’s what makes the next step possible. DraftOrder -> SubmittedOrder -> PaidOrder works the same way: you can edit only a draft and refund only a paid order, and the compiler plays the gate agent. Modeling such transitions is the subject of Workflows And States.
This is the software-design use of typed programming.
The recurring idea is:
untrusted / weakly typed value
│
│ runtime computation establishes P(x)
▼
value carrying evidence of P
│
│ static type checker preserves
│ that evidence through the program
▼
domain computationScala’s opaque type + smart constructor is a relatively lightweight version of this idea. Refinement and dependent type systems push more of P(x) itself into what the compiler can reason about.
Costs and failure modes
The approach has costs, and it can go wrong: conversion code at every boundary, types that lie because something constructs them without checking, facts that expire after they’re checked, modeling too precisely before the domain is understood, and encodings harder to read than the invariant they protect. These are worked through, with sources, in What Belongs In Types; the guard against most of them is the What Belongs In Types.
Notes in this section
The notes sit in five subfolders, in reading order; each folder has an index. Start with Reading paths to pick a route through the sources.
Foundations
Folder index. What a type system proves, and what to put in one.
- Type systems: Pierce’s definition, soundness and conservativity, and what type systems buy.
- Dimensions of type systems: static, dynamic and gradual checking; safety and what “strong” means; nominal and structural equivalence.
- Type inference: inference as ergonomics, and its limits.
- Types as propositions: the Curry-Howard correspondence and what it means for ordinary code.
- What belongs in the type system: types, contracts, runtime checks and tests; good targets; a decision procedure; where types stop matching reality; costs and failure modes.
Parsing and evidence
Folder index. How a value earns a stronger type.
- Parse, don’t validate: shotgun parsing, partial functions made total, where to parse, and where it gets harder.
- How strong the evidence is: constructive and encapsulated types, names that are not type safety, hidden constructors, ghosts of departed proofs.
- Types at the boundary: trust boundaries, DTOs and serialization, the database as a boundary, evolving types, and tolerant readers.
Domain modeling
Folder index. Types that say which values and states can exist.
- Domain modeling with types: overview, type-first design, the same ideas across languages, values and entities, errors as values.
- Newtypes and simple values: primitive obsession, newtypes and opaque types, constrained simple values.
- Algebraic data types: product and sum types, counting values, sums versus tagged classes and hierarchies.
- Making illegal states unrepresentable: business rules as choice types, booleans, a flag plus an optional value, behaviour as data.
- Workflows and states: workflows as function types, one type per state, state machines, typestate with phantom types, and long-running workflows.
Architecture
Folder index. From a typed domain to a program.
- Functional domain modeling: Ghosh’s principles, keeping effects out of the domain, modules as algebras with laws, composing effectful operations, commands and events.
- Effects, interpreters and wiring: Reader and Kleisli, free monads, ZIO, algebraic effects, and embedded DSLs.
- Tagless final: the encoding, rules for using it, two critiques, and the expression problem.
- Declarative design: declarative specifications and engines, four senses of “declarative”, DSLs, and semantic modeling.
Stronger type systems
Folder index. Predicates in types, types that depend on values, and Scala.
- Refinement types: predicates in types, how the checking works, and limits.
- Refinement types by language: what Python, TypeScript, Haskell, Rust, Ada and Scala offer, and Scala’s terminology trap.
- Towards dependent types: the progression from ordinary to dependent types.
- Scala type system: abstract types and the currency case study, nominal and structural subtyping, union and intersection types, path-dependent types, type tags, multiversal equality, and encoding contracts in Scala.
Across the section
- Reading paths: a map of every source with where it’s held, and curricula for practical type-driven design, runtime checks and type evidence, and type theory.
- Provenance: raw input, related private material, and the history of the notes.
Sources in the library
Every library source cited in this section, grouped by kind, with the notes and sections that use it. The Library sources list at the end of each note gives the reverse view, with what each source covers.
Books
- Abelson et al. 2022, Structure and Interpretation of Computer Programs, JavaScript Edition: Declarative Design, Declarative Design
- Alexander 2021, Scala Cookbook, 2nd Edition: Newtypes And Simple Values, Scala Type System
- Allen et al. 2016, Haskell Programming from First Principles: Type Inference, Parse Dont Validate, Strength Of Evidence, Types At The Boundary, Domain Modeling With Types, Algebraic Data Types, Algebraic Data Types, Newtypes And Simple Values, Reading Paths
- Bird 1998, Introduction to Functional Programming using Haskell, 2nd Edition: further reading in Types As Propositions
- Bloch 2018, Effective Java, 3rd Edition: What Belongs In Types, What Belongs In Types, Strength Of Evidence, Domain Modeling With Types, Algebraic Data Types, Newtypes And Simple Values, Scala Type System, Reading Paths
- Bodner 2024, Learning Go, 2nd Edition: Types At The Boundary, Domain Modeling With Types, Scala Type System
- Bragilevsky 2021, Haskell in Depth: Type Inference, What Belongs In Types, What Belongs In Types, Newtypes And Simple Values, Newtypes And Simple Values, Workflows And States, Refinement Types By Language, Dependent Types, Reading Paths; further reading in Tagless Final
- De Goes et al. 2025, Zionomicon: Effects And Interpreters, Tagless Final
- Fowler 2010, Domain-Specific Languages: Declarative Design
- Fowler 2019, Refactoring: Improving the Design of Existing Code, 2nd Edition: Newtypes And Simple Values
- Ghosh 2017, Functional and Reactive Domain Modeling: Algebraic Data Types, Illegal States Unrepresentable, Workflows And States, Functional Domain Modeling, Effects And Interpreters, Effects And Interpreters, Effects And Interpreters, Declarative Design, Reading Paths
- Gibbons and de Moor 2003, The Fun of Programming: Declarative Design; further reading in Effects And Interpreters, Tagless Final
- Granin 2025, Functional Design and Architecture: Functional Domain Modeling, Effects And Interpreters, Effects And Interpreters, Tagless Final, Declarative Design, Reading Paths
- Harper 2016, Practical Foundations for Programming Languages, 2nd Edition: Dimensions Of Type Systems, Types As Propositions, Parse Dont Validate, Reading Paths, Reading Paths; further reading in Refinement Types
- Jhala et al. 2020, Programming with Refinement Types: What Belongs In Types, Refinement Types, Refinement Types, Refinement Types, Dependent Types, Reading Paths, Reading Paths
- Khononov 2021, Learning Domain-Driven Design: Types At The Boundary, Domain Modeling With Types, Newtypes And Simple Values, Illegal States Unrepresentable, Workflows And States, Functional Domain Modeling, Functional Domain Modeling, Reading Paths
- Khononov 2025, Balancing Coupling in Software Design: Newtypes And Simple Values, Illegal States Unrepresentable
- Kleppmann et al. 2026, Designing Data-Intensive Applications, 2nd Edition: Dimensions Of Type Systems, Types At The Boundary, Reading Paths
- Krishnamurthi 2025, Programming Languages: Application and Interpretation, version 3: Type Systems, Dimensions Of Type Systems, Scala Type System, Reading Paths
- Kurt 2018, Get Programming with Haskell: Domain Modeling With Types, Domain Modeling With Types, Algebraic Data Types, Algebraic Data Types, Reading Paths; further reading in Types At The Boundary, Newtypes And Simple Values, Illegal States Unrepresentable
- Lammel 2018, Software Languages: Syntax, Semantics, and Metaprogramming: further reading in Declarative Design
- Maguire 2018, Thinking with Types: Type-Level Programming in Haskell: Type Systems, Types As Propositions, What Belongs In Types, What Belongs In Types, Strength Of Evidence, Strength Of Evidence, Algebraic Data Types, Newtypes And Simple Values, Workflows And States, Dependent Types, Reading Paths; further reading in Dimensions Of Type Systems, Refinement Types By Language
- Martin 2018, Clean Architecture: Functional Domain Modeling; further reading in Effects And Interpreters
- Milewski 2019, Category Theory for Programmers, Scala Edition: Types As Propositions, Algebraic Data Types, Scala Type System
- Millett et al. 2015, Patterns, Principles, and Practices of Domain-Driven Design: Domain Modeling With Types, Newtypes And Simple Values, Workflows And States, Functional Domain Modeling, Functional Domain Modeling
- Odersky et al. 2021, Programming in Scala, 5th Edition: Illegal States Unrepresentable, Refinement Types By Language, Scala Type System, Reading Paths
- Ousterhout 2018, A Philosophy of Software Design: further reading in What Belongs In Types
- Parsons 2023, Production Haskell: Type Inference, What Belongs In Types, What Belongs In Types, Parse Dont Validate, Parse Dont Validate, Parse Dont Validate, Strength Of Evidence, Strength Of Evidence, Types At The Boundary, Types At The Boundary, Domain Modeling With Types, Algebraic Data Types, Algebraic Data Types, Illegal States Unrepresentable, Functional Domain Modeling, Functional Domain Modeling, Effects And Interpreters, Effects And Interpreters, Effects And Interpreters, Tagless Final, Tagless Final, Refinement Types By Language, Dependent Types, Reading Paths, Reading Paths
- Percival et al. 2020, Architecture Patterns with Python: Parse Dont Validate, Types At The Boundary, Functional Domain Modeling, Functional Domain Modeling, Effects And Interpreters; further reading in Domain Modeling With Types, Newtypes And Simple Values
- Pierce 2002, Types and Programming Languages: Type Systems, Type Systems, Dimensions Of Type Systems, Dimensions Of Type Systems, Type Inference, Types As Propositions, What Belongs In Types, Dependent Types, Scala Type System, Reading Paths, Reading Paths, Reading Paths
- Pilquist et al. 2023, Functional Programming in Scala, 2nd Edition: Parse Dont Validate, Functional Domain Modeling, Reading Paths; further reading in Domain Modeling With Types, Workflows And States, Effects And Interpreters
- Płachta 2022, Grokking Functional Programming: Parse Dont Validate, Types At The Boundary, Algebraic Data Types, Newtypes And Simple Values, Illegal States Unrepresentable, Illegal States Unrepresentable, Reading Paths; further reading in Domain Modeling With Types, Workflows And States
- Ramalho 2022, Fluent Python, 2nd Edition: Type Systems, Dimensions Of Type Systems, Dimensions Of Type Systems, Types As Propositions, Refinement Types By Language, Scala Type System
- Richardson 2019, Microservices Patterns: With Examples in Java: further reading in Functional Domain Modeling
- Rosien 2021, Essential Effects: Functional Domain Modeling; further reading in Effects And Interpreters
- Scott et al. 2025, Programming Language Pragmatics, 5th Edition: further reading in Type Systems, Scala Type System
- Sebesta 2019, Concepts of Programming Languages, 12th Edition: Dimensions Of Type Systems, Dimensions Of Type Systems, Refinement Types By Language
- Seemann et al. 2019, Dependency Injection: Principles, Practices, and Patterns: Functional Domain Modeling, Effects And Interpreters
- Serrano Mena 2021, Book of Monads, 2nd Edition: Functional Domain Modeling, Functional Domain Modeling, Effects And Interpreters, Effects And Interpreters, Effects And Interpreters, Tagless Final, Tagless Final
- Serrano Mena 2022, Haskell: Almost Standard Libraries: Parse Dont Validate; further reading in Types At The Boundary, Algebraic Data Types
- Skinner 2023, Effective Haskell: Strength Of Evidence, Strength Of Evidence, Algebraic Data Types, Newtypes And Simple Values, Workflows And States, Reading Paths; further reading in Parse Dont Validate, Tagless Final
- Slatkin 2019, Effective Python, 2nd Edition: What Belongs In Types
- Suereth 2012, Scala in Depth: Scala Type System, Scala Type System, Scala Type System
- Thomas et al. 2020, The Pragmatic Programmer, 2nd Edition: Type Systems, What Belongs In Types, What Belongs In Types, What Belongs In Types
- Thompson 2023, Haskell: The Craft of Functional Programming, 3rd Edition: Type Inference, Strength Of Evidence, Strength Of Evidence, Algebraic Data Types, Effects And Interpreters
- Vernon 2016, Domain-Driven Design Distilled: Types At The Boundary, Types At The Boundary, Domain Modeling With Types, Algebraic Data Types, Workflows And States, Functional Domain Modeling, Functional Domain Modeling, Reading Paths
- Volpe 2021, Practical FP in Scala, 2nd Edition: Strength Of Evidence, Strength Of Evidence, Strength Of Evidence, Types At The Boundary, Tagless Final, Refinement Types, Refinement Types By Language, Reading Paths, Reading Paths
- Volpe 2023, Functional Event-Driven Architecture: Powered by Scala 3: Workflows And States, Refinement Types By Language, Reading Paths; further reading in Newtypes And Simple Values, Functional Domain Modeling, Scala Type System
- Wampler 2021, Programming Scala, 3rd Edition: Newtypes And Simple Values, Workflows And States, Dependent Types, Scala Type System, Scala Type System, Scala Type System, Scala Type System, Scala Type System, Reading Paths
- Wasowski et al. 2023, Domain-Specific Languages: Effective Modeling, Automation, and Reuse: Declarative Design
- Welsh et al. 2020, Scala with Cats: Parse Dont Validate, Functional Domain Modeling, Functional Domain Modeling, Reading Paths
- Wlaschin 2018, Domain Modeling Made Functional: What Belongs In Types, Parse Dont Validate, Parse Dont Validate, Types At The Boundary, Domain Modeling With Types, Algebraic Data Types, Algebraic Data Types, Algebraic Data Types, Newtypes And Simple Values, Newtypes And Simple Values, Illegal States Unrepresentable, Workflows And States, Workflows And States, Workflows And States, Functional Domain Modeling, Functional Domain Modeling, Reading Paths, Reading Paths, Reading Paths
Papers, articles and chapters
- Bauer et al. 2014, An Effect System for Algebraic Effects and Handlers: Effects And Interpreters
- Carette et al. 2009, Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages: Effects And Interpreters, Tagless Final; further reading in Declarative Design
- Erdweg et al. 2012, Language Composition Untangled: further reading in Declarative Design
- Gibbons 2006, Design Patterns as Higher-Order Datatype-Generic Programs: further reading in Functional Domain Modeling
- Gibbons et al. 2014, Folding Domain-Specific Languages: Deep and Shallow Embeddings: Effects And Interpreters, Tagless Final, Tagless Final, Declarative Design
- Guarino et al. 2009, What Is an Ontology? (doi:10.1007/978-3-540-92673-3): Declarative Design
- Guizzardi 2007, On Ontology, Ontologies, Conceptualizations, Modeling Languages, and (Meta)Models: further reading in Declarative Design
- Hackett 2020, Review of “Thinking with Types” (doi:10.1017/S0956796820000015): Types As Propositions, Reading Paths; further reading in Algebraic Data Types, Dependent Types
- Hudak 1996, Building Domain-Specific Embedded Languages (doi:10.1145/242224.242477): Effects And Interpreters, Declarative Design, Declarative Design
- Hughes 1990, Why Functional Programming Matters: Functional Domain Modeling
- Iung et al. 2020, Systematic mapping study on domain-specific language development tools: further reading in Declarative Design
- Khattab et al. 2023, DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines (arXiv:2310.03714): Declarative Design, Declarative Design
- King 2019, Parse, don’t validate: Parse Dont Validate, Parse Dont Validate, Parse Dont Validate, Parse Dont Validate, Reading Paths, Reading Paths, Reading Paths; further reading in Types At The Boundary, Illegal States Unrepresentable
- King 2020, Names are not type safety: Strength Of Evidence, Strength Of Evidence, Newtypes And Simple Values, Reading Paths, Reading Paths
- Kowalski 1979, Algorithm = Logic + Control: Declarative Design, Declarative Design
- Leduc et al. 2019, The Software Language Extension Problem: Tagless Final
- Mernik et al. 2005, When and How to Develop Domain-Specific Languages: further reading in Declarative Design
- Mokhov et al. 2020, Build Systems a la Carte: Theory and Practice: Declarative Design; further reading in Tagless Final
- Nielson et al. 1999, Type and Effect Systems: Type Systems; further reading in What Belongs In Types
- Noonan 2018, Ghosts of Departed Proofs (Functional Pearl) (doi:10.1145/3242744.3242755): Parse Dont Validate, Parse Dont Validate, Strength Of Evidence, Reading Paths, Reading Paths; further reading in Workflows And States, Dependent Types
- Peyton Jones et al. 2000, Composing Contracts: An Adventure in Financial Engineering (doi:10.1145/351240.351267): Effects And Interpreters, Declarative Design
- Plotkin et al. 2013, Handling Algebraic Effects: Effects And Interpreters
- Pretnar 2015, An Introduction to Algebraic Effects and Handlers: Effects And Interpreters; further reading in Type Systems
- Rondon et al. 2008, Liquid Types: Type Inference, Refinement Types, Refinement Types, Dependent Types, Reading Paths; further reading in What Belongs In Types
- Siek et al. 2006, Gradual Typing for Functional Languages: Dimensions Of Type Systems; further reading in What Belongs In Types
- Tan et al. 2026, Etas: An Effect-Typed Language for Agent Systems (arXiv:2607.17780): Effects And Interpreters, Declarative Design
- Vargas 2023, Why on earth a ZIO IO monad for Scala?: further reading in Effects And Interpreters
- Wadler 2015, Propositions as Types: Types As Propositions, Reading Paths, Reading Paths, Reading Paths; further reading in Refinement Types
- Wang et al. 2026, AgentSPEX: An Agent SPecification and EXecution Language (arXiv:2604.13346): Declarative Design
Slides
- Schwarz 2019, Monads do not Compose: Functional Domain Modeling
- Schwarz 2020, Scala 3 by Example: ADTs for DDD, Part 1: Domain Modeling With Types, Algebraic Data Types, Reading Paths, Reading Paths
- Schwarz 2023, Kleisli composition, flatMap, join, map, unit: Functional Domain Modeling
- Schwarz 2023, A sighting of traverse_ in Practical FP in Scala: further reading in Functional Domain Modeling
Named in the notes, not in the library
Works the notes recommend or quote that have no local copy, in the library or elsewhere on this computer:
- Books: Edwin Brady, Type-Driven Development with Idris; Vlad Riscutia, Programming with Types; Dan Vanderkam, Effective TypeScript; Jon Gjengset, Rust for Rustaceans; Sandy Maguire, Algebra-Driven Design; Friedman and Christiansen, The Little Typer (all in Reading Paths); Miran Lipovača, Learn You a Haskell for Great Good! (quoted in Domain Modeling With Types).
- Free online material, linked from Reading Paths but not saved: Scott Wlaschin’s Designing with Types series, Software Foundations, Programming Language Foundations in Agda, and Niki Vazou’s Liquid Haskell course.
Related material elsewhere
Sections inside larger notes:
- Recursion and folds: the “Type-Driven Approach” reading of fold signatures under
## Folds. - Type classes and polymorphism:
## Type classes, and the link-only sections## GADTsand## Type-level programming. The “scala sealed trait as ADTs” jot is in FP links to sort under## Topics to study. - CPython, the JVM, and polymorphism:
## Runtime validation and annotation-based dispatch(static checking vs Pydantic validation at boundaries). - Intent-driven architecture:
## DDD practices(strategic DDD, Event Storming).
Applied in projects:
- Language choice for AI systems: strong type systems as feedback for AI-generated code.
- Behavioral types and protocols and Type-oriented functional harnesses: types applied to AI system design.