Hmm, the user is asking about the Curry-Howard correspondence, specifically the fundamental connection between logic and computer science. They want to know how propositions and proofs map to types and programs, and how this manifests in dependently typed languages.
Okay, first I need to state the core analogy clearly: propositions ↔ types, proofs ↔ programs. That’s the heart of it. Then I should explain why this is profound—not just a metaphor but an isomorphism where logical operations correspond to type constructors, and proof rules correspond to program combinators.
For dependently typed languages, the user is asking for a concrete manifestation. I should highlight how types can depend on values, which mirrors predicates depending on terms. The classic example is vectors with length encoded in the type—the type Vector A n depends on the natural number n. Proving a property about vectors (e.g., “appending preserves length”) becomes writing a function whose type encodes that property. The function itself is the proof.
I should also mention how this turns proofs into executable code and ensures correctness by construction. Maybe mention Idris or Agda as examples. Keep it concise but precise—no fluff, just the structural parallels and the dependently typed payoff.
Wait, the user said “explain” but also “what is the fundamental connection.” So I’ll start with the high-level mapping, then drill into dependently typed languages as the natural extension where the correspondence becomes visually obvious. Avoid tangential history unless relevant. Focus on the isomorphism and the practical implication: programs as proofs, types as specifications.
The Curry-Howard correspondence (also called the Curry-Howard isomorphism) is a direct structural analogy between:
- Logic (proof theory) and
- Type theory (as used in programming languages).
Its fundamental insight is: "Proofs are programs, and propositions are types."
The Core Analogy
| Logic (Proof Theory) | Type Theory (Programming) |
|---|
| Proposition (a statement that can be true or false) | Type (a classification of values) |
| Proof of a proposition (a construction demonstrating truth) | Program (or term) of a type (a value inhabiting that type) |
| Proof rule (e.g., implication introduction) | Type constructor or function type |
| Logical consequence (Γ ⊢ A) | Typeability (Γ ⊢ t : A) |
Breaking Down the Analogy
-
Proposition ≡ Type
- A logical statement like "If it rains, the ground gets wet" (
Rain → WetGround) is seen not as a truth-valued sentence, but as a type definition.
- The type
WetGround is a valid output type only if the input is of type Rain. This is exactly the function type Rain -> WetGround.
-
Proof ≡ Program
- A proof of
Rain → WetGround is a construction method: "Assume it rains (we have a proof of Rain), then by physical law X, we can construct a proof of WetGround."
- This construction method is identical to a function that takes an argument of type
Rain and produces a result of type WetGround.
- The steps of the proof correspond to the expressions and evaluations of the program.
Example:
- Logic: To prove
A ∧ B (A and B), you must provide a proof of A and a proof of B.
- Programming: A value of the pair type
(A, B) is a pair containing a value of type A and a value of type B.
- The pair constructor
(a, b) is the proof rule for conjunction introduction.
How This Manifests in Dependently Typed Languages
Dependently typed languages (like Idris, Agda, Coq, Lean) take the Curry-Howard correspondence to its logical extreme. Here, the analogy becomes not just elegant but practically powerful.
Key Feature: In these languages, types can depend on values (not just other types).
Vector A n: A type of lists of elements of type A with a specific, known length n (a value-level natural number).
- The proposition: "There exists a list of length 5."
- The type:
Vector String 5.
This enables types to express precise logical predicates about programs.
Concrete Manifestation:
-
Specifications as Types: You can write a function whose type itself states a correctness property.
- Proposition: "Appending two vectors of lengths
n and m produces a vector of length n + m."
- Type:
append : (v1 : Vector A n) -> (v2 : Vector A m) -> Vector A (n + m)
- Program (Proof): You must write a function that, given
v1 and v2, returns a Vector A (n + m). The type checker verifies that your implementation respects the length property. The code you write is the proof.
-
Elimination Rules as Case Analysis: The logical rule to prove something from A ∨ B (A or B) is to handle both cases. This maps directly to programming a case or match expression on a sum type (Either A B).
-
Proofs Become Verified, Executable Programs: In Coq/Lean, you "prove a theorem" by writing a functional program whose type is the theorem statement. Once the type checker accepts it, you have a machine-verified proof. You can then extract that program to Haskell, OCaml, or Scheme as guaranteed-correct code.
-
Total Functional Programming: Because every program must have a type and every type must be inhabited by a total (terminating) program to be a valid proof, dependently typed languages naturally enforce totality. A "proof" cannot get stuck or diverge.
Summary
- Fundamental Connection: An isomorphism between the syntactic structures of logical proofs and well-typed programs. The rules of logic are in one-to-one correspondence with the rules of type formation and term construction.
- In Dependently Typed Languages: This isomorphism is exposed and exploited. The language's type system is so expressive that types become logical specifications and functions become constructive proofs. Writing a program that type-checks against a rich dependent type is simultaneously writing a formally verified proof of the proposition encoded in that type. The boundary between programming and proving vanishes.