Let expression
In computer science, a "let" expression associates a function definition with a restricted scope. The "let" expression may also be defined in mathematics, where it associates a Boolean condition with a restricted scope. The "let" expression may be considered as a lambda abstraction applied to a value. Within mathematics, a let expression may also be considered as a conjunction of expressions, within an existential quantifier which restricts the scope of the variable. The let expression is present in many functional languages to allow the local definition of expression, for use in defining another expression. The let-expression is present in some functional languages in two forms; let or "let rec". Let rec is an extension of the simple let expression which uses the fixed-point combinator to implement recursion.
In computer science, a "let" expression associates a function definition with a restricted scope. The "let" expression may also be defined in mathematics, where it associates a Boolean condition with a restricted scope. The "let" expression may be considered as a lambda abstraction applied to a value. Within mathematics, a let expression may also be considered as a conjunction of expressions, within an existential quantifier which restricts the scope of the variable. The let expression is present in many functional languages to allow the local definition of expression, for use in defining another expression. The let-expression is present in some functional languages in two forms; let or "let rec". Let rec is an extension of the simple let expression which uses the fixed-point combinator to implement recursion. is equivalent to defining the function f by f\ x = y in the expression z , which may be written as the let expression; \operatorname{let} f\ x = y \operatorname{in} z The let expression is understandable as a natural language expression. The let expression represents the substitution of a variable for a value. The substitution rule describes the implications of equality as substitution. x \not \in \operatorname{FV}(E) \land x \in \operatorname{FV}(F) \implies \operatorname{let} x : G \operatorname{in} E\ F = E\ (\operatorname{let} x : G \operatorname{in} F)\\ x \in \operatorname{FV}(E) \land x \not \in \operatorname{FV}(F) \implies \operatorname{let} x : G \operatorname{in} E\ F = (\operatorname{let} x : G \operatorname{in} E)\ F\\ x \not \in \operatorname{FV}(E) \land x \not \in \operatorname{FV}(F) \implies \operatorname{let} x : G \operatorname{in} E\ F = E\ F \end{cases} where F is not of type Boolean. From this definition the following standard definition of a let expression, as used in a functional language may be derived. x \not \in \operatorname{FV}(y) \implies (\operatorname{let} x : x = y \operatorname{in} z) = z[x := y] = (\lambda x.z)\ y For simplicity the marker specifying the existential variable, x : , will be omitted from the expression where it is clear from the context. x \not \in \operatorname{FV}(y) \implies (\operatorname{let} x = y \operatorname{in} z) = z[x := y] = (\lambda x.z)\ y L\ (\operatorname{let} x : x = y \operatorname{in} z) & \iff (\operatorname{let} x : x = y \operatorname{in} L\ z) \\ & \iff x = y \land L\ z \end{align} Using the rule of substitution, \begin{align} & \iff x = y \land(L\ z)[x :=y]\\ & \iff x = y \land(L[x :=y]\ z[x :=y])\\ & \iff x = y \land L\ z[x :=y]\\ & \implies L\ z[x :=y] \end{align} so for all L, L \operatorname{let} x : x = y \operatorname{in} z \implies L\ z[x :=y] Let L\ X = (X = K) where K is a new variable. then, (\operatorname{let} x : x = y \operatorname{in} z) = K \implies z[x :=y] = K So, \operatorname{let} x : x = y \operatorname{in} z = z[x :=y] But from the mathematical interpretation of a beta reduction, (\lambda x.z)\ y = z[x :=y] Here if y is a function of a variable x, it is not the same x as in z. Alpha renaming may be applied. So we must have, x \not \in \operatorname{FV}(y) so, x \not \in \operatorname{FV}(y) \implies \operatorname{let} x : x = y \operatorname{in} z = (\lambda x.z)\ y This result is represented in a functional language in an abbreviated form, where the meaning is unambiguous; x \not \in \operatorname{FV}(y) \implies (\operatorname{let} x = y \operatorname{in} z) = z[x := y] = (\lambda x.z)\ y Here the variable x is implicitly recognised as both part of the equation defining x, and the variable in the existential quantifier. A contradiction arises if E is defined by E = \neg . In this case, x \not \in \operatorname{FV}(E) \land x \in \operatorname{FV}(F) \implies \operatorname{let} x : G \operatorname{in} E\ F = E\ (\operatorname{let} x : G \operatorname{in} F) becomes, \operatorname{let} x : G \operatorname{in} \neg F = \neg\ (\operatorname{let} x : G \operatorname{in} F) and using, (\exists x E \land F) \iff \operatorname{let} x : E \operatorname{in} F (\exists x G \land \neg F) = \neg\ (\exists x G \land F) = (\exists x \neg G \lor \neg F) This is false if G is false. To avoid this contradiction F is not allowed to be of type Boolean. For Boolean F the correct statement of the dropping rule uses implication instead of equality, x \not \in \operatorname{FV}(E) \land x \in \operatorname{FV}(F) \implies (\operatorname{let} x : G \operatorname{in} E\ F \to E\ (\operatorname{let} x : G \operatorname{in} F)) It may appear strange that a different rule applies for Boolean than other types. The reason for this is that the rule, (\exists x E \land F) \iff \operatorname{let} x : E \operatorname{in} F only applies where F is Boolean. The combination of the two rules creates a contradiction, so where one rule holds, the other does not. (\operatorname{let}_s x = y \operatorname{in} z) \equiv (\lambda x.z)\ y The simple let expression definition was then extended to allow recursion using the fixed-point combinator. \lambda f.\operatorname{let} x = f\ x \operatorname{in} x This representation may be converted into a lambda term. A lambda abstraction does not support reference to the variable name, in the applied expression, so x must be passed in as a parameter to x. \lambda f.\operatorname{let} x\ x = f\ (x\ x) \operatorname{in} x\ x Using the eta reduction rule, f\ x = y \equiv f = \lambda x.y gives, \lambda f.\operatorname{let} x = \lambda x.f\ (x\ x) \operatorname{in} x\ x A let expression may be expressed as a lambda abstraction using, n \not \in FV(E) \to (\operatorname{let} n = E \operatorname{in} L \equiv (\lambda n.L)\ E) gives, \lambda f.(\lambda x.x\ x)\ (\lambda x.f\ (x\ x)) This is possibly the simplest implementation of a fixed point combinator in lambda calculus. However one beta reduction gives the more symmetrical form of Curry's Y combinator. \lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x)) (\operatorname{let\ rec} x = y \operatorname{in} z) \equiv (\lambda x.z)\ (Y\ (\lambda x.y)) & = \operatorname{let} x \in X \land y \in Y \operatorname{in} x\ y \\ & = \operatorname{let} (x, y) \in X \times Y \operatorname{in} x\ y \end{align} But a different rule applies for applying the let expression to itself. \begin{align} & (\operatorname{let} x \in X \operatorname{in} x)\ (\operatorname{let} x \in X \operatorname{in} x) \\ & = \operatorname{let} x \in X \operatorname{in} x\ x \end{align} There appear no simple rule for combining values. What is required is a general form of expression that represents a variable whose value is a member of a set of values. The expression should be based on the variable and the set. Function application applied to this form should give another expression in the same form. In this way any expression on functions of multiple values may be treated as if it had one value. It is not sufficient for the form to represent only the set of values. Each value must have a condition that determines when the expression takes the value. The resulting construct is a set of pairs of conditions and values, called a "value set". See narrowing of algebraic value sets. The substitution operator is also used. The expression L[G := S] means substitute every occurrence of G in L by S and return the expression. The definition used is extended to cover the substitution of expressions, from the definition given on the Lambda calculus page. The matching of expressions should compare expressions for alpha equivalence (renaming of variables). \operatorname{de-lambda}[F = \lambda P.E] \equiv \operatorname{de-lambda}[F\ P = E] \operatorname{de-lambda}[E = F] \equiv \operatorname{de-lambda}[E] = \operatorname{de-lambda}[F] \operatorname{de-lambda}[(\lambda F.E) L] \equiv \operatorname{let-combine}[\operatorname{let} F : \operatorname{de-lambda}[F = L] \operatorname{in} E] V \not \in \operatorname{FV}[\lambda F.E] \to \operatorname{de-lambda}[\lambda F.E] \equiv \operatorname{let-combine}[\operatorname{let} V : \operatorname{de-lambda}[V\ F = E] \operatorname{in} V] V \ne W \to \operatorname{let-combine}[\operatorname{let} V : E \operatorname{in} \operatorname{let} W : F \operatorname{in} G] \equiv \operatorname{let} V, W : E \land F \operatorname{in} G \operatorname{let-combine}[\operatorname{let} V : E \operatorname{in} F] \equiv \operatorname{let} V : E \operatorname{in} F Rule 6 creates a unique variable V, as a name for the function. \operatorname{let} p : p\ f = \operatorname{let} x : x\ q = f\ (q\ q) \operatorname{in} f\ (x\ x) \operatorname{in} p |- | 4 || |- | 5 || |- | 3 || |- | 8 || |- | 8 || |- | 4 || |- | 2 || |- | 1 || |- | || \operatorname{let} p : p\ f = \operatorname{let} x : x\ x = f\ (x\ x) \operatorname{in} f\ (x\ x)] \operatorname{in} p |} \operatorname{get-lambda}[F, G\ V = E] = \operatorname{get-lambda}[F, G = \lambda V.E] \operatorname{get-lambda}[F, F = E] = \operatorname{de-let}[E] \operatorname{de-let}[\lambda V.E] \equiv \lambda V.\operatorname{de-let}[E] \operatorname{de-let}[M\ N] \equiv \operatorname{de-let}[M]\ \operatorname{de-let}[N] \operatorname{de-let}[V] \equiv V V \not \in FV[\operatorname{get-lambda}[V, E \to \operatorname{de-let}[\operatorname{let} V : E \ \operatorname{in} V] \equiv \operatorname{get-lambda}[V, E] V \not \in FV[\operatorname{get-lambda}[V, E \to \operatorname{de-let}[\operatorname{let} V : E \ \operatorname{in} L] \equiv (\lambda V.\operatorname{de-let}[L])\ \operatorname{get-lambda}[V, E] W \not \in \operatorname{FV}[\operatorname{get-lambda}[V, E \to \operatorname{de-let}[\operatorname{let} V, W : E \land F \ \operatorname{in} G] \equiv \operatorname{de-let}[\operatorname{let} V : E \ \operatorname{in} \operatorname{let} W : F \ \operatorname{in} G] V \in \operatorname{FV}[\operatorname{get-lambda}[V, E \to \operatorname{de-let}[\operatorname{let} V : E \ \operatorname{in} L] \equiv \operatorname{de-let}[\operatorname{let} V : V\ V = \operatorname{get-lambda}[V, E][V:=V\ V] \ \operatorname{in} L[V:=V\ V W \in \operatorname{FV}[\operatorname{get-lambda}[V, E \to \operatorname{de-let}[\operatorname{let} V, W : E \land F \ \operatorname{in} L] \equiv \operatorname{de-let}[\operatorname{let} V: V\ W = \operatorname{get-lambda}[V, E][V:=V\ W] \ \operatorname{in} \operatorname{let} W: F[V:=V\ W] \ \operatorname{in} L[V:=V\ W There is no exact structural equivalent in lambda calculus for let expressions that have free variables that are used recursively. In this case some addition of parameters is required. Rules 8 and 10 add these parameters. Rules 8 and 10 are sufficient for two mutually recursive equations in the let expression. However they will not work for three or more mutually recursive equations. The general case needs an extra level of looping which makes the meta function a little more difficult. The rules that follow replace rules 8 and 10 in implementing the general case. Rules 8 and 10 have been left so that the simpler case may be studied first. lambda-form - Convert the expression into a conjunction of expressions, each of the form variable = expression. \operatorname{lambda-form}[G\ V = E] = \operatorname{lambda-form}[G = \lambda V.E] \operatorname{lambda-form}[E \land F] = \operatorname{lambda-form}[E] \land \operatorname{lambda-form}[F] \operatorname{lambda-form}[V = E] = V = E ...... where V is a variable. lift-vars - Get the set of variables that need X as a parameter, because the expression has X as a free variable. X \in \operatorname{FV}[E] \to \operatorname{lift-vars}[X, V = E] = \{V\} X \not \in \operatorname{FV}[E] \to \operatorname{lift-vars}[X, V = E] = \{\} \operatorname{lift-vars}[X, E \land F] = \operatorname{lift-vars}[X, E] \cup \operatorname{lift-vars}[X. F] sub-vars - For each variable in the set substitute it for the variable applied to X in the expression. This makes X a variable passed in as a parameter, instead of being a free variable in the right hand side of the equation. \operatorname{sub-vars}[E, \{V\} \cup S, X] = \operatorname{sub-vars}[E[V:=V\ X], S, X] \operatorname{sub-vars}[E, \{\}, X] = E de-let - Lift each condition in E so that X is not a free variable on the right hand side of the equation. \begin{align} L &= \operatorname{lambda-form}[E] \land S = \operatorname{lift-vars}[X, L] \to \operatorname{de-let}[\operatorname{let} V \ldots W, X : E \land F \ \operatorname{in} G] \\ & \equiv \operatorname{de-let}[\operatorname{let} V \ldots W: \operatorname{sub-vars}[L, S, X] \ \operatorname{in} \operatorname{let} \operatorname{sub-vars}[\operatorname{lambda-form}[F], S, X] \ \operatorname{in} \operatorname{sub-vars}[G, S, X \end{align} \operatorname{let} p : p\ f = \operatorname{let} x : x\ q = f\ (q\ q) \ \operatorname{in} f\ (x\ x) \ \operatorname{in} p is converted to, \lambda f.(\lambda x.f\ (x\ x))\ (\lambda q.f\ (q\ q)) |- | 1 || |- | 2 || |- | 3 || |- | 7 || |- | 4 || |- | 4 || |- | 5 || |- | 1 || |- | 2 || |- | 3 || |- | 4 || |- | 5 || |- | || (\lambda x.f\ (x\ x))\ (\lambda q.f\ (q\ q)) |} For a second example take the lifted version of the Y combinator, \operatorname{let}p, q : p\ f\ x = f\ (x\ x) \land q\ p\ f = (p\ f)\ (p\ f) \ \operatorname{in} q\ p is converted to, (\lambda p.(\lambda q.q\ p)\ \lambda p.\lambda f.(p\ f)\ (p\ f))\ \lambda f.\lambda x.f\ (x\ x) For a third example the translation of, \operatorname{let} x: x\ f = f\ (x\ f) \ \operatorname{in} x is, (\lambda x.x\ x)\ (\lambda x.\lambda f.f\ (x\ x\ f)) For a forth example the translation of, \operatorname{let} x: x = f\ x \ \operatorname{in} x is, (\lambda x.x\ x)\ (\lambda x. f\ (x\ x)) which is the famous y combinator. ===Works cited===
References
No reference rows published for this article.
Cite this article
MLA
"Let expression." encyclopegia.org, 2026, https://encyclopegia.org/wiki/let-expression. Accessed 24 November 2026.
Chicago
"Let expression." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/let-expression.
APA
encyclopegia.org. (2026). Let expression. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/let-expression
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON