Professional Documents
Culture Documents
ulus
Luigi Liquori1
Department of Mathemati
s and Computer S
ien
e, University of Udine,
Via delle S
ienze, 206 I-33100 Udine, Italy
Abstra
t. We develop a
al
ulus whi
h is a \dire
t" des
endant of the blue
al
ulus of Boudol [Bou97℄.
This
al
ulus is both an extension of Abadi & Cardelli's & -
al
ulus [AC96℄ and the Milner's -
al
ulus
[Mil93℄. We give a simple type system that is a dire
t extension of any type fragment
onsidered in
[AC96℄ en
odable into the -
al
ulus. The type system enjoys Subje
t Redu
tion. We provide nally an
adequate CPS transform from our
al
ulus to the blue
al
ulus. This transform shows that the latter
an be seen as a \target language", while our
al
ulus provide a very expressive and promising notation
for higher-order obje
t-oriented
on
urrent programming languages.
1 Introdu tion
In [Bou97℄, Boudol introdu
es the
al
ulus, a dire
t extension of the and the
al
uli. The main
inspiration of his was to argue that the
al
ulus as a basis for a programming language was not the best
hoi
e; As for the assembly language, a (skilled) \ "-programmer must make up names for intermediate
results. Counterwise, fun
tional, imperative and obje
t oriented
al
uli relies this (heavy, indeed) task to the
ompiler or the interpreter of the language.
Our aim here is to design a dire
t model for higher-order
on
urren
y, that would have the same expressive
power of the -
al
ulus, but would be more
onvenient as a programming notation.
The syntax of the Obje t Cal ulus with names (from now on & ) is:
O ::= x j [mi = & (x)Oi ℄i2I j x:m j x:m := & (y)O j let x1 = O1 ; : : : ; xn = On in O
This
al
ulus is both an extension and a restri
tion of the primitive
al
ulus of [AC96℄. The restri
tion is
that the re
ipient of a message sent is always a variable. The enri
hment
onsists in adding a \let"-de
laration,
as in Landin's ISWIM. The let-de
laration is always re
ursive.
The pro
ess of translation of the & -
al
ulus into the & -
al
ulus is spe
ied in two stages. The rst, whi
h we
write O , is simply -
onversion. The se
ond stage given by a \translation" fun
tion, written as , ensures
that the re
ipients of messages are always variables. It is dened as follows:
Translation fun
tion of & into &
x = x
([mi = & (x)Oi ℄i2I ) = [mi = & (x)Oi ℄i2I
` O + val; 0;
where val is an obje
t of the shape [mi = & (x)Oi ℄i2I . The rules of the operational semanti
s are presented
below:
Big-step operational semanti
s for &
(Obje
t)
` [mi = & (x)Oi ℄i2I + [mi = & (x)Oi ℄i2I ;
` x + [mi = & (y )Oi ℄i2I ; 0 0 ` Oj fx=yg + val; 00 j2I
(Sele
t)
` x:mj + val; 00
` O + [mi = & (y )Oi ℄i2I ; 0 val [mi = & (y)Oi ; mj = & (y)O0 ℄i2I nfjg j2I
(Override)
( ; x 7! O) ` x:mj := & (y )O0 + val ; ( 0 ; x 7! val)
` O + val;
(V ariable)
( ; x 7! O) ` x + val ; ( ; x 7! val)
( ; x1 7! O1 ; : : : ; xn 7! On ) ` O + val; 0
(Let)
` let x1 = O1 ; : : : ; xn = On in O + val; 0
Theorem 1.
For any
losed & -term O1 , O1 has a & -normal form O2 if and only if O1 has a & -normal form O2 .
2
1.4 A \low-level" translation of & into
We
ould en
ode the & -
al
ulus into the polyadi
-
al
ulus using & as an intermediate syntax, following
the \blue" lines of [Bou97℄.
Assuming that the set of X of let-bounded variables is
ontained into the set N of names, we dene a
translation [ ℄ : & ! (N ! ) as follows:
Translation of & into polyadi
[ x ℄ u = xu
[ x:m ℄ u = x(u)u(x; m; u)
[ [mi = & (y )Oi ℄i2I ℄ u = u(s; l; v )( [l = mi ℄[[ Oi ℄ v )
[ let x = O1 in O2 ℄ u = (x)([[ O2 ℄ u j!x(v )[[ O1 ℄ v )
[ x:m := & (y )O ℄ u = !u(s; l; v )([l = m℄[[ O ℄ v j [l 6= m℄x(s; l; v ))
The translation uses the (mis)mat
hing operators when dealing with method sele
tion/override. Combin-
ing this translation with the previous we get (yet another) translation of the & -
al
ulus into the polyadi
-
al
ulus whi
h is a \bit" simpler than the one proposed by [San96,HK96℄.
Translation of & into polyadi
[ x ℄ u = xu
[ O:m ℄ u = (x)(x (u)u(x; m; u) j!x(v )[[ O ℄ v )
[ O:m := & (y )O2 ℄ u = (x)(!u(s; l; v )([l = m℄[[ O2 ℄ v j [l 6= m℄x(s; l; v )) j!x(w)[[ O1 ℄ w)
This is already a result of this paper. Sin
e this is a \step-by-step" translation, the
hannel u is used to
output the \
ontinuation" of the
omputation, as in any (low level) operational semanti
s in
ontinuation
passing style. In Se
tion 3 we will see how translate the & -
al
ulus in a very dire
t way into the -
al
ulus.
Some intuitions of & . We explain how to build the deep blue
al
ulus out of the the &
al
ulus,
using the -
al
ulus as a guideline. We break a term let x1 = O1 in O2 into two parts: one is the de
larations
itself, written as hx = O1 i; and the other is the is the s
ope of the name x, whi
h is determined by a (x)
guard. As su
h, we write
let x = O in O2 is now written (x)(hx = O1 i j O2 ):
Here the symbol = in hx ( Oi means that the resour
e O is inexahustible. Counterwise, the symbol (
in hx ( Oi means that the resour
e O
an be used only on
e. To sum up the syntax of is:
3
i.e. the model of
omputation is the usual message-passing one.
(Ass) (P j Q) j R P j (Q j R)
(Migr) ( (x)P j Q) (x)(P j Q) x 62 fn(Q)
(Garb) (x)P P x 62 fn(P )
ev ev
(Stru
t) P P0 & P ! Q ) P0 ! Q
ev
(Congr) P P0 ) E[P ℄ ! E[P ℄
We dis
uss the most important rules, namely, (Sel () and (Over), sin
e the other rules are routine.
{ (Sel (). This rule apply when
1. the resour
e a
essible by name x is an obje
t [mi = & (y )Pi ℄i2I .
2. the resour
e is in parallel with a sending of message mj on name-
hannel x
3. mj is a method of [mi = & (y )Pi ℄i2I .
If so happen, then the redu
t is the pro
ess P obtained by substituting y with x in Pj , as in the & -
al
ulus.
4
{ (Over) This rule apply when
1. the resour
e a
essible by name x is an obje
t [mi = & (y )Pi ℄i2I .
2. the resour
e is in parallel with an override of method mj on name-
hannel x
3. mj is a method of [mi = & (y )Pi ℄i2I .
If so happen, then the redu
t is the resour
e D obtained by substituting the body for mj with & (s)P in
=
hx ( [mi = & (y )Pi ℄
i2I i. Operationally speaking, a pie
e of
ode is moved into the resour
e from outside,
modifying the resour
e itself.
3 En odings
O ::= x j [mi = & (x)Oi ℄i2I j x:m j x:m := & (y)O j (x)(hx1 = O1 i j : : : j hxn = On i j O):
We
an then translate the & -
al
ulus into the -
al
ulus as follows:
Translation of & into
[ x℄ = x
[ [mi = & (y )Oi ℄i2I ℄ = [mi = & (y )Oi ℄i2I
[ x:m ℄ = x:m
[ x:m := & (y )O2 ℄ = x:m := & (y )[[ O2 ℄
[ let x1 = O1 ; : : : ; xn = On in O ℄ = (x1 ; : : : ; xn )(hx1 = O1 i j : : : j hx1 = O1 i j [ O ℄ )
5
3.3 ( )
We want translate the asyn
hronous and polyadi
-
al
ulus. We assume that -
al
ulus names are also
names for . The syntax is the usual one, i.e.
We omit the redu tion and the ongruen e rules that are standard. Then the translation is as follows:
The en oding of the - al ulus is not diÆ ult and it is presented as follows:
3.5 ( )
The en oding of the - al ulus without obje t override is not diÆ ult and it is presented below:
6
Translation of without obje
t override into
[ x℄ = x
[ x:m ℄ = x m x
[ [mi = & (y )Pi ℄i2I ℄ = z:( i2I hmi = y:[ Pi ℄ i j z )
[ P j Q℄ = [ P ℄ j [ Q℄
[ (x)P ℄ = (x)[[ P ℄
= =
[ hx ( Oi ℄ = hx ( [ O ℄i
Worthy noti
ing is the translation of x:m; the dupli
ation of x in the translation is ne
essary in order to
perform the self-appli
ation semanti
s, i.e. the re
eiver must be applied to the body of the
alled method.
As a simple example,
onsider the evaluation of the following simple term:
ev
hx ( [id = & (s)s℄i j x:id ! x;
whi
h is translated and evaluated as follows:
ev
x ( y:(hid = s:si j y) j x id x !
h (y:(hid = s:si j y i)) id x
ev
! (hid = s:si j id) x
h id = s:si j id x
ev
! (s:s) x
ev
! x:
This means that by eliminating the obje
t override, we obtain that the blue
al
ulus is as expressive as the
deep blue one, i.e. = . If we want to add the obje
t override, instead, then the above en
oding is not
still valid.
4 Some Examples
4.1 A point resour
e, a
essible by x
We model a point whi
h may be moved along some dire
tion. The obje
t a
essible at name-address-lo
ation
x has therefore one eld and one method (althought the dieren
e between elds and methods is weak in
[AC96℄: pos, whi
h gives the a
tual position of the point, and move whi
h arranges the point in a given
position. Let
hx = O i;
7
with
4 [pos = & (s)n; move = & (s)(m)s:pos := & (s0 )([s:pos + m℄)i℄:
O=
Here n represent the name-
hannel-referen
e along the value of the eld pos is a
essed, and ([s + m℄) is a
meta-operation on names that adds the two values a
essible by the eld pos of O and the name m. Now
onsider the following evaluation:
ev 0
h x = Oi j x:move(p) ! hx = O i j x:pos := & (s )([x:pos + p℄)
ev 0
! hx = [pos = & (s)([x:pos + p℄); move = & (s)(m)s:pos := & (s )([s:pos + m℄)℄i:
Note that the invo
ation of the move method modies the resour
e but not the a
ess to the lo
ation itself,
i.e. the override is \imperative".
hx = Buff (n)i;
with
4 [state = & (s)n; put = & (s)(m)s:state := & (s0 )m; get = & (s)(m)m:ba
k(s:state)℄:
Buff (n) =
The buer has one private eld state
ontaining an a
ess to the value, and two methods, namely put and
get that perform, respe
tively a write and a read operation on the eld state. In parti
ular the get method
returns the value of the state eld throught the message ba
k along the name-
hannel-referen
e m. Now
onsider the following evaluation:
ev
hx = Buff (n)i j x:put(p) j x:get(q) ! hx = Buff (p)i j x:get(q )
ev
! hx = Buff (p)i j q:ba
k (x:state):
` P : :
The type rules are:
8
Rules for resour
es and
on
urren
y
` P : 1 ` Q : 2
(P ari ) (i 2 1; 2)
` P j Q : i
;x : ` O :
(Resour
e1 )
x ( Oi :
` h
;x : ` O :
(Resour
e2 )
` h x = Oi :
;x : ` P :
(P rivate)
(x)P :
`
` P : ` <:
(Subtype)
` P :
` x : [mk : k ℄
(Sele
t)
` x:mk : k
Obje
t Rule
; x : [mi : i ℄ i2I ` P i : i 8 i2I
(Obje
t)
` [mi = & (x)Pi ℄i2I : [mi : i ℄ i2I
In addition to those rules we have the usual rules for subtyping and for well formation of types and
ontexts (omitted).
Referen
es
[AC96℄ M. Abadi and L. Cardelli. A Theory of Obje
ts. Springer-Verlag, 1996.
[Bou97℄ G. Boudol. The -Cal
ulus in Dire
t Style. In Pro
. of POPL, 1997.
[HK96℄ H. Huttel and J. Kleist. Obje
ts as Mobile Pro
esses. Te
hni
al Report RR-96-38, BRICS, Basi
Resear
h
in Computer S
ien
e, 1996.
[Lau93℄ J. Laun
hbury. A Natural Semanti
s for Lazy Evaluation. In Pro
. of POPL, pages 144{154, 1993.
[Mil93℄ R. Milner. The Polyadi
-
al
ulus: a Tutorial. Logi
and Algebra of Spe
i
ation, pages 203{246, 1993.
Previously in Te
hni
al Report ECS-LFCS-91-180, Edimburgh University, 1991.
[San96℄ D. Sangiorgi. An Interpretation of Typed Obje
ts into Typed -
al
ulus. Te
hni
al Report Report RR-3000,
INRIA, Sophia Antipolis, 1996.