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 .
History [ edit ]
Dana Scott 's LCF language [1] was a stage in the evolution of lambda calculus into modern functional languages. This language introduced the let expression, which has appeared in most functional languages since that time.
The languages Scheme ,[2] ML , and more recently Haskell [3] have inherited let expressions from LCF.
Stateful imperative languages such as ALGOL and Pascal essentially implement a let expression, to implement restricted scope of functions, in block structures.[citation needed ]
A closely related "where " clause, together with its recursive variant "where rec ", appeared already in Peter Landin 's The mechanical evaluation of expressions .[4]
Description [ edit ]
A "let" expression defines a function or value for use in another expression. As well as being a construct used in many functional programming languages, it is a natural language construct often used in mathematical texts. It is an alternate syntactical construct for a where clause.
Let expression
Where clause
Let
a
=
3
{\displaystyle a=3}
and
b
=
4
{\displaystyle b=4}
in
a
2
+
b
2
{\displaystyle {\sqrt {a^{2}+b^{2}}}}
a
2
+
b
2
{\displaystyle {\sqrt {a^{2}+b^{2}}}}
where
a
=
3
{\displaystyle a=3}
and
b
=
4
{\displaystyle b=4}
In both cases the whole construct is an expression whose value is 5. Like the if-then-else the type returned by the expression is not necessarily Boolean.
A let expression comes in 4 main forms,
Form
And
Recursive
Definition / Constraint
Description
Simple
No
No
Definition
Simple non recursive function definition.
Recursive
No
Yes
Definition
Recursive function definition (implemented using the Y combinator ).
Mutual
Yes
Yes
Definition
Mutually recursive function definition.
Mathematical
Yes
Yes
Constraint
Mathematical definition supporting a general Boolean let condition.
In functional languages the let expression defines functions which may be called in the expression. The scope of the function name is limited to the let expression structure.
In mathematics, the let expression defines a condition, which is a constraint on the expression. The syntax may also support the declaration of existentially quantified variables local to the let expression.
The terminology, syntax and semantics vary from language to language. In Scheme , let is used for the simple form and let rec for the recursive form. In ML let marks only the start of a block of declarations with fun marking the start of the function definition. In Haskell, let may be mutually recursive, with the compiler figuring out what is needed.
Definition [ edit ]
A lambda abstraction represents a function without a name. This is a source of the inconsistency in the definition of a lambda abstraction. However lambda abstractions may be composed to represent a function with a name. In this form the inconsistency is removed. The lambda term,
(
λ
f
.
z
)
(
λ
x
.
y
)
{\displaystyle (\lambda f.z)\ (\lambda x.y)}
is equivalent to defining the function
f
{\displaystyle f}
by
f
x
=
y
{\displaystyle f\ x=y}
in the expression
z
{\displaystyle z}
, which may be written as the let expression;
let
f
x
=
y
in
z
{\displaystyle \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.
Let definition in mathematics [ edit ]
In mathematics the let expression is described as the conjunction of expressions. In functional languages the let expression is also used to limit scope. In mathematics scope is described by quantifiers. The let expression is a conjunction within an existential quantifier.
(
∃
x
E
∧
F
)
⟺
let
x
:
E
in
F
{\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}
where E and F are of type Boolean.
The let expression allows the substitution to be applied to another expression. This substitution may be applied within a restricted scope, to a sub expression. The natural use of the let expression is in application to a restricted scope (called lambda dropping ). These rules define how the scope may be restricted;
{
x
∉
FV
(
E
)
∧
x
∈
FV
(
F
)
⟹
let
x
:
G
in
E
F
=
E
(
let
x
:
G
in
F
)
x
∈
FV
(
E
)
∧
x
∉
FV
(
F
)
⟹
let
x
:
G
in
E
F
=
(
let
x
:
G
in
E
)
F
x
∉
FV
(
E
)
∧
x
∉
FV
(
F
)
⟹
let
x
:
G
in
E
F
=
E
F
{\displaystyle {\begin{cases}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
∉
FV
(
y
)
⟹
(
let
x
:
x
=
y
in
z
)
=
z
[
x
:=
y
]
=
(
λ
x
.
z
)
y
{\displaystyle 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
:
{\displaystyle x:}
, will be omitted from the expression where it is clear from the context.
x
∉
FV
(
y
)
⟹
(
let
x
=
y
in
z
)
=
z
[
x
:=
y
]
=
(
λ
x
.
z
)
y
{\displaystyle x\not \in \operatorname {FV} (y)\implies (\operatorname {let} x=y\operatorname {in} z)=z[x:=y]=(\lambda x.z)\ y}
Derivation [ edit ]
To derive this result, first assume,
x
∉
FV
(
L
)
{\displaystyle x\not \in \operatorname {FV} (L)}
then
L
(
let
x
:
x
=
y
in
z
)
⟺
(
let
x
:
x
=
y
in
L
z
)
⟺
x
=
y
∧
L
z
{\displaystyle {\begin{aligned}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{aligned}}}
Using the rule of substitution,
⟺
x
=
y
∧
(
L
z
)
[
x
:=
y
]
⟺
x
=
y
∧
(
L
[
x
:=
y
]
z
[
x
:=
y
]
)
⟺
x
=
y
∧
L
z
[
x
:=
y
]
⟹
L
z
[
x
:=
y
]
{\displaystyle {\begin{aligned}&\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{aligned}}}
so for all L ,
L
let
x
:
x
=
y
in
z
⟹
L
z
[
x
:=
y
]
{\displaystyle L\operatorname {let} x:x=y\operatorname {in} z\implies L\ z[x:=y]}
Let
L
X
=
(
X
=
K
)
{\displaystyle L\ X=(X=K)}
where K is a new variable. then,
(
let
x
:
x
=
y
in
z
)
=
K
⟹
z
[
x
:=
y
]
=
K
{\displaystyle (\operatorname {let} x:x=y\operatorname {in} z)=K\implies z[x:=y]=K}
So,
let
x
:
x
=
y
in
z
=
z
[
x
:=
y
]
{\displaystyle \operatorname {let} x:x=y\operatorname {in} z=z[x:=y]}
But from the mathematical interpretation of a beta reduction,
(
λ
x
.
z
)
y
=
z
[
x
:=
y
]
{\displaystyle (\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
∉
FV
(
y
)
{\displaystyle x\not \in \operatorname {FV} (y)}
so,
x
∉
FV
(
y
)
⟹
let
x
:
x
=
y
in
z
=
(
λ
x
.
z
)
y
{\displaystyle 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
∉
FV
(
y
)
⟹
(
let
x
=
y
in
z
)
=
z
[
x
:=
y
]
=
(
λ
x
.
z
)
y
{\displaystyle 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.
No lifting from Boolean [ edit ]
A contradiction arises if E is defined by
E
=
¬
{\displaystyle E=\neg }
. In this case,
x
∉
FV
(
E
)
∧
x
∈
FV
(
F
)
⟹
let
x
:
G
in
E
F
=
E
(
let
x
:
G
in
F
)
{\displaystyle 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,
let
x
:
G
in
¬
F
=
¬
(
let
x
:
G
in
F
)
{\displaystyle \operatorname {let} x:G\operatorname {in} \neg F=\neg \ (\operatorname {let} x:G\operatorname {in} F)}
and using,
(
∃
x
E
∧
F
)
⟺
let
x
:
E
in
F
{\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}
(
∃
x
G
∧
¬
F
)
=
¬
(
∃
x
G
∧
F
)
{\displaystyle (\exists xG\land \neg F)=\neg \ (\exists xG\land F)}
=
(
∃
x
¬
G
∨
¬
F
)
{\displaystyle =(\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
∉
FV
(
E
)
∧
x
∈
FV
(
F
)
⟹
(
let
x
:
G
in
E
F
→
E
(
let
x
:
G
in
F
)
)
{\displaystyle 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,
(
∃
x
E
∧
F
)
⟺
let
x
:
E
in
F
{\displaystyle (\exists xE\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.
Joining let expressions [ edit ]
Let expressions may be defined with multiple variables,
(
∃
v
⋯
∃
w
∃
x
E
∧
F
)
⟺
let
v
,
…
,
w
,
x
:
E
in
F
{\displaystyle (\exists v\cdots \exists w\exists xE\land F)\iff \operatorname {let} v,\ldots ,w,x:E\operatorname {in} F}
then it can be derived,
x
∉
F
V
(
E
)
⟹
(
∃
v
⋯
∃
w
∃
x
E
∧
F
)
⟺
(
∃
v
⋯
∃
w
(
E
∧
∃
x
F
)
)
{\displaystyle x\not \in FV(E)\implies (\exists v\cdots \exists w\exists xE\land F)\iff (\exists v\cdots \exists w(E\land \exists xF))}
so,
x
∉
F
V
(
E
)
⟹
(
let
v
,
…
,
w
,
x
:
E
∧
F
in
L
≡
let
v
,
…
,
w
:
E
in
let
x
:
F
in
L
)
{\displaystyle x\not \in FV(E)\implies (\operatorname {let} v,\ldots ,w,x:E\land F\operatorname {in} L\equiv \operatorname {let} v,\ldots ,w:E\operatorname {in} \operatorname {let} x:F\operatorname {in} L)}
Laws relating lambda calculus and let expressions [ edit ]
The Eta reduction gives a rule for describing lambda abstractions. This rule along with the two laws derived above define the relationship between lambda calculus and let expressions.
Name
Law
Eta-reduction equivalence
f
x
=
y
≡
f
=
λ
x
.
y
{\displaystyle f\ x=y\equiv f=\lambda x.y}
Let-lambda equivalence
f
∉
F
V
(
E
)
⟹
(
let
f
:
f
=
E
in
L
≡
(
λ
f
.
L
)
E
)
{\displaystyle f\notin FV(E)\implies (\operatorname {let} f:f=E\operatorname {in} L\equiv (\lambda f.L)\ E)}
(where
f
{\displaystyle f}
is a variable name.)
Let combination
x
∉
F
V
(
E
)
⟹
(
let
v
,
…
,
w
,
x
:
E
∧
F
in
L
≡
let
v
,
…
,
w
:
E
in
let
x
:
F
in
L
)
{\displaystyle x\notin FV(E)\implies (\operatorname {let} v,\dots ,w,x:E\land F\operatorname {in} L\equiv \operatorname {let} v,\dots ,w:E\operatorname {in} \operatorname {let} x:F\operatorname {in} L)}
Let definition defined from lambda calculus [ edit ]
To avoid the potential problems associated with the mathematical definition , Dana Scott originally defined the let expression from lambda calculus. This may be considered as the bottom up, or constructive, definition of the let expression, in contrast to the top down, or axiomatic mathematical definition.
The simple, non recursive let expression was defined as being syntactic sugar for the lambda abstraction applied to a term. In that definition,
(
let
s
x
=
y
in
z
)
≡
(
λ
x
.
z
)
y
{\displaystyle (\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 .
Fixed-point combinator [ edit ]
The fixed-point combinator may be represented by the expression,
λ
f
.
let
x
=
f
x
in
x
{\displaystyle \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 .
λ
f
.
let
x
x
=
f
(
x
x
)
in
x
x
{\displaystyle \lambda f.\operatorname {let} x\ x=f\ (x\ x)\operatorname {in} x\ x}
Using the eta reduction rule,
f
x
=
y
≡
f
=
λ
x
.
y
{\displaystyle f\ x=y\equiv f=\lambda x.y}
gives,
λ
f
.
let
x
=
λ
x
.
f
(
x
x
)
in
x
x
{\displaystyle \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
∉
F
V
(
E
)
→
(
let
n
=
E
in
L
≡
(
λ
n
.
L
)
E
)
{\displaystyle n\not \in FV(E)\to (\operatorname {let} n=E\operatorname {in} L\equiv (\lambda n.L)\ E)}
gives,
λ
f
.
(
λ
x
.
x
x
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle \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.
λ
f
.
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle \lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))}
Recursive let expression [ edit ]
The recursive let expression called "let rec" is defined using the Y combinator for recursive let expressions.
(
l
e
t
r
e
c
x
=
y
in
z
)
≡
(
λ
x
.
z
)
(
Y
(
λ
x
.
y
)
)
{\displaystyle (\operatorname {let\ rec} x=y\operatorname {in} z)\equiv (\lambda x.z)\ (Y\ (\lambda x.y))}
Mutually recursive let expression [ edit ]
This approach is then generalized to support mutual recursion. A mutually recursive let expression may be composed by rearranging the expression to remove any and conditions. This is achieved by replacing multiple function definitions with a single function definition, which sets a list of variables equal to a list of expressions. A version of the Y combinator, called the Y* poly-variadic fix-point combinator
[5] is then used to calculate fixed point of all the functions at the same time. The result is a mutually recursive implementation of the let expression.
Multiple values [ edit ]
A let expression may be used to represent a value that is a member of a set,
let
x
∈
X
in
x
{\displaystyle \operatorname {let} x\in X\operatorname {in} x}
Under function application, of one let expression to another,
(
let
x
∈
X
in
x
)
(
let
y
∈
Y
in
y
)
=
let
x
∈
X
∧
y
∈
Y
in
x
y
=
let
(
x
,
y
)
∈
X
×
Y
in
x
y
{\displaystyle {\begin{aligned}&(\operatorname {let} x\in X\operatorname {in} x)\ (\operatorname {let} y\in Y\operatorname {in} 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{aligned}}}
But a different rule applies for applying the let expression to itself.
(
let
x
∈
X
in
x
)
(
let
x
∈
X
in
x
)
=
let
x
∈
X
in
x
x
{\displaystyle {\begin{aligned}&(\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{aligned}}}
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 .
Rules for conversion between lambda calculus and let expressions [ edit ]
Meta-functions will be given that describe the conversion between lambda and let expressions. A meta-function is a function that takes a program as a parameter. The program is data for the meta-program. The program and the meta program are at different meta-levels.
The following conventions will be used to distinguish program from the meta program,
Square brackets [] will be used to represent function application in the meta program.
Capital letters will be used for variables in the meta program. Lower case letters represent variables in the program.
≡
{\displaystyle \equiv }
will be used for equals in the meta program.
For simplicity the first rule given that matches will be applied. The rules also assume that the lambda expressions have been pre-processed so that each lambda abstraction has a unique name.
The substitution operator is also used. The expression
L
[
G
:=
S
]
{\displaystyle 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).
Conversion from lambda to let expressions [ edit ]
The following rules describe how to convert from a lambda expression to a let expression, without altering the structure.
d
e
-
l
a
m
b
d
a
[
V
]
≡
V
{\displaystyle \operatorname {de-lambda} [V]\equiv V}
d
e
-
l
a
m
b
d
a
[
M
N
]
≡
d
e
-
l
a
m
b
d
a
[
M
]
d
e
-
l
a
m
b
d
a
[
N
]
{\displaystyle \operatorname {de-lambda} [M\ N]\equiv \operatorname {de-lambda} [M]\ \operatorname {de-lambda} [N]}
d
e
-
l
a
m
b
d
a
[
F
=
λ
P
.
E
]
≡
d
e
-
l
a
m
b
d
a
[
F
P
=
E
]
{\displaystyle \operatorname {de-lambda} [F=\lambda P.E]\equiv \operatorname {de-lambda} [F\ P=E]}
d
e
-
l
a
m
b
d
a
[
E
=
F
]
≡
d
e
-
l
a
m
b
d
a
[
E
]
=
d
e
-
l
a
m
b
d
a
[
F
]
{\displaystyle \operatorname {de-lambda} [E=F]\equiv \operatorname {de-lambda} [E]=\operatorname {de-lambda} [F]}
d
e
-
l
a
m
b
d
a
[
(
λ
F
.
E
)
L
]
≡
l
e
t
-
c
o
m
b
i
n
e
[
let
F
:
d
e
-
l
a
m
b
d
a
[
F
=
L
]
in
E
]
{\displaystyle \operatorname {de-lambda} [(\lambda F.E)L]\equiv \operatorname {let-combine} [\operatorname {let} F:\operatorname {de-lambda} [F=L]\operatorname {in} E]}
V
∉
FV
[
λ
F
.
E
]
→
d
e
-
l
a
m
b
d
a
[
λ
F
.
E
]
≡
l
e
t
-
c
o
m
b
i
n
e
[
let
V
:
d
e
-
l
a
m
b
d
a
[
V
F
=
E
]
in
V
]
{\displaystyle 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
≠
W
→
l
e
t
-
c
o
m
b
i
n
e
[
let
V
:
E
in
let
W
:
F
in
G
]
≡
let
V
,
W
:
E
∧
F
in
G
{\displaystyle V\neq 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}
l
e
t
-
c
o
m
b
i
n
e
[
let
V
:
E
in
F
]
≡
let
V
:
E
in
F
{\displaystyle \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.
Example [ edit ]
For example, the Y combinator ,
λ
f
.
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle \lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))}
is converted to,
let
p
:
p
f
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
in
p
{\displaystyle \operatorname {let} p:p\ f=\operatorname {let} x:x\ q=f\ (q\ q)\operatorname {in} f\ (x\ x)\operatorname {in} p}
Rule
show Lambda expression
6
show
d
e
-
l
a
m
b
d
a
[
λ
f
.
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
{\displaystyle \operatorname {de-lambda} [\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]}
V
∉
FV
[
λ
F
.
E
]
→
d
e
-
l
a
m
b
d
a
[
λ
F
.
E
]
{\displaystyle V\not \in \operatorname {FV} [\lambda F.E]\to \operatorname {de-lambda} [\lambda F.E]}
V
=
p
,
F
=
f
,
E
=
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle V=p,F=f,E=(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))}
l
e
t
-
c
o
m
b
i
n
e
[
let
V
:
d
e
-
l
a
m
b
d
a
[
V
F
=
E
]
in
V
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} V:\operatorname {de-lambda} [V\ F=E]\operatorname {in} V]}
4
show
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
=
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f=(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]\operatorname {in} p]}
d
e
-
l
a
m
b
d
a
[
p
f
=
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
{\displaystyle \operatorname {de-lambda} [p\ f=(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]}
d
e
-
l
a
m
b
d
a
[
E
=
F
]
{\displaystyle \operatorname {de-lambda} [E=F]}
E
=
p
f
,
F
=
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle E=p\ f,F=(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))}
d
e
-
l
a
m
b
d
a
[
E
]
=
d
e
-
l
a
m
b
d
a
[
F
]
{\displaystyle \operatorname {de-lambda} [E]=\operatorname {de-lambda} [F]}
d
e
-
l
a
m
b
d
a
[
p
f
]
=
d
e
-
l
a
m
b
d
a
[
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
{\displaystyle \operatorname {de-lambda} [p\ f]=\operatorname {de-lambda} [(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]}
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
d
e
-
l
a
m
b
d
a
[
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {de-lambda} [(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]\operatorname {in} p]}
5
show
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
d
e
-
l
a
m
b
d
a
[
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {de-lambda} [(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]\operatorname {in} p]}
d
e
-
l
a
m
b
d
a
[
(
λ
x
.
f
(
x
x
)
)
(
λ
x
.
f
(
x
x
)
)
]
{\displaystyle \operatorname {de-lambda} [(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))]}
d
e
-
l
a
m
b
d
a
[
(
λ
F
.
E
)
L
]
{\displaystyle \operatorname {de-lambda} [(\lambda F.E)L]}
F
=
x
,
E
=
f
(
x
x
)
,
L
=
(
λ
x
.
f
(
x
x
)
)
{\displaystyle F=x,E=f\ (x\ x),L=(\lambda x.f\ (x\ x))}
l
e
t
-
c
o
m
b
i
n
e
[
let
F
:
d
e
-
l
a
m
b
d
a
[
F
=
L
]
in
E
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} F:\operatorname {de-lambda} [F=L]\operatorname {in} E]}
l
e
t
-
c
o
m
b
i
n
e
[
let
x
:
d
e
-
l
a
m
b
d
a
[
x
=
λ
x
.
f
(
x
x
)
]
in
f
(
x
x
)
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} x:\operatorname {de-lambda} [x=\lambda x.f\ (x\ x)]\operatorname {in} f\ (x\ x)]}
3
show
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
l
e
t
-
c
o
m
b
i
n
e
[
let
x
:
d
e
-
l
a
m
b
d
a
[
x
=
λ
x
.
f
(
x
x
)
]
in
f
(
x
x
)
]
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {let-combine} [\operatorname {let} x:\operatorname {de-lambda} [x=\lambda x.f\ (x\ x)]\operatorname {in} f\ (x\ x)]\operatorname {in} p]}
d
e
-
l
a
m
b
d
a
[
x
=
λ
x
.
f
(
x
x
)
]
{\displaystyle \operatorname {de-lambda} [x=\lambda x.f\ (x\ x)]}
d
e
-
l
a
m
b
d
a
[
F
=
λ
P
.
E
]
{\displaystyle \operatorname {de-lambda} [F=\lambda P.E]}
F
=
x
,
P
=
x
,
E
=
f
(
x
x
)
{\displaystyle F=x,P=x,E=f\ (x\ x)}
d
e
-
l
a
m
b
d
a
[
F
P
=
E
]
{\displaystyle \operatorname {de-lambda} [F\ P=E]}
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
{\displaystyle \operatorname {de-lambda} [x\ x=f\ (x\ x)]}
8
show
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
l
e
t
-
c
o
m
b
i
n
e
[
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
]
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {let-combine} [\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)]\operatorname {in} p]}
l
e
t
-
c
o
m
b
i
n
e
[
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)]}
l
e
t
-
c
o
m
b
i
n
e
[
Y
]
{\displaystyle \operatorname {let-combine} [Y]}
Y
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
{\displaystyle Y=\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)}
Y
{\displaystyle Y}
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
{\displaystyle \operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)}
8
show
l
e
t
-
c
o
m
b
i
n
e
[
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
in
p
]
{\displaystyle \operatorname {let-combine} [\operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)\operatorname {in} p]}
l
e
t
-
c
o
m
b
i
n
e
[
Y
]
{\displaystyle \operatorname {let-combine} [Y]}
Y
=
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
]
in
p
{\displaystyle Y=\operatorname {let} p:\operatorname {de-lambda} [p\ f=\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)]\operatorname {in} p}
Y
{\displaystyle Y}
let
p
:
p
f
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
in
p
{\displaystyle \operatorname {let} p:p\ f=\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)\operatorname {in} p}
4
show
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
in
f
(
x
x
)
in
p
{\displaystyle \operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {let} x:\operatorname {de-lambda} [x\ x=f\ (x\ x)]\operatorname {in} f\ (x\ x)\operatorname {in} p}
d
e
-
l
a
m
b
d
a
[
x
x
=
f
(
x
x
)
]
{\displaystyle \operatorname {de-lambda} [x\ x=f\ (x\ x)]}
d
e
-
l
a
m
b
d
a
[
E
=
F
]
{\displaystyle \operatorname {de-lambda} [E=F]}
E
=
x
x
,
F
=
f
(
x
x
)
{\displaystyle E=x\ x,F=f\ (x\ x)}
d
e
-
l
a
m
b
d
a
[
E
]
=
d
e
-
l
a
m
b
d
a
[
F
]
{\displaystyle \operatorname {de-lambda} [E]=\operatorname {de-lambda} [F]}
d
e
-
l
a
m
b
d
a
[
x
x
]
=
d
e
-
l
a
m
b
d
a
[
f
(
x
x
)
]
{\displaystyle \operatorname {de-lambda} [x\ x]=\operatorname {de-lambda} [f\ (x\ x)]}
2
show
let
p
:
d
e
-
l
a
m
b
d
a
[
p
f
]
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
x
]
=
d
e
-
l
a
m
b
d
a
[
f
(
x
x
)
]
in
f
(
x
x
)
in
p
{\displaystyle \operatorname {let} p:\operatorname {de-lambda} [p\ f]=\operatorname {let} x:\operatorname {de-lambda} [x\ x]=\operatorname {de-lambda} [f\ (x\ x)]\operatorname {in} f\ (x\ x)\operatorname {in} p}
d
e
-
l
a
m
b
d
a
[
x
x
]
,
d
e
-
l
a
m
b
d
a
[
f
(
x
x
)
]
{\displaystyle \operatorname {de-lambda} [x\ x],\operatorname {de-lambda} [f\ (x\ x)]}
d
e
-
l
a
m
b
d
a
[
p
f
]
,
d
e
-
l
a
m
b
d
a
[
M
1
N
1
]
,
d
e
-
l
a
m
b
d
a
[
M
2
N
2
]
,
{\displaystyle \operatorname {de-lambda} [p\ f],\operatorname {de-lambda} [M_{1}\ N_{1}],\operatorname {de-lambda} [M_{2}\ N_{2}],}
M
1
=
p
,
N
1
=
f
,
M
2
=
x
,
N
2
=
x
,
M
3
=
f
,
N
3
=
x
x
{\displaystyle M_{1}=p,N_{1}=f,M_{2}=x,N_{2}=x,M_{3}=f,N_{3}=x\ x}
d
e
-
l
a
m
b
d
a
[
M
1
]
d
e
-
l
a
m
b
d
a
[
N
1
]
,
d
e
-
l
a
m
b
d
a
[
M
2
]
d
e
-
l
a
m
b
d
a
[
N
2
]
,
d
e
-
l
a
m
b
d
a
[
M
3
]
d
e
-
l
a
m
b
d
a
[
N
3
]
{\displaystyle \operatorname {de-lambda} [M_{1}]\ \operatorname {de-lambda} [N_{1}],\operatorname {de-lambda} [M_{2}]\ \operatorname {de-lambda} [N_{2}],\operatorname {de-lambda} [M_{3}]\ \operatorname {de-lambda} [N_{3}]}
d
e
-
l
a
m
b
d
a
[
p
]
d
e
-
l
a
m
b
d
a
[
f
]
,
d
e
-
l
a
m
b
d
a
[
x
]
d
e
-
l
a
m
b
d
a
[
x
]
,
d
e
-
l
a
m
b
d
a
[
f
]
d
e
-
l
a
m
b
d
a
[
x
]
d
e
-
l
a
m
b
d
a
[
x
]
{\displaystyle \operatorname {de-lambda} [p]\ \operatorname {de-lambda} [f],\operatorname {de-lambda} [x]\ \operatorname {de-lambda} [x],\operatorname {de-lambda} [f]\ \operatorname {de-lambda} [x]\ \operatorname {de-lambda} [x]}
1
show
let
p
:
d
e
-
l
a
m
b
d
a
[
p
]
d
e
-
l
a
m
b
d
a
[
f
]
=
let
x
:
d
e
-
l
a
m
b
d
a
[
x
]
d
e
-
l
a
m
b
d
a
[
x
]
=
d
e
-
l
a
m
b
d
a
[
f
]
(
d
e
-
l
a
m
b
d
a
[
x
]
d
e
-
l
a
m
b
d
a
[
x
]
)
in
f
(
x
x
)
]
in
p
{\displaystyle \operatorname {let} p:\operatorname {de-lambda} [p]\ \operatorname {de-lambda} [f]=\operatorname {let} x:\operatorname {de-lambda} [x]\ \operatorname {de-lambda} [x]=\operatorname {de-lambda} [f]\ (\operatorname {de-lambda} [x]\ \operatorname {de-lambda} [x])\operatorname {in} f\ (x\ x)]\operatorname {in} p}
d
e
-
l
a
m
b
d
a
[
V
]
{\displaystyle \operatorname {de-lambda} [V]}
V
{\displaystyle V}
let
p
:
p
f
=
let
x
:
x
x
=
f
(
x
x
)
in
f
(
x
x
)
]
in
p
{\displaystyle \operatorname {let} p:p\ f=\operatorname {let} x:x\ x=f\ (x\ x)\operatorname {in} f\ (x\ x)]\operatorname {in} p}
Conversion from let to lambda expressions [ edit ]
These rules reverse the conversion described above. They convert from a let expression to a lambda expression, without altering the structure. Not all let expressions may be converted using these rules. The rules assume that the expressions are already arranged as if they had been generated by de-lambda .
g
e
t
-
l
a
m
b
d
a
[
F
,
G
V
=
E
]
=
g
e
t
-
l
a
m
b
d
a
[
F
,
G
=
λ
V
.
E
]
{\displaystyle \operatorname {get-lambda} [F,G\ V=E]=\operatorname {get-lambda} [F,G=\lambda V.E]}
g
e
t
-
l
a
m
b
d
a
[
F
,
F
=
E
]
=
d
e
-
l
e
t
[
E
]
{\displaystyle \operatorname {get-lambda} [F,F=E]=\operatorname {de-let} [E]}
d
e
-
l
e
t
[
λ
V
.
E
]
≡
λ
V
.
d
e
-
l
e
t
[
E
]
{\displaystyle \operatorname {de-let} [\lambda V.E]\equiv \lambda V.\operatorname {de-let} [E]}
d
e
-
l
e
t
[
M
N
]
≡
d
e
-
l
e
t
[
M
]
d
e
-
l
e
t
[
N
]
{\displaystyle \operatorname {de-let} [M\ N]\equiv \operatorname {de-let} [M]\ \operatorname {de-let} [N]}
d
e
-
l
e
t
[
V
]
≡
V
{\displaystyle \operatorname {de-let} [V]\equiv V}
V
∉
F
V
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
:
E
in
V
]
≡
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
{\displaystyle 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
∉
F
V
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
:
E
in
L
]
≡
(
λ
V
.
d
e
-
l
e
t
[
L
]
)
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
{\displaystyle 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
∉
FV
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
,
W
:
E
∧
F
in
G
]
≡
d
e
-
l
e
t
[
let
V
:
E
in
let
W
:
F
in
G
]
{\displaystyle 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
∈
FV
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
:
E
in
L
]
≡
d
e
-
l
e
t
[
let
V
:
V
V
=
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
[
V
:=
V
V
]
in
L
[
V
:=
V
V
]
]
{\displaystyle 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
∈
FV
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
,
W
:
E
∧
F
in
L
]
≡
d
e
-
l
e
t
[
let
V
:
V
W
=
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
[
V
:=
V
W
]
in
let
W
:
F
[
V
:=
V
W
]
in
L
[
V
:=
V
W
]
]
{\displaystyle 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 .
l
a
m
b
d
a
-
f
o
r
m
[
G
V
=
E
]
=
l
a
m
b
d
a
-
f
o
r
m
[
G
=
λ
V
.
E
]
{\displaystyle \operatorname {lambda-form} [G\ V=E]=\operatorname {lambda-form} [G=\lambda V.E]}
l
a
m
b
d
a
-
f
o
r
m
[
E
∧
F
]
=
l
a
m
b
d
a
-
f
o
r
m
[
E
]
∧
l
a
m
b
d
a
-
f
o
r
m
[
F
]
{\displaystyle \operatorname {lambda-form} [E\land F]=\operatorname {lambda-form} [E]\land \operatorname {lambda-form} [F]}
l
a
m
b
d
a
-
f
o
r
m
[
V
=
E
]
=
V
=
E
{\displaystyle \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
∈
FV
[
E
]
→
l
i
f
t
-
v
a
r
s
[
X
,
V
=
E
]
=
{
V
}
{\displaystyle X\in \operatorname {FV} [E]\to \operatorname {lift-vars} [X,V=E]=\{V\}}
X
∉
FV
[
E
]
→
l
i
f
t
-
v
a
r
s
[
X
,
V
=
E
]
=
{
}
{\displaystyle X\not \in \operatorname {FV} [E]\to \operatorname {lift-vars} [X,V=E]=\{\}}
l
i
f
t
-
v
a
r
s
[
X
,
E
∧
F
]
=
l
i
f
t
-
v
a
r
s
[
X
,
E
]
∪
l
i
f
t
-
v
a
r
s
[
X
.
F
]
{\displaystyle \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.
s
u
b
-
v
a
r
s
[
E
,
{
V
}
∪
S
,
X
]
=
s
u
b
-
v
a
r
s
[
E
[
V
:=
V
X
]
,
S
,
X
]
{\displaystyle \operatorname {sub-vars} [E,\{V\}\cup S,X]=\operatorname {sub-vars} [E[V:=V\ X],S,X]}
s
u
b
-
v
a
r
s
[
E
,
{
}
,
X
]
=
E
{\displaystyle \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.
L
=
l
a
m
b
d
a
-
f
o
r
m
[
E
]
∧
S
=
l
i
f
t
-
v
a
r
s
[
X
,
L
]
→
d
e
-
l
e
t
[
let
V
…
W
,
X
:
E
∧
F
in
G
]
≡
d
e
-
l
e
t
[
let
V
…
W
:
s
u
b
-
v
a
r
s
[
L
,
S
,
X
]
in
let
s
u
b
-
v
a
r
s
[
l
a
m
b
d
a
-
f
o
r
m
[
F
]
,
S
,
X
]
in
s
u
b
-
v
a
r
s
[
G
,
S
,
X
]
]
{\displaystyle {\begin{aligned}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{aligned}}}
Examples [ edit ]
For example, the let expression obtained from the Y combinator ,
let
p
:
p
f
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
in
p
{\displaystyle \operatorname {let} p:p\ f=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)\ \operatorname {in} p}
is converted to,
λ
f
.
(
λ
x
.
f
(
x
x
)
)
(
λ
q
.
f
(
q
q
)
)
{\displaystyle \lambda f.(\lambda x.f\ (x\ x))\ (\lambda q.f\ (q\ q))}
Rule
show Lambda expression
6
show
d
e
-
l
e
t
[
let
p
:
p
f
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
in
p
]
{\displaystyle \operatorname {de-let} [\operatorname {let} p:p\ f=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)\ \operatorname {in} p]}
d
e
-
l
e
t
[
let
V
:
E
in
V
]
{\displaystyle \operatorname {de-let} [\operatorname {let} V:E\ \operatorname {in} V]}
V
=
p
,
E
=
p
f
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
{\displaystyle V=p,E=p\ f=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)}
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
{\displaystyle \operatorname {get-lambda} [V,E]}
1
show
g
e
t
-
l
a
m
b
d
a
[
p
,
p
f
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
]
{\displaystyle \operatorname {get-lambda} [p,p\ f=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)]}
g
e
t
-
l
a
m
b
d
a
[
F
,
G
V
=
E
]
{\displaystyle \operatorname {get-lambda} [F,G\ V=E]}
F
=
p
,
G
=
p
,
V
=
f
,
E
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
{\displaystyle F=p,G=p,V=f,E=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)}
g
e
t
-
l
a
m
b
d
a
[
F
,
G
=
λ
V
.
E
]
{\displaystyle \operatorname {get-lambda} [F,G=\lambda V.E]}
2
show
g
e
t
-
l
a
m
b
d
a
[
p
,
p
=
λ
f
.
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
]
{\displaystyle \operatorname {get-lambda} [p,p=\lambda f.\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)]}
g
e
t
-
l
a
m
b
d
a
[
F
,
F
=
E
]
{\displaystyle \operatorname {get-lambda} [F,F=E]}
F
=
p
,
E
=
λ
f
.
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
{\displaystyle F=p,E=\lambda f.\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)}
d
e
-
l
e
t
[
E
]
{\displaystyle \operatorname {de-let} [E]}
3
show
d
e
-
l
e
t
[
λ
f
.
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
]
{\displaystyle \operatorname {de-let} [\lambda f.\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)]}
d
e
-
l
e
t
[
λ
V
.
E
]
{\displaystyle \operatorname {de-let} [\lambda V.E]}
V
=
f
,
E
=
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
{\displaystyle V=f,E=\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)}
λ
V
.
d
e
-
l
e
t
[
E
]
{\displaystyle \lambda V.\operatorname {de-let} [E]}
7
show
λ
f
.
d
e
-
l
e
t
[
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
]
{\displaystyle \lambda f.\operatorname {de-let} [\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)]}
d
e
-
l
e
t
[
let
x
:
x
q
=
f
(
q
q
)
in
f
(
x
x
)
]
{\displaystyle \operatorname {de-let} [\operatorname {let} x:x\ q=f\ (q\ q)\ \operatorname {in} f\ (x\ x)]}
V
∉
F
V
[
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
]
→
d
e
-
l
e
t
[
let
V
:
E
in
L
]
{\displaystyle V\not \in FV[\operatorname {get-lambda} [V,E]]\to \operatorname {de-let} [\operatorname {let} V:E\ \operatorname {in} L]}
V
=
x
,
E
=
x
q
=
f
(
q
q
)
,
L
=
f
(
x
x
)
{\displaystyle V=x,E=x\ q=f\ (q\ q),L=f\ (x\ x)}
(
λ
V
.
d
e
-
l
e
t
[
L
]
)
g
e
t
-
l
a
m
b
d
a
[
V
,
E
]
{\displaystyle (\lambda V.\operatorname {de-let} [L])\ \operatorname {get-lambda} [V,E]}
4
show
(
λ
x
.
d
e
-
l
e
t
[
f
(
x
x
)
]
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
q
=
f
(
q
q
)
]
{\displaystyle (\lambda x.\operatorname {de-let} [f\ (x\ x)])\ \operatorname {get-lambda} [x,x\ q=f\ (q\ q)]}
d
e
-
l
e
t
[
f
(
x
x
)
]
{\displaystyle \operatorname {de-let} [f\ (x\ x)]}
d
e
-
l
e
t
[
M
N
]
{\displaystyle \operatorname {de-let} [M\ N]}
M
=
f
,
N
=
(
x
x
)
{\displaystyle M=f,N=(x\ x)}
d
e
-
l
e
t
[
M
]
d
e
-
l
e
t
[
N
]
{\displaystyle \operatorname {de-let} [M]\ \operatorname {de-let} [N]}
d
e
-
l
e
t
[
f
]
d
e
-
l
e
t
[
x
x
]
{\displaystyle \operatorname {de-let} [f]\ \operatorname {de-let} [x\ x]}
4
show
(
λ
x
.
d
e
-
l
e
t
[
f
]
d
e
-
l
e
t
[
x
x
]
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
q
=
f
(
q
q
)
]
{\displaystyle (\lambda x.\operatorname {de-let} [f]\ \operatorname {de-let} [x\ x])\ \operatorname {get-lambda} [x,x\ q=f\ (q\ q)]}
d
e
-
l
e
t
[
x
x
]
{\displaystyle \operatorname {de-let} [x\ x]}
d
e
-
l
e
t
[
M
N
]
{\displaystyle \operatorname {de-let} [M\ N]}
M
=
x
,
N
=
x
{\displaystyle M=x,N=x}
d
e
-
l
e
t
[
M
]
d
e
-
l
e
t
[
N
]
{\displaystyle \operatorname {de-let} [M]\ \operatorname {de-let} [N]}
d
e
-
l
e
t
[
x
]
d
e
-
l
e
t
[
x
]
{\displaystyle \operatorname {de-let} [x]\ \operatorname {de-let} [x]}
5
show
(
λ
x
.
d
e
-
l
e
t
[
f
]
(
d
e
-
l
e
t
[
x
]
d
e
-
l
e
t
[
x
]
)
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
q
=
f
(
q
q
)
]
{\displaystyle (\lambda x.\operatorname {de-let} [f]\ (\operatorname {de-let} [x]\ \operatorname {de-let} [x]))\ \operatorname {get-lambda} [x,x\ q=f\ (q\ q)]}
d
e
-
l
e
t
[
V
]
{\displaystyle \operatorname {de-let} [V]}
V
{\displaystyle V}
1
show
(
λ
x
.
f
(
x
x
)
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
q
=
f
(
q
q
)
]
{\displaystyle (\lambda x.f\ (x\ x))\ \operatorname {get-lambda} [x,x\ q=f\ (q\ q)]}
g
e
t
-
l
a
m
b
d
a
[
x
,
x
q
=
f
(
q
q
)
]
{\displaystyle \operatorname {get-lambda} [x,x\ q=f\ (q\ q)]}
g
e
t
-
l
a
m
b
d
a
[
F
,
G
V
=
E
]
{\displaystyle \operatorname {get-lambda} [F,G\ V=E]}
F
=
x
,
G
=
x
,
V
=
q
,
E
=
f
(
q
q
)
{\displaystyle F=x,G=x,V=q,E=f\ (q\ q)}
g
e
t
-
l
a
m
b
d
a
[
F
,
G
=
λ
V
.
E
]
{\displaystyle \operatorname {get-lambda} [F,G=\lambda V.E]}
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
q
.
f
(
q
q
)
]
{\displaystyle \operatorname {get-lambda} [x,x=\lambda q.f\ (q\ q)]}
2
show
(
λ
x
.
f
(
x
x
)
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
q
.
f
(
q
q
)
]
{\displaystyle (\lambda x.f\ (x\ x))\ \operatorname {get-lambda} [x,x=\lambda q.f\ (q\ q)]}
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
q
.
f
(
q
q
)
]
{\displaystyle \operatorname {get-lambda} [x,x=\lambda q.f\ (q\ q)]}
g
e
t
-
l
a
m
b
d
a
[
F
,
F
=
E
]
{\displaystyle \operatorname {get-lambda} [F,F=E]}
F
=
x
,
E
=
λ
q
.
f
(
q
q
)
{\displaystyle F=x,E=\lambda q.f\ (q\ q)}
d
e
-
l
e
t
[
E
]
{\displaystyle \operatorname {de-let} [E]}
d
e
-
l
e
t
[
λ
q
.
f
(
q
q
)
]
{\displaystyle \operatorname {de-let} [\lambda q.f\ (q\ q)]}
3
show
(
λ
x
.
f
(
x
x
)
)
d
e
-
l
e
t
[
λ
q
.
f
(
q
q
)
]
{\displaystyle (\lambda x.f\ (x\ x))\ \operatorname {de-let} [\lambda q.f\ (q\ q)]}
d
e
-
l
e
t
[
λ
q
.
f
(
q
q
)
]
{\displaystyle \operatorname {de-let} [\lambda q.f\ (q\ q)]}
d
e
-
l
e
t
[
λ
V
.
E
]
{\displaystyle \operatorname {de-let} [\lambda V.E]}
V
=
q
,
E
=
f
(
q
q
)
{\displaystyle V=q,E=f\ (q\ q)}
λ
V
.
d
e
-
l
e
t
[
E
]
{\displaystyle \lambda V.\operatorname {de-let} [E]}
λ
q
.
d
e
-
l
e
t
[
f
(
q
q
)
]
{\displaystyle \lambda q.\operatorname {de-let} [f\ (q\ q)]}
4
show
(
λ
x
.
f
(
x
x
)
)
(
λ
q
.
d
e
-
l
e
t
[
f
(
q
q
)
]
)
{\displaystyle (\lambda x.f\ (x\ x))\ (\lambda q.\operatorname {de-let} [f\ (q\ q)])}
d
e
-
l
e
t
[
f
(
q
q
)
]
{\displaystyle \operatorname {de-let} [f\ (q\ q)]}
d
e
-
l
e
t
[
M
1
N
1
]
{\displaystyle \operatorname {de-let} [M_{1}\ N_{1}]}
M
1
=
f
,
N
1
=
q
q
{\displaystyle M_{1}=f,N_{1}=q\ q}
d
e
-
l
e
t
[
M
1
]
d
e
-
l
e
t
[
N
1
]
{\displaystyle \operatorname {de-let} [M_{1}]\ \operatorname {de-let} [N_{1}]}
d
e
-
l
e
t
[
f
]
d
e
-
l
e
t
[
q
q
]
{\displaystyle \operatorname {de-let} [f]\ \operatorname {de-let} [q\ q]}
d
e
-
l
e
t
[
M
2
N
2
]
{\displaystyle \operatorname {de-let} [M_{2}\ N_{2}]}
M
2
=
q
,
N
2
=
q
{\displaystyle M_{2}=q,N_{2}=q}
d
e
-
l
e
t
[
q
]
d
e
-
l
e
t
[
q
]
{\displaystyle \operatorname {de-let} [q]\ \operatorname {de-let} [q]}
5
show
(
λ
x
.
f
(
x
x
)
)
(
λ
q
.
d
e
-
l
e
t
[
f
]
(
d
e
-
l
e
t
[
q
]
d
e
-
l
e
t
[
q
]
)
)
{\displaystyle (\lambda x.f\ (x\ x))\ (\lambda q.\operatorname {de-let} [f]\ (\operatorname {de-let} [q]\ \operatorname {de-let} [q]))}
d
e
-
l
e
t
[
V
]
{\displaystyle \operatorname {de-let} [V]}
{\displaystyle }
V
{\displaystyle V}
(
λ
x
.
f
(
x
x
)
)
(
λ
q
.
f
(
q
q
)
)
{\displaystyle (\lambda x.f\ (x\ x))\ (\lambda q.f\ (q\ q))}
For a second example take the lifted version of the Y combinator ,
let
p
,
q
:
p
f
x
=
f
(
x
x
)
∧
q
p
f
=
(
p
f
)
(
p
f
)
in
q
p
{\displaystyle \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,
(
λ
p
.
(
λ
q
.
q
p
)
λ
p
.
λ
f
.
(
p
f
)
(
p
f
)
)
λ
f
.
λ
x
.
f
(
x
x
)
{\displaystyle (\lambda p.(\lambda q.q\ p)\ \lambda p.\lambda f.(p\ f)\ (p\ f))\ \lambda f.\lambda x.f\ (x\ x)}
Rule
show Lambda expression
8
d
e
-
l
e
t
[
let
p
,
q
:
p
f
x
=
f
(
x
x
)
∧
q
p
f
=
(
p
f
)
(
p
f
)
in
q
p
]
{\displaystyle \operatorname {de-let} [\operatorname {let} p,q:p\ f\ x=f\ (x\ x)\land q\ p\ f=(p\ f)\ (p\ f)\ \operatorname {in} q\ p]}
7
d
e
-
l
e
t
[
let
p
:
p
f
x
=
f
(
x
x
)
in
let
q
:
q
p
f
=
(
p
f
)
(
p
f
)
in
q
p
]
{\displaystyle \operatorname {de-let} [\operatorname {let} p:p\ f\ x=f\ (x\ x)\ \operatorname {in} \operatorname {let} q:q\ p\ f=(p\ f)\ (p\ f)\ \operatorname {in} q\ p]}
1, 2
(
λ
p
.
d
e
-
l
e
t
[
let
q
:
q
p
f
=
(
p
f
)
(
p
f
)
in
q
p
]
)
g
e
t
-
l
a
m
b
d
a
[
p
,
p
f
x
=
f
(
x
x
)
]
{\displaystyle (\lambda p.\operatorname {de-let} [\operatorname {let} q:q\ p\ f=(p\ f)\ (p\ f)\ \operatorname {in} q\ p])\ \operatorname {get-lambda} [p,p\ f\ x=f\ (x\ x)]}
7, 4, 5
(
λ
p
.
d
e
-
l
e
t
[
let
q
:
q
p
f
=
(
p
f
)
(
p
f
)
in
q
p
]
)
λ
f
.
λ
x
.
f
(
x
x
)
{\displaystyle (\lambda p.\operatorname {de-let} [\operatorname {let} q:q\ p\ f=(p\ f)\ (p\ f)\ \operatorname {in} q\ p])\ \lambda f.\lambda x.f\ (x\ x)}
1, 2
(
λ
p
.
(
λ
q
.
q
p
)
g
e
t
-
l
a
m
b
d
a
[
q
,
q
p
f
=
(
p
f
)
(
p
f
)
]
)
λ
f
.
λ
x
.
f
(
x
x
)
{\displaystyle (\lambda p.(\lambda q.q\ p)\ \operatorname {get-lambda} [q,q\ p\ f=(p\ f)\ (p\ f)])\ \lambda f.\lambda x.f\ (x\ x)}
(
λ
p
.
(
λ
q
.
q
p
)
λ
p
.
λ
f
.
(
p
f
)
(
p
f
)
)
λ
f
.
λ
x
.
f
(
x
x
)
{\displaystyle (\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,
let
x
:
x
f
=
f
(
x
f
)
in
x
{\displaystyle \operatorname {let} x:x\ f=f\ (x\ f)\ \operatorname {in} x}
is,
(
λ
x
.
x
x
)
(
λ
x
.
λ
f
.
f
(
x
x
f
)
)
{\displaystyle (\lambda x.x\ x)\ (\lambda x.\lambda f.f\ (x\ x\ f))}
Rule
show Lambda expression
9
let
x
:
x
f
=
f
(
x
f
)
in
x
{\displaystyle \operatorname {let} x:x\ f=f\ (x\ f)\ \operatorname {in} x}
1
let
x
:
x
x
=
g
e
t
-
l
a
m
b
d
a
[
x
,
x
f
=
f
(
x
f
)
]
[
x
:=
x
x
]
in
x
[
x
:=
x
x
]
{\displaystyle \operatorname {let} x:x\ x=\operatorname {get-lambda} [x,x\ f=f\ (x\ f)][x:=x\ x]\ \operatorname {in} x[x:=x\ x]}
2
let
x
:
x
x
=
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
f
.
f
(
x
f
)
]
[
x
:=
x
x
]
in
x
x
{\displaystyle \operatorname {let} x:x\ x=\operatorname {get-lambda} [x,x=\lambda f.f\ (x\ f)][x:=x\ x]\ \operatorname {in} x\ x}
let
x
:
x
x
=
(
λ
f
.
f
(
x
f
)
)
[
x
:=
x
x
]
in
x
x
{\displaystyle \operatorname {let} x:x\ x=(\lambda f.f\ (x\ f))[x:=x\ x]\ \operatorname {in} x\ x}
7
let
x
:
x
x
=
λ
f
.
f
(
x
x
f
)
in
x
x
{\displaystyle \operatorname {let} x:x\ x=\lambda f.f\ (x\ x\ f)\ \operatorname {in} x\ x}
1
(
λ
x
.
x
x
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
x
=
λ
f
.
f
(
x
x
f
)
]
{\displaystyle (\lambda x.x\ x)\ \operatorname {get-lambda} [x,x\ x=\lambda f.f\ (x\ x\ f)]}
2
(
λ
x
.
x
x
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
x
.
λ
f
.
f
(
x
x
f
)
]
{\displaystyle (\lambda x.x\ x)\ \operatorname {get-lambda} [x,x=\lambda x.\lambda f.f\ (x\ x\ f)]}
(
λ
x
.
x
x
)
(
λ
x
.
λ
f
.
f
(
x
x
f
)
)
{\displaystyle (\lambda x.x\ x)\ (\lambda x.\lambda f.f\ (x\ x\ f))}
For a forth example the translation of,
let
x
:
x
=
f
x
in
x
{\displaystyle \operatorname {let} x:x=f\ x\ \operatorname {in} x}
is,
(
λ
x
.
x
x
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle (\lambda x.x\ x)\ (\lambda x.f\ (x\ x))}
which is the famous y combinator .
Rule
show Lambda expression
9
let
x
:
x
=
f
x
in
x
{\displaystyle \operatorname {let} x:x=f\ x\ \operatorname {in} x}
2
let
x
:
x
x
=
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
f
x
]
[
x
:=
x
x
]
in
x
[
x
:=
x
x
]
{\displaystyle \operatorname {let} x:x\ x=\operatorname {get-lambda} [x,x=f\ x][x:=x\ x]\ \operatorname {in} x[x:=x\ x]}
let
x
:
x
x
=
(
f
x
)
[
x
:=
x
x
]
in
x
x
{\displaystyle \operatorname {let} x:x\ x=(f\ x)[x:=x\ x]\ \operatorname {in} x\ x}
7
let
x
:
x
x
=
f
(
x
x
)
in
x
x
{\displaystyle \operatorname {let} x:x\ x=f\ (x\ x)\ \operatorname {in} x\ x}
1
(
λ
x
.
x
x
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
x
=
f
(
x
x
)
]
{\displaystyle (\lambda x.x\ x)\ \operatorname {get-lambda} [x,x\ x=f\ (x\ x)]}
2
(
λ
x
.
x
x
)
g
e
t
-
l
a
m
b
d
a
[
x
,
x
=
λ
x
.
f
(
x
x
)
]
{\displaystyle (\lambda x.x\ x)\ \operatorname {get-lambda} [x,x=\lambda x.f\ (x\ x)]}
(
λ
x
.
x
x
)
(
λ
x
.
f
(
x
x
)
)
{\displaystyle (\lambda x.x\ x)\ (\lambda x.f\ (x\ x))}
Key people [ edit ]
See also [ edit ]
References [ edit ]
Works cited [ edit ]