You are on page 1of 9

The Deep Blue Cal

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.

1.1 Syntax of the Obje t Cal ulus with names

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.

1.2 Translation of & into & 

The pro ess of translation of the & - al ulus into the &  - al ulus is spe i ed 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 de ned as follows:
Translation fun tion  of & into & 
x = x
([mi = & (x)Oi ℄i2I ) = [mi = & (x)Oi ℄i2I

(O:m) = let x = O in x:m

(O1 :m := & (y )O2 ) = let x = O1 in x:m := & (y )O2

1.3 Dynami Semanti s


The Dynami semanti s is inspired to [Lau93℄. In order to express a big-step semanti s, we need to introdu e
a stru ture, alled Heap. A heap is a partial fun tion from variables to obje ts. It may be viewed as an
(unordered) set of variable/obje t expression pairs, binding distin t variable name to obje t expression. The
obey to the following grammar:
::= ; j ; x 7! O:
The judgment we wishes to derive has the following form:

` 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

The following result an be proved.

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 de ne 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:

P ::= hx ( [mi = & (x)Pi ℄i2I i j hx = [mi = & (x)Pi ℄i2I i j


(P j P ) j  (x)P j x:m j x:m := & (y )P j x:
The redu tion rule is peformed when a resour e hx ( Oi is in parallel with a message send x:m and
when the body & (y )P of m belongs to the interfa e of O, i.e.
ev
hx ( Oi j x:m ! P fx=yg;

3
i.e. the model of omputation is the usual message-passing one.

2 The Deep Blue Cal ulus


2.1 The Syntax and the Operational Semanti s
We assume given a denumerable set N of names, ranged over x; y; z . We sometimes use also s when we have
in mind, so alled, self-variable, and a; b; ; : : : when we have in mind variables rather than names, thought
there is no formal distin tion here. The untyped syntax of the deep blue al ulus (from now on denoted by
 ) is given by the following grammar (distinguished only for onvenien e into three synta ti ategories):

P ::= (P j P ) j  (x)P j D j x:m j x:m := & (x)P j x j O


O ::= [mi = & (x)Pi ℄i2I
D ::= hx ( Oi j hx = Oi:
The form P represents pro esses, the form O represents general obje ts, and the form D represents \re-
sour es". A resour e hx ( Oi has the following meaning: the obje t O is a essible only via the name-
hannel-referen e x. The operational semanti s of the   - al ulus is given throught a term rewriting system
=
+ some ongruen e rules presented below. Let ( denotes both ( and = .
Congruen e rules
(Comm) P j Q QjP 

(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 )

Redu tion rules


Ctx E ::= [ ℄ j  (x)E j (E j P ) j (P j E) j E:m j E:m := & (y)O
ev
(Sel () hx ( [mi = & (y )Pi ℄i2I i j x:mj ! Pj fx=yg (j 2 I )
ev
(Sel = ) hx = [mi = & (y )Pi ℄i2I i j x:mj ! h x = [mi = & (y)Pi ℄i2I i j Pj fx=yg (j 2 I )
ev
(Over) hx ( [mi = & (y)Pi ℄i2I i j x:mj := & (y)P
=
! h x ( [mi = & (y)Pi ; mj = & (y)P ℄i2I nfjg i (j 2 I )
=

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

3.1 (&    )


As we sayed in the introdu tion, we laimed that the   - al ulus ontains the & - al ulus. To prove this,
observe that terms of the & - al ulus an be regarded as elements of a subset of   , given by the grammar:

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 ℄ )

3.2 (&  )


Combining the above translation with  we an now see that & - al ulus is a sub- al ulus of   .
Translation of & into 
[ x℄ = x
[ [mi = & (y )Oi ℄i2I ℄ = [mi = & (y )Oi ℄i2I
[ O:m ℄ =  (x)(hx = [ O ℄ i j x:m)
[ O1 :m := & (y )O2 ℄ =  (x)(hx = [ O1 ℄ i j x:m := & (y )[[ O2 ℄ ) x fresh

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.

P ::= xye j x(ye)P j!x(ye)P j (P j P ) j  (x)P:

We omit the redu tion and the ongruen e rules that are standard. Then the translation is as follows:

Translation of  into 


[ xye ℄ = x:msg (ye)
[ x(ye)P ℄ = hx ( [msg = & (s)(ye)[[ P ℄ i
[ !x(ye)P ℄ = hx = [msg = & (s)(ye)[[ P ℄ i
[ P j Q℄ = [ P ℄ j [ Q℄
[  (x)P ℄ =  (x)[[ P ℄

3.4 (   )

The en oding of the   - al ulus is not diÆ ult and it is presented as follows:

Translation of  into 


[ x℄ = x
[ x:P ℄ = [arg = & (y )y:arg; val = & (y )[[ P ℄ x:arg=x℄)
[ P x ℄ = [ P ℄x
[ P j Q℄ = [ P ℄ j [ Q℄
[  (x)P ℄ =  (x)[[ P ℄
= =
[ hx ( P i ℄ = hx ( [ P ℄i

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.

3.6 CPS transforms of  into 


The te hniques of ontinuations is widely used in the semanti s of fun tional programming languages and
ontrol operators. In parti ular, we are interested into ontinuation passing style tranformations, that maps
programs written in one language into another, providing also an evaluation strategy.
[Gigi: Cosimo, i sto lavorando sopra...℄

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 di eren 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 modi es the resour e but not the a ess to the lo ation itself,
i.e. the override is \imperative".

4.2 A \non-lo ked" bu er resour e, a essible by x


We (impli itly) assume that the state eld is private i.e. not a essible from the outside. Let

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 bu er 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):

That is the omputation is nondeterministi .

5 A Type System for the Deep Blue Cal ulus

The type system S for   is presented as follows:


The types we use are:

;  ::= [mi : i ℄ i2I


The judgments we wishes to derive in S have the following shape:

` 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

` x: `  <: [mi : i ℄


i2I ; y : [mi : i ℄ i2I ` P : k
(Override)
` x:mk := & (y)P : 

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.

You might also like