TL;DR
The author argues that functional programming techniques and algebraic data types (ADTs) help prevent whole classes of runtime bugs by encoding domain rules in types. Concrete OCaml and TypeScript examples show how sum/product types, Options/Results, pattern matching and immutability make illegal states unrepresentable and refactors safer.
What happened
The piece sets out a practical case for applying functional programming ideas to high-reliability domains such as banking, telecom and payments. It demonstrates common failure modes—magic strings, nulls, conflicting booleans and incomplete lifecycles—and shows how modeling domain state with algebraic data types (product and sum types) prevents those invalid states from arising. The author provides examples in OCaml and TypeScript: a discriminated Payment type, a transaction lifecycle (TxnState) that blocks illegal transitions via Result returns, a Call type that separates billable from non-billable states, and parsing utilities that return Result or Option values instead of producing NaN or throwing. Pattern matching and exhaustiveness checks are highlighted as compiler-driven safeguards during refactors. The article also emphasizes Options/Results over nulls and exceptions, and notes immutability and pure functions as aids to predictable behaviour and easier testing.
Why it matters
- Encoding rules in types reduces the chance that code can enter invalid states at runtime.
- Compiler-enforced exhaustiveness turns many refactors into compile-time checks rather than runtime incidents.
- Explicit Option/Result handling makes error and absence cases as visible as success paths, improving robustness.
- Immutable data and pure functions improve predictability and testability in systems that need high availability.
Key facts
- Common production problems named include magic strings, unexpected nulls, conflicting booleans, and incomplete lifecycles.
- Product types (records) and sum types (tagged unions) are used together to model domain rules.
- Examples are provided in both OCaml and TypeScript to illustrate ADTs, pattern matching and discriminated unions.
- Pattern matching plus exhaustiveness checks forces code to handle each variant; adding a new case surfaces all sites that need updates.
- Transaction lifecycle example models states like Pending, Settled(ledger_id), Failed(reason) and Reversed(original_ledger_id) to prevent illegal transitions.
- Function return types like Result (Ok/Err) are used to represent permitted or blocked transitions instead of letting illegal state changes occur.
- Call lifecycle example separates dialing, connected, dropped and completed states so only Completed yields billable duration.
- Config parsing example shows parsing environment values into Result or Option types to avoid silent failures like NaN interpreted as zero.
- The author recommends avoiding null for optional values and not using exceptions for expected error channels.
What to watch next
- Compiler exhaustiveness checks: adding a new ADT variant triggers compile-time reminders to update matches (confirmed in the source).
- Whether teams in banking and telecom begin to model lifecycles with ADTs rather than implicit conventions (not confirmed in the source).
- Uptake of the migration playbook for juniors and mid-level engineers mentioned by the author (not confirmed in the source).
Quick glossary
- Algebraic Data Type (ADT): A composite type formed by combining product types (records/tuples) and sum types (variants) to model domain data precisely.
- Product type: A type that groups multiple fields together (think "and"), such as a record with named properties.
- Sum type (tagged union): A type that can be one of several distinct cases (think "or"), typically discriminated by a tag or variant constructor.
- Option / Maybe: A type representing presence or absence of a value without using null, usually as Some(value) or None.
- Result / Either: A type representing either a successful value (Ok/Right) or an error (Err/Left), used instead of exceptions for expected failures.
Reader FAQ
Do ADTs and functional techniques eliminate all bugs?
Not confirmed in the source.
Which languages are used in the examples?
The article uses OCaml and TypeScript to demonstrate ADTs, pattern matching and Result/Option usage (confirmed in the source).
Should teams stop using nulls and exceptions entirely?
The author recommends avoiding null for optional values and not using exceptions to represent expected errors, preferring Option and Result types (confirmed in the source).
Is there guidance for migrating existing codebases?
The article states it provides a migration playbook aimed at juniors and mid-level engineers (confirmed in the source).

Why Reliability Demands Functional Programming: ADTs, Safety, and Critical Infrastructure By Rastrian on 2025-09-16 at 16:29 UTC View on GitHub In banking, telecom, and payments, reliability is not a nice…
Sources
- Functional programming and reliability: ADTs, safety, critical infrastructure
- How can functional programming improve the reliability …
- All You Need to Know about Functional Programming
- How functional programming mattered – Oxford Academic
Related posts
- How a Father’s Fitness Might Be Packaged in Sperm RNA and Inherited
- What 4M Hacker News Posts Reveal About How Stories Go Viral and Timing
- Dad’s Fitness Encoded in Sperm RNA Could Influence Offspring Health