Simply Typed Lambda Calculus
Simply typed lambda calculus extends lambda calculus by assigning types to each term, ensuring that only valid operations occur. This prevents meaningless expressions and introduces structure to computation. Simply typed lambda calculus is more restrictive than untyped lambda calculus but ensures logical consistency.
Basic Notation and Typing Rules
Each term in lambda calculus is assigned a type, written as:
which means variable
Typing Approaches
There are two main approaches to typing in lambda calculus:
-
Church-style typing (explicit typing) ~ C++
-
Every variable and function must have an explicit type annotation.
-
The type of a term is written directly in the lambda expression.
-
Example:
Here,
is explicitly declared as having type . -
More restrictive, as all terms must be explicitly typed.
-
Easier to analyze and ensures that every function has a known type.
-
-
Curry-style typing (implicit typing) ~ Python
-
Types are not explicitly written in lambda expressions.
-
Instead, types are inferred from the context
(typing environment). -
Example:
This means
has type in the context , but we do not explicitly write the type in the expression. -
More flexible, allowing implicit type inference.
-
Common in functional programming languages like Haskell and OCaml, where types are inferred automatically.
-
Key Differences
| Feature | Church Typing | Curry Typing |
|---|---|---|
| Explicit types | ✅ Required | ❌ Inferred |
| Type annotations | ✏️ Written in terms | 🚀 Inferred from context |
| Flexibility | ❌ More strict | ✅ More flexible |
| Common in | Formal systems, logic | Functional programming |
🚀 Church typing is stricter and ensures correctness, while Curry typing allows greater flexibility through type inference!