Unformatted text preview: Equation 1 says that the entire expression produces a procedure that takes
an argument of type t f and produces a value of the same type as that of
. 22 ¢
¤ ¦ Equation 6 says that expects an argument of type
of the same type as that of and returns a value ¡ ¦
£¡ ¦ Similarly equation 7 says that expects an argument of the same type as
that of and returns a value of the same type as that of
.
¦
£¡ 5
5 We can ﬁll in t f , t x , t0 , t1 , t2 , t3 , and t4 in any way we like, so long as they satisfy
the equations
t1
t2 ¢ ¢
¤
¢ ¤ ¤ ¤ tx ¢ tf
tx t0
t1
t3
t4
t2
tf
tf t4 t3 Our goal is to ﬁnd values for the variables that make all the equations true. We
can express such a solution as a set of equations where the lefthand sides are all
variables. We call such a set of equations a substitution. The variables that occur
on the lefthand side of some equation in the substitution are said to be bound in
the substitution. 23 We can solve such equations systematically. This process is called uniﬁcation.
We separate the state of our calculation into the set of equations still to be solved
and the substitution found so far. Initially, all of the equations are to be solved,
and the substitution found is empty. Equations
t0 t f
t1
t2
t1 t x
t3
t4
t2
tf
t3
t f tx
t4 Substitution ¢
¢ ¤ ¢ ¤ ¢ ¤ ¤ We consider each equation in turn. If the equation’s lefthand side is a variable,
we add it to the substitution. Substitution
t0 t f
t1 Equations
t1 t x
t2
t3
t4
t2
tf
t3
t f tx
t4 ¢ ¢ ¤ ¢ ¤ ¢ ¤ ¤ However, doing this may change the substitution. For example, our next equation
gives a value for t1 . We need to propagate that information into the value for t 0 ,
which contains t1 on its righthand side. So we substitute the righthand side for
each occurrence of t1 in the substitution. This gets us: 24 Substitution
t0 t f
(t x
t1 t x
t2 t2 ) Equations
t3
t4
t2
tf
t3
t f tx
t4 ¢ ¤
¤ ¢ ¤ ¢ ¢ ¤ If the righthand side were a variable, we’d switch the sides and do the same thing.
We can continue in this manner for the next three equations. Substitution
t0 t f
(t x
t1 t x
t2
t3 Equations
t2
tf
t3
t f tx
t4 Substitution
t0 t f
(t x
t1 t x
t2
t3
t4 Equations
tf
t3
t f tx
t4 Substitution
t0 t f
(t x
t1 t x
t3
t4
t2 t2 ) Equations
t4
t2
tf
t3
t f tx
t4 ¢ t2 ) ¤ ¢ ¢
¤ ¤ ¢ ¤ ¢ ¤ ¢ ¤ ¢ ¢ ¤ ¢ ¤ ¢ ¤ ¢ ¤ ¢ ¢ ¤ ¤ 25 ) ¤ ¢ ¤ Now, the next equation to be considered contains t 3 , which is already bound to
in the substitution. So we substitute
for t3 in the equation. We would do
the same thing for any other type variables in the equation. We call this applying
the substitution to the equation. ¢ ¤
Substitution
t0 t f
(t x
t1 t x
t3
t4
t2 ¢ ¢ ¤ ¢ ¢ ¤ ¢ ¤ ) ¤ ¤ ¢ ¤ ¢ ¤ ¢ Equations
tf
t f tx
t4 ¤ We move the resulting equation into the substitution and update the substitution
as necessary; this time no updating takes place since t f does not occur in the
substitution. ¤ (t x ) ¢ ¢ ¤ ) ¢
Substitution
t0 (
t1 t x
t3
t4
t2
tf ¢ ¢
¤ ¤ ¤ ¢ ¢
¢ ¤ ¤ ¤ ¤ ¢ Equations
t f tx
t4 The next equation, t f
tx
t4 , contains t f and t4 , which are bound in the substitution, so we apply the substitution to this equation. This gets 26 (t x ¤ ¢ ) ) ¤ ¢ ¢ ¢ ¤ ¤ ¢ ¤ ¢ ¤ ¢ ¤ ¢ ¤ ¤ ¤
¢ ¢ ¤ ¢ ¤ tx Substitution
t0 (
t1 t x
t3
t4
t2
tf ¢ Equations If neither side of the equation is a variable, we can simplify, yielding two new
equations. (t x ¤ ¢ ) ¤ ) ¢ ¢ Substitution
t0 (
t1 t x
t3
t4
t2
tf ¢ Equations
tx ¢
¤ ¤ ¢ ¤ ¢ ¤ ¤ ¤ ¤ ¤ ¢ ¢ ¤ ¢ ¢ ¢ ¤ We can process these as usual: We switch the sides of the ﬁrst equation, add it to
the substitution, and update the substitution, as we did before. ¤ ¢
¤ ( ¢ ) ¢ ¢ ¤
¤ ¤ ¢ ¤ ¢ ¢ ¤ ¢ ¤
¤ ¢ ¤ ¢ ¢ ¢ ¢ ¤ ¤ ¤ ¤ ¢ §¢
¤ ¤ The ﬁnal equation, ) ¢ Substitution
t0 (
t1
t3
t4
t2
tf
tx Equations , is always true, so we can discard it.
27 ¢ ¤
( ¤ ¢ ) ¢ ¤
) ¤ ¢
Substitution
t0 (
t1
t3
t4
t2
tf
tx ¢ ¤ ¢ ¤ ¢ ¢ ¤ ¢ ¢ ¤ ¢
¢ ¤
¤ ¤ ¤ Equations We have no more equations, so we are done. We conclude from this calculation that our original expression
should be
assigned the type
¦¡ &...
View
Full Document
 Fall '09
 Logic, Expression, rator tenv

Click to edit the document details