Algorithm W 2026-10-14
Algorithm W performs type inference by traversing the program's abstract syntax tree, introducing fresh type variables, combining type substitutions obtained by type unification, and generalizing eligible let bindings. It distinguishes fresh instances of a type scheme from the shared monomorphic types of parameters to a lambda abstraction.
Eta conversion 2026-10-14
Eta conversion expresses extensionality for a lambda abstraction whose fresh argument is only passed to a function. The side condition prevents removal of a genuine dependency. In a categorical model with , the inverse laws for currying and evaluation validate this conversion as well as beta reduction.
Function type 2026-10-13
A function type classifies functions that accept arguments of type and produce results of type if they return. For example, has function type in our teaching programming language, while has function type . A function type specifies how a function may be used; it does not guarantee that a call returns.
Figure 1.
Checking an integer function call from its parts
. An addition rule checks the body of a lambda abstraction, the abstraction rule gives its function type, and lambda application checks the argument and obtains the result type. Arrows run from prerequisite typing judgments to their conclusions. Details.
The two central typing judgment rules are
The lambda abstraction rule checks the body under an extended typing context; the lambda application rule checks that the argument has exactly the required type. These rules describe our simple type examples. [ref]
For , assume ; both and have type int, so has type int. The abstraction therefore has function type . Since has type int, the call has type int and evaluates to . Replacing by true fails the argument requirement. This local derivation explains each step without running the program.
Arrows associate to the right: means , a function returning another function. For instance, has function type . Supplying one integer yields a function awaiting the second. Functions can also be arguments: accepts an integer-to-integer function and has an integer result type.
// Target: computer-science.bigb
Let ordered by subset. Encode a finite subset and output by a natural number . Define and . Every Scott continuous map satisfies , proving that application is the projection of a retraction. Lambda abstraction has graph .
Identity weakening rule Created 2026-10-06 Updated 2026-10-25
The rule with premises and conclusion retains the first derivation while allowing an unused second assumption. Under the Curry-Howard correspondence, the output term is the first premise term, with the enlarged context. This allows a lambda abstraction whose bound variable does not occur in its body.
The implication introduction rule discharges a temporary assumption from a derivation of , producing . Under the Curry-Howard correspondence, a body under gives the lambda abstraction . Unused assumptions may also be discharged.
Lambda application 2026-10-14
Application applies the lambda term to the lambda term . It associates to the left: . Together with variables and lambda abstraction, it generates all lambda terms.
Lambda model Created 2026-10-14 Updated 2026-10-20
A lambda model interprets variables, lambda application and lambda abstraction so that capture-avoiding substitution agrees with environments and all beta equivalence equations hold. A reflexive domain gives such an interpretation. Validity of eta conversion requires an extra inverse law and does not follow merely from a retraction.
Let polymorphism 2026-10-14
Let polymorphism gives an eligible let-bound name a type scheme, allowing fresh instantiation at each use. In the pure Hindley-Milner type system, generalize the inferred type's type variables that are free in that type and not free in the current typing context. The identity function example under type variable meets this condition. A lambda abstraction's parameter receives one monomorphic type shared by its uses. Languages with mutation, such as Standard ML with ML reference types, need additional restrictions on generalization.
Parallel beta reduction 2026-10-14
Parallel beta reduction permits simultaneous reduction in the body of a lambda abstraction and both sides of an application, together with when and . Variables reduce to themselves. Its capture-avoiding substitution lemma is . Its transitive closure equals ordinary finite beta reduction, while its one-step diamond property yields the Church-Rosser theorem.
A fixed-point combinator is a closed lambda term such that for every lambda term . It suffices to check this for a fresh free variable , since capture-avoiding substitution then gives every instance. Take
If , applying both sides to gives . Conversely suppose is a fixed-point combinator. Its application to a fresh has a head normal form, because it is beta equivalent to . Since is closed, head reduction of must first expose a lambda abstraction in itself. Thus , and
This establishes the needed abstraction equality by beta reduction, without assuming eta conversion. Abstracting now gives .
Two examples are the Curry fixed-point combinator and the Turing fixed-point combinator:
Writing , we have , while . Different displayed syntax alone would not prove that the two combinators are distinct under beta equivalence. Here is a reduct invariant that does. Every finite reduct of is , up to alpha equivalence: is beta-normal and the one remaining beta-redex is its self-application. No such reduct contains the closed subterm .
Every finite reduct of , in contrast, retains a closed subterm . The contraction recreates one. The only other redexes created by these expansions are abstractions applied to variables; contracting them substitutes a variable, so preserves any closed inside their bodies. This describes all redexes inductively: expansion inserts only a variable-headed application and a copy of , and a variable substitution preserves that description. Thus every finite reduct contains . A common reduct of and is impossible, so the Church-Rosser theorem proves .
Finally put , with . The fixed-point combinator equation gives
where is fresh. If had a head normal form with leading abstractions, then would have one with . A reduct of a head normal form preserves its initial abstraction count and variable-headed spine: only its argument subterms can still contract. These two head normal forms therefore cannot have a common reduct, contradicting the Church-Rosser theorem. Hence is unsolvable.
A lambda term is built recursively as a variable , an application , or a lambda abstraction . Application associates to the left and abstraction binds occurrences of its variable. We identify consistent renamings of bound variables by alpha equivalence. A beta reduction contracts to the capture-avoiding substitution , at any subterm. Write for finitely many such steps, including none. Beta equivalence is the reflexive, symmetric, transitive closure of reduction, so it is represented by a finite zigzag of forward and backward steps.
To prove the Church-Rosser theorem, introduce parallel beta reduction by the four rules
By structural induction every term parallel-reduces to itself. Each ordinary step is a parallel step. Conversely, each parallel step can be performed by an ordinary finite sequence: reduce the displayed subterms recursively, and in the fourth rule contract the root last. Hence and are the same relation.
The substitution lemma is
Prove it by induction on the parallel-reduction derivation for . The variable case separates from other variables; application and abstraction follow from their inductive hypotheses. For abstraction, rename its binder fresh for before substituting. For a contracted redex, choose its binder distinct from and fresh for . The substitution identity follows by structural induction with fresh binders; the variable cases use , and application and abstraction preserve the identity. Apply the hypotheses to the body and argument, then the parallel contraction rule and this identity. This proves the lemma for every derivation, including simultaneous contractions inside a redex.
Define the complete development of a lambda term by
Only a root redex already present in the source application is contracted by this clause; a newly created root redex need not be contracted.
We claim that implies . Induct on the derivation. The variable and abstraction cases are immediate. In the ordinary application rule, use the inductive developments of both components. If its original function is an abstraction, also contract the resulting root redex by the parallel contraction rule; otherwise just use the application rule, even if the reduct has acquired a new root redex. In the contraction rule, the reduct has form , and the substitution lemma with , gives . This establishes the claim.
Consequently, any two parallel reducts of each parallel-reduce to . Thus parallel reduction has the one-step diamond property. Its finite transitive closure is confluent: fill a finite grid of elementary diamonds to join two finite reduction paths from the same term. Since its closure equals ordinary finite beta reduction,
A finite conversion zigzag now also has a common reduct, by induction along it. If the next zigzag step points forward from a term already having a common reduct, join its two outgoing paths by confluence; if it points backward, compose the new forward path to that common reduct. The reverse implication is immediate because two paths to a common reduct form a conversion zigzag. This proves
A beta-normal form contains no beta-redex, so its only finite reduct is itself. If two normal forms are beta-equivalent, their common reduct must equal both. Hence a term has at most one beta-normal form up to alpha equivalence. The qualification about bound-variable names is essential.
For an example without normal form, take the Omega combinator
Its only redex is the root, and contracting it reproduces . Every finite reduct is therefore , which is not a beta-normal form. By the theorem it cannot even be beta-equivalent to any normal form.
Choose mutually inverse maps and . This is an extensional reflexive object in the Cartesian closed category. Define its application morphism
For endomorphisms , application in the underlying set is .
It is useful to define term interpretation uniformly over any context object . An environment assigns each free variable a morphism . Variables are interpreted by their assigned maps, and application is interpreted by and pairing. For lambda abstraction, lift the old environment along , interpret the new variable by , and let interpret the body. Then set
Taking gives interpretations in the requested set of endomorphisms. Other context objects are needed in the recursive definition to handle bound variables correctly.
The beta reduction rule follows from and the evaluation identity for currying. Applying the interpreted abstraction to a map gives
Induction on terms identifies this with interpretation of the capture-avoiding substitution of the argument for .
For eta conversion, suppose is not free in and write for the interpretation of . The body on is the uncurried form of . Hence
Thus beta-eta-equivalent terms have equal interpretations in . The full isomorphism, rather than just a retract of the function object, provides the inverse law used in the eta step.
Write and . The displayed formula is . A proof of logical implication may use its temporary assumption more than once; this is ordinary natural deduction, not a linear proof system.
Assume , then , then , then . The identity weakening rule derives from the hypotheses and . Discharging by the implication introduction rule gives . Applying by the implication elimination rule gives . Discharge to obtain . Applying gives an ; discharge to obtain a ; apply once more to obtain , and finally discharge .
Here is the complete decorated natural deduction derivation, split at its intermediate conclusion to keep the tree readable. Superscript labels mark which assumption occurrences are discharged; both occurrences labelled are discharged together.
To avoid an excessively wide final tree, continue the same derivation as follows, using the right-hand derived premise above:
followed by
Thus the concise lambda term, with bound-variable types determined by the displayed tree, is
Under the Curry-Howard correspondence, implication introduction rules correspond to lambda abstractions, implication elimination rules to applications, and the identity weakening rule retains the first term while allowing an unused second hypothesis. No other inference rule or classical axiom is required.
Reflexive domain 2026-10-14
A pointed complete partial order is reflexive when there are Scott continuous maps and with . Define and interpret lambda abstraction using . The inverse law gives beta soundness; additionally gives eta soundness.
Solvable lambda term 2026-10-14
A lambda term is solvable if its closure by lambda abstractions over its free variables can be applied to finitely many closed lambda terms to obtain in beta equivalence. This is equivalent to having a head normal form. A head variable in a head normal form can be replaced by a projection returning ; conversely standardization theorem for beta reduction traces any successful head computation back to a head variable of the original term.
A finite beta reduction can be rearranged into standard order, contracting earlier residual redexes before later ones. In particular, a lambda term with a head normal form reaches one by head reduction, and a term with a beta-normal form reaches it by normal-order beta reduction. Head reduction contracts the outermost redex on the left application spine, including under initial lambda abstractions.
Type variable 2026-10-13
A type variable is a placeholder for a type. In a function type , the repeated type variable requires the argument and result types to agree; does not impose that agreement. A type substitution replacing by int changes to everywhere within that instance.
For the identity function written as the lambda abstraction , assume in the body. Looking up gives result type , so the abstraction rule gives . In the pure Hindley-Milner type system, let identity = λx.x in ... gives identity the type scheme by let polymorphism. Each use receives fresh type variables: identity 3 chooses int for its instance, and identity true chooses bool for a separate instance. These choices do not change the original type scheme.
Figure 1.
Independent type instantiations of a let-bound identity function
. The type scheme stays general while two uses receive different type substitutions. Each use preserves the equality of its own argument and result types. Details.
For example, let identity = λx.x in let a = identity 3 in identity true is valid and has type bool. By contrast, (λf. let a = f 3 in f true) (λx.x) is rejected by the Hindley-Milner type system: the lambda abstraction binds f to one monomorphic function type. The first call requires its argument type to be int, and the second requires that same type to be bool. Naming the first result with let a does not generalize f. The distinction makes reusable code possible while keeping the assumptions about a supplied argument consistent.
// Target: computer-science.bigb
Typing context 2026-10-14
A typing context records the types assumed for available program names. In , looking up either name yields int. Checking a lambda abstraction extends the typing context with its argument's type for the body. In the Hindley-Milner type system, a typing context can also hold type schemes for names introduced by let polymorphism.