We can define an equivalence relation on type expressions.
1 and
2 are equivalent if there exist
and
' for which
1 =
(
2)
and also
2 =
'(
1)
Or in other words, two type-expressions are equivalent if each is an instance of the other.
(
1) =
(
2)
if '(
1) =
'(
2) then there exists
" such that
' =
" o
where
o is functional product.
The most general unifier is unique up to equivalence.
=
for any type-variable
. (We can
interpret this by saying that
can be unified
with
,
so that the previous rule could be applied).
((1
2)
)
=
otherwise
Suppose =
,
a type-constant. Then
does not unify
with
for
any type-variable
.
Suppose =
1
2
Then
does not unify with
0
So the only possiblity is that
=
,
a type-variable.
Then
=
mgu(
1,
1)
exists, so that
mgu(
2,
1)
also exists. Therefore
2 =
or
2 =
, for some
type-variable
. In the latter case,
mgu(
,
) exists, where
=
for some type variable
. But this does not unify
with
1, a contradiction. Therefore
2 =
Consider 1 of height h + 1,
and
2, supposing that
Now suppose ' unifies with
21. Then, for any type variable
it is clear that
'
unifies with
11
12
hence, by our supposition,
'
unifies with
21
22
so that
' unifies with
21.
Conversely, any " which unifies with
21 also unifies with
11. Hence by the inductive hypothesis,
11 is equivalent to
21.
Similarly 12 is equivalent to
22. Hence
1 is
equivalent to
2, establishing our result.
K =
S =
(
)
(
)
=
((
)
1) =
Now consider
((
)
(
)
)
1
2
3 )
We may suppose that the variables of
1,
2 and
3
are distinct.
There are 2 cases.
for some
11,
12,
13. Moreover
(((11
12)
11
13)
2
3 )
There are 2 sub-cases:
where
(
12) =
(
22) =
'12
(
13) =
'13
Moreover
There are two sub-sub-cases
We'll also write
'(
(
12))
=
"12 and
'(
(
11))
=
"11
Now 11 and
3 have a common instance in
"11, so that
exists. Now consider
(1
3)
(
2
3 )
=
((11
12
13)
3)
(
2
3 )
=
(
"'12
"'13)
(
2
3 )
Where
Proceeding, we obtain
(1
3)
(
2
3 )
=
(
"'12
"'13)
(
(
21
22 )
3 )
But 21 and
3
also have a common instance in
"11
so that
exists. Hence
(1
3)
(
2
3 )
=
(
"'12
"'13)
""22
Where
""22 =
""(
22).
Since
"11
is a common instance of
11,
3
there exists
- for which
-(
'''
(
12))
=
'(
(
12))
=
"12
-(
'''
(
13))
=
'(
(
12))
=
"13
(for we we are free to choose - so that
the function product
- o
'''
agrees with
' o
for those variables of
12,
13 that do not
occur in
11).
Likewise, since "11 is a common instance of
3 and
21
there exists
x
for which
x(
""
(
22))
=
'(
(
22))
=
"12
for we can choose x so that the
function product
x o
""
agrees with the function product
' o
for those variables of
22 that do not occur
in
21.
Thus "12 is an instance of
"'12 and
""22.
Hence there exists
and moreover "12 is an instance of
+(
'12)
=
+12, say, that is, for
some
y,
where again we may choose y so that
y o
+o
"'
agrees with
' o
for those variables of
13 that do not
occur in
12.
Now +12 is an instance of
12 and
22.
Hence there exists
# for which
#(
(
11))
=
+(
"'
(
11))
=
+11
That is
z(
'
(
(
13)))
=
+(
"'
(
13)
On the other hand
Thus the result is true in this sub-sub-case.
Now consider
(1
3)
(
2
3 )
=
((11
12
13)
3)
(
2
3 )
Now suppose
"' = mgu(
11 ,
3) does exist.
=
"'(
12
13)
(
2
3 )
=
"'(
12
13)
(
(
21
22)
3 )
Likewise, suppose
"" = mgu(
21 ,
3) does exist.
=
("'(
12)
"'(
13))
""(
22)
Finally, suppose
+ =
mgu
(
"'(
12),
""(
22))
exists. Then
+12 is a common
instance of
12 and
22. Therefore there exists
# for which
Thus 11 and
11 have a common instance, a contradiction
to the basic assumption of sub-sub-case 1.1.2. Hence either of the most
general unifiers we have subsequently supposed to exist in this
sub-sub-case does not exist. In either of these circumstances
(1
3)
(
2
3 )
=
In this sub-case we can, as above, construct
+ and
# leading
to the conclusion that, if
(
1
3)
(
2
3 )
then
11
12
and
2 does exist
(S
1
2
3 )
=
(1
3)
(
2
3 )
=
(
2
3 )
=
=
(S
1
2
3 )
In this case (1
3) is an instance
of
12, which will give
when applied to (
2
3 )
There are 3 cases
While
d0 d1 =
Here
d0 = d0
so the required equation is immediate.
Then for any
function type 1
2,
However, for any non-function
type ,
= bottom.
Suppose
where
= mgu(
11,
21). Thus
12 is an instance of
22. Likewise
22 is
an
instance of
12. Hence
12 is equivalent to
22.
Moreover, any that unifies with
11 necessarily unifies with
12, and conversely. So, by Lemma TA3 above,
we have that
11 is equivalent to
12.
=
(
)
(
)
=
In particular both Curry's and Turing's fixpoint combinators involve
self-application, so both map to in the type-algebra.
However the following lemma shows that the existence of a
well-typed fixpoint operator is not ruled out.
(((
)
)
)
((
1
2)
1
2)
=
1
2
On the other hand
=
((1
2)
1
2)
1
2
=
1
2
Thus establishing our result.
let variable = expr1 in expr2 endas being a sugared form of
let m = map in length (m sin list1) + length (m hd list2) endHere map has the polymorphic type (
(float -> float) -> (List float) -> (List float)while the second has type
((Listbut if we consider the corresponding) ->
) -> (List (List
)) -> (List
)
((we have a problem that m is not, according to the usual rules, allowed to have different instances of a polymorphic type. We canm. length (m sin list1) + length (m hd list2) ) map)
((m1. length (m1 sin list1) + length (m2 hd list2) ) map map)