Skip to main content
FUNCTIONAL-PROGRAMMING5 MIN READ

Make illegal states unrepresentable

Use algebraic data types to replace coordinated booleans with explicit domain variants.

The move: model the domain's valid choices directly. Algebraic data types are a way to say, "this value is one of these cases, and each case carries only the data it needs." That matters because many production bugs begin as impossible combinations that the code allowed. Flags multiply states Two booleans create four combinations. Three create eight. Most domains do not actually have eight valid states. The invalid states leak into conditionals, dashboards, migrations, and support scripts. Variants name the real states An ADT lets you represent the meaningful alternatives. Payment = Pending | Authorized(id) | Captured(id, amount) | Failed(reason)…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us