A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Liquid Types

Research Depth 102 in the knowledge graph ☐ I know this ☆ Set as goal
545prerequisites beneath it
See this on the map →
Refinement TypesSMT Solving and Theory Combination+1 more→
liquid-haskell refinement-types smt-based-verification subtyping fluid-typing automatic-verification

Core Idea

Liquid types refine dependent types with liquid type checking — a technique that restricts refinements to a decidable subset of predicates (typically quantifier-free linear arithmetic), enabling fully automatic type checking via SMT solving. Rather than requiring users to manually prove type constraints (as in full dependent type theory), a liquid type checker automatically discharges proof obligations using an SMT solver. A liquid type for a list might be `[Int]<{v:Int | v > 0}>` (a list of positive integers). The type checker enforces this by verifying that all list-construction operations produce values satisfying the refinement, using SMT calls internally. Liquid Haskell is the most mature implementation, embedding liquid types into Haskell for practical verification without sacrificing automation or ease of use.

Explainer

Dependent types (in languages like Coq or Agda) allow types to depend on values, enabling extremely expressive type systems that can express complex properties. A dependent type `Vec(n)` represents vectors of exactly length n; you can express "the result is a list of length equal to the input" as a type. But dependent types come at a cost: verifying that a function satisfies its dependent type requires manual proofs, and the proof process is interactive and labor-intensive.

Liquid types strike a pragmatic balance. They refine ordinary types with logical predicates (drawn from a decidable logic), enabling strong correctness guarantees without manual proofs. The refinement is expressed as a liquid type annotation — a predicate that values of that type must satisfy. A liquid type for a list of positive integers is `{xs : [Int] | all(xs, \x -> x > 0)}` (in Liquid Haskell: `[Int]<{v:Int | v > 0}>`). The type checker automatically verifies that list operations maintain this invariant using SMT solving.

The key innovation is the restriction to decidable logics, typically quantifier-free linear arithmetic (QF_LIA) over integers. This logic is expressive enough to reason about:

But it excludes:

Restricting to this fragment makes the decision problem tractable: an SMT solver like Z3 can always determine whether a constraint is satisfiable in bounded time.

Liquid Haskell (developed at UC San Diego) is the most mature implementation. Users write Haskell code with liquid type annotations:

```haskell

-- A natural number (Int >= 0)

{-@ type Nat = {v:Int | v >= 0} @-}

-- A function that divides x by y, where y != 0

{-@ divide :: x:Int -> y:{Int | y != 0} -> Int @-}

divide x y = x `div` y

```

When this function is called with a non-zero divisor (e.g., `divide(10, 3)`), the type checker verifies the constraint is satisfied. If called with zero (e.g., `divide(10, 0)`), the checker rejects it at compile time — division by zero is a type error, not a runtime error. The user writes the type annotation once; the checker verifies it everywhere the function is called.

The checking process is fully automatic: the type checker generates SMT queries and delegates them to a solver (typically Z3). No user-written proofs, no interactive tactic languages, no expertise in formal logic required. This automation is the pragmatic breakthrough that makes liquid types practical for real code.

Applications include:

The limitations are inherent to the decidable logic restriction: you cannot express arbitrary mathematical properties or non-linear constraints. But for the common case of verifying safety and liveness properties (bounds, non-negativity, ordering, absence of errors), the automatic checking makes liquid types a practical and popular choice.

Current research extends liquid types to more expressive logics (nonlinear arithmetic with limited quantification, temporal properties) while maintaining decidability, and integrates them with other type system features (generics, polymorphism, modules) for real-world software verification.

Practice Questions 4 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Finite State Machines (FSMs) → Deterministic Finite Automata (DFA) → Nondeterministic Finite Automata (NFA) → Two-Way Finite Automata → NFA to DFA Conversion (Subset Construction) → DFA Properties and Minimization Algorithms → Regular Languages: Definition and Characterization → Context-Free Grammars (CFGs) → Pushdown Automata (PDA) → Equivalence of CFGs and Pushdown Automata → Closure Properties of Context-Free Languages → Limitations of Context-Free Languages → Pumping Lemma for Context-Free Languages → Turing Machines → Variants of Turing Machines and Equivalence → Nondeterministic Time Complexity and NP → The P vs. NP Problem → Complexity Class P: Polynomial Time → Complexity Class NP: Nondeterministic Polynomial Time → NP-Completeness and Cook-Levin Theorem → The Cook-Levin Theorem → Boolean Satisfiability, Cook-Levin, and Reductions → SAT Solving and Conflict-Driven Clause Learning → SMT Solving and Theory Combination → Liquid Types

Longest path: 103 steps · 545 total prerequisite topics

Prerequisites (3)

Leads To (0)

No topics depend on this one yet.