The Curry–Howard correspondence is a profound observation in computer science and mathematical logic that establishes a direct relationship between formal proof systems and programming systems. In short, the correspondence states that:
In this way, constructing a proof for a logical formula can be seen as constructing a program with a corresponding type.
The correspondence was named after Haskell Curry and William Howard, who worked separately to establish the relationship between propositional logic and programming systems.
The idea gained notoriety when it was applied to intuitionistic logic, especially with the type system in the context of functional programming.
For example, in the context of functional programming, a program that has type A -> B
can be seen as a proof that, given an input of type A
, it is possible to produce a value of type B
.
In logic, the implication A → B
means that if A
is true, then B
is also true.
In the type system, this corresponds to a program that receives a value of type A
and returns a value of type B
. Such a program can be represented in a functional language such as Haskell:
implication :: (A -> B) -> A -> B
implication f x = f x
Here, the implication
function demonstrates how to transform a value of A
into a value of B
using a given function.
In logic, the conjunction A ∧ B
means that both A
and B
are true.
In the type system, this corresponds to a pair of values, one of type A
and the other of type B
.
In Haskell, we can represent this with tuples:
conjunction :: (A, B)
conjunction = (valueA, valueB)
In logic, the disjunction A ∨ B
means that at least one of the values, A
or B
, is true.
In the type system, this corresponds to a sum type, that is, a value that can be of one type or the other.
In Haskell, we use Either
to represent this:
disjunction :: Either A B
disjunction = Left valueA -- Or Right valueB
The Curry–Howard correspondence is a powerful concept that unifies logic and programming, allowing for a deeper understanding of how we design and verify software. Using concrete examples and modern tools, it is possible to apply these principles to write safer and more reliable code.
With this insight, we can appreciate how modern programming languages are deeply influenced by type theory and mathematical logic.
Sources:
compilers interpreters programming terlang