without constants) call-by-value -calculus, defined by Plotkin as a restriction ..... Condition app exploits the binary operation over S for modeling the ap- plication.
The call-by-value -calculus: a semantic investigation A. Pravato
S. Ronchi della Rocca
L. Roversi
July31; 1996
Abstract In this work we present a categorical approach for modeling the pure (i.e., without constants) call-by-value -calculus, defined by Plotkin as a restriction of the classical one. In particular, we study the properties a category must enjoy for give rise to a model of such a language. This definition is enough general for grasping models in different settings.
1 Introduction The call-by-value -calculus is a restriction of the classical -calculus ( -calculus, for short), based on the notion of value. A value is a term which is either a variable or an abstraction. In particular, the call-by-value -calculus is obtained from the classical one by restricting the evaluation rule (the -rule) to redexes whose operand is a value. This leads to a call-by-value parameter passing mechanism, which is a feature present in many real programming languages, where an evaluation is callby-value if it evaluates parameters before they have been passed. This feature, together with the lazy evaluation, where an evaluation is lazy if it evaluates function bodies only when parameters are supplied, were both implemented in the SECD machine, defined by Landin [11] for computing -terms. The call-by-value -calculus was introduced by Plotkin [14] in order to define a paradigmatic language for modeling the behaviour of this machine. Here we will deal with the semantics of the “pure” (i.e., without constants) callby-value -calculus ( v -calculus, for short).
Addr.: Universit`a degli studi di Torino, Dipartimento di Informatica, C.so Svizzera 185 - 10149 TORINO. E-mail: fpravato; ronchi; roverg di:unito:it
@
1
As far as the denotational semantics of the v -calculus is concerned, a general definition of a model for this language was given in [4], following the HindleyLongo approach for defining a model for -calculus [6]. I.e., a model is defined as an applicative structure with an interpretation function that maps terms (in a given environment) to elements of the model, and that must satisfy some constraints. The main difference between the original definition of Hindley-Longo and this one, is that there must exist a proper subset of the carrier of the applicative structure, the set V of semantic values, where all values must be interpreted. Such a definition, while clear and intuitive, does not help in order to effectively build models of the language, since it does not characterize the properties a structure must enjoy in order the constraints on the interpretation function are satisfied. The aim of this paper is to give a categorical characterization of a model for the v -calculus, and to use it for building models in different mathematical settings. Recall that the models of -calculus have a very nice categorical characterization: they are the reflexive objects of a cartesian closed category with enough points, where an object A is reflexive if, and only if, A A is a retract of it (notation: A . A A), while the condition of having enough points is a suitable notion of “concreteness” for categories. A categorical characterization of models for the v -calculus cannot be obtained by modifying or restricting the previous one. A counterexample is the model defined in [4], built in the category of Scott domains and strict continuous functions. Namely, the model arising from the initial solu[D ? D]?, where [D ? D]? denotes the tion of the domain equation: D lifted space of strict continuous functions. Indeed, the category of Scott domains and strict continuous functions is not cartesian closed. We give a categorical characterization of models for the v -calculus starting from logical considerations. The logical intuition we follow is that, while the calculus is related to the intuitionistic logic, through the Curry-Howard isomorphism extended to the untyped case (with reflexive types), the v -calculus is related to the linear intuitionistic logic, where the modality characterizes the values. It turns out that a suitable class of categories for interpreting the v -calculus is a restriction of the one defined in [2] for interpreting the multiplicative and exponential fragment of intuitionistic linear logic, equipped with a suitable retraction, and “having enough ), where is the object representing the values”. The retraction is . T ( domain of interpretation, T is a suitable functor and represents the internalization of the morphisms in a monoidal closed category. The notion of “having enough values” is the natural restriction to v -calculus of the notion of “having enough points.” The meaning of this notion is that morphisms are different if and only if there is at least a value where they show a different behaviour. This class of categories is general enough for grasping models built in very different settings. Indeed, we prove that every Scott domain solution of the equation
!
!
D
!
D ? D
!
D
?
D
2
D [D !? D]? or coherence domain D solution of the equation D !(D ? D), induces a categorical model of the v -calculus. The fact that the coherence space solution of D !(D ? D ) is a model for the v -calculus was first stated by Girard. However this domain is also a model for -calculus, and it was the leading idea of [5] for building an optimal reduction machine for -reduction, translating -calculus into a variation of proof-nets. By the way, in this paper we prove (see Remark 6.3) that, despite the intuition, to be a model for the -calculus does not imply to be a model for the v -calculus too.
The characterization we give is not complete with respect to all the models for the v -calculus. Indeed, it is based on the choice of modeling the v -calculus in a “total” setting. From a set-theoretic point of view, this corresponds to model the set of the semantic values V by (a suitable set) of total functions from D to D , where D is the whole interpretation domain. All the models cited above belong to this class. In a “partial” approach V would be modeled by functions from V to D , where V is a proper subset of D . I.e., in this latter case the space of semantic values V D. An example of a partial model is the is the solution of the equation V term model. All the total models we know are instances of our category. So we conjecture that our characterization is complete for total models. It is easy, but tedious, to show that every partial model we know from the literature can be easily extended to a total one turning out to be instances of our category. The paper is organized as follows: in Section 2 the v -calculus and its notion of model is defined. Section 3 is devoted to introduce some categorical concept useful in the remaining section. In Section 4, starting from logical argumentation, the categorical structure needed for modeling the v -calculus is defined. This categorical structure is used in Section 5 and in Section 6 to define a categorical model for the v -calculus. In Section 7 problems involving the extensionality are treated, while in Section 8 two instances of the categorical model are introduced. An earlier, partial version of this paper was in [15]. In the paper we will assume a basic knowledge about category theory, Scott Domains and Coherence Spaces.
?
2 Modeling the call-by-value -calculus The call-by-value lambda calculus, or v -calculus, is a restriction of the classical one, based on the concept of value. In particular, the restriction concerns the evaluation rule, namely the -rule, which is replaced by the v -rule.
3
Definition 2.1 Let Var be a denumerable set of variables, ranged over by x; y; z . Let be the set of pure untyped -terms M built out from the following grammar:
M ::= x j (MM ) j (x:M ) We use M; N; P; Q for denoting terms. Terms of the form (MN ) are called application while that of the form (x:M ) are called abstraction. The set of syntactic values, or simply values, is the set Val defined as:
Val = Var [ f(x:M ) j x 2 Var
and
M 2 g:
The call-by-value evaluation rule is the following reduction rule:
( v ) (x:M )N
!v [N=x]M
if N
2 Val
where [N=x]M denotes the substitution of N for every free occurences of x in M , renaming bound variables in M to avoid variable clash. The reflexive, symmetric, transitive and contextual closure of v , together with the possibility of renaming bound variables, lead an equivalence theory on terms of . Formally, the formal theory v is a set of rules for deriving formulas of the following shape:
!
M =v N
where both M and N belong to . The rules are:
M =v M ()
M =v N () N =v M
y 62 FV (M ) () (x:M ) =v (y:[y=x]M ) N =v P () (MN ) =v (MP )
M =v N N =v P ( ) M =v P
N 2 Val ( ) ((x:M )N ) =v [N=x]M v
M =v N ( ) (MP ) =v (NP )
FV
M =v N ( ) (x:M ) =v (x:N )
where (M ) is the set of the free variables of M . Two terms M and N will be said v -equal if the formula derivable in the above system, writing:
M =v N will be
v ` M =v N: Definition 2.2 A term M
2 is valuable iff there exists N 2 Val such that: v ` M =v N: 4
Notice that, if we take Val to be , then the v -reduction rule becomes the classical -reduction rule, hence the theory v becomes the usual theory . That is, the classical lambda calculus can be viewed as a call-by-value lambda calculus which values are all the terms. A model for the v -calculus will be a structure in which a term M is interpreted. This interpretation must satisfy two constraints. The first one is that two v -equal terms should have the same interpretation. The second one is that it must be contextual closed, namely, if two terms M and N have the same interpretation, then for every context C [ ], C [M ] and C [N ] must have the same interpretation. A general definition of a model for the v -calculus, following the HindleyLongo approach for defining a lambda calculus model [6], has been given in [4]. We recall here that definition in a slightly different form, more suitable for our aims.
2
S , and call V the Definition 2.3 Let S and V be two non empty sets such that V set of semantic values. Let Env be the set of environments, where an environment V , where = dom() is a finite subset of Var. is a map :
X!
X
M
h
Ii
i) A pseudo-v -structure is an applicative structure = S; V; ; , where : S S S and : Env S is such that is defined only for terms with free variables in dom( ), and satisfies the following conditions:
!
I
! !
I
I [x] = (x), (abs) I [x:M ] 2 V , (app) I [M N ] = I [M ] I [N ], (eval) I [x:M ] d = I xd [M ], for every d 2 V , (ceq) if 8x 2 FV (M ): (x) = 0 (x) then I [M ] = I 0[M ], () if y 62 FV (M ) then I [x:M ] = I [y:[y=x]M ], where xd behaves as on every y 6 x, while (x) = d. ii) A v -model is a pseudo-v -structure such that I satisfies also: ( ) if 8d 2 V: I xd [M ] = I xd [N ] then I [x:M ] = I [x:N ]. iii) Let M; N 2 . An environment is compatible both with M and N iff FV (M ) [ FV (N ) dom(). Let M = hS; V; ; Ii be a v -model. The formula M =v N is valid in M, writing M j= M =v N; iff for every compatible both with M and N , I [M ] = I [N ]. (var)
5
Some remarks are in order about the previous definition. The subset V of S provides a semantic account of the syntactic values. So environments map variables to V since variables are values. Moreover, since every abstraction is a value too, we need abs. Condition app exploits the binary operation over S for modeling the application. Condition eval is necessary for modeling the substitution mechanism of values for variables. Context equality (ceq) states an obviousness: the interpretation of a term depends only on its free variables. Condition is the semantic counter part of the -conversion.
I
Remark 2.4 The conditions on given in Definition 2.3 i) do not give a definition of the interpretation function by standard induction, because of condition (abs). So, condition ( ) is necessary in order to this interpretation should be contextual closed.
I
3 Categorical tools In this section we recall some definitions we need for building a categorical v model. In the next section we shall give a detailed description of the intuition behind the choices we are going to make. A symmetric monoidal category is a category C with a bifunctor : C C C, an object II and natural isomorphisms, for each A; B; C ObjC ,
2
!
A;B;C : A (B C ) ! (A B ) C A : II A ! A A : A II ! A
A;B : A B ! B A
for making an associative and symmetric bifunctor with left and right identity II, and such that
(A B);C;D A;B;(C D) = (A;B;C idB ) ?A;1(B C );D (idA B;C;D ) (A idC ) A;II;C = idA C II = II
A;B B;A = idB A B = B B;II C;A;B (A B);C A;B;C = ( A;C idB ) A;C;B (idA B;C ) in order the coherence theorem holds (see [8]), namely: in a monoidal symmetric category, any two isomorphisms built out of , , , id and A;B with A B , using and composition, coincide. C is monoidal Given a monoidal symmetric category C, an endofunctor T : C : if, for each A; B ObjC , there are a natural transformation mA;B : TA TB T (A B ) and a map mII : II T II such that they commute together with T , , , , . Namely, the following diagrams commute:
6
2
!
!
6
!
T II TA mII idTA II
6
TA
-T
mII;A
(II
A)
idTA mII
TA
TA
- TA?
- T A
mA;II
TA T II
6
(
II)
TA
TA II
TA
- TA?
m idTC m TA TB) TC A;B T (A B) TC A B;C- T ((A B) C )
(
6
6
TA;TB;TC
TA;B;C
id m - TA T (B C ) mA;B C- T (A (B C )) TA (TB TC ) TA B;C
The monoidal functor T is also monoidal symmetric if:
TA TB
TA;TB
- T A B
mA;B
(
)
T ( A;B )
?
?
TB TA mB A- T (B A) A monoidal (symmetric) natural transformation is a natural transformation be: T , such that its instantiations tween two monoidal (symmetric) functors, : T1 2 commute together with , the two functors T1 , T2 and their mA;B and mII . Namely, the following diagrams commute: T1 ) m(A;B m(IIT1 )
!
T1 A T1 B
A B
?
T2 A T2 B
- T1 A B (
)
II
(A B)
- T2 A ? B
T mA;B
( 2)
(
QQ
- T1
II
QQ QQs ?
II
m(IIT2 )
T2 II
)
A monoidal symmetric category C is also closed if there is a bifunctor C C, such that, for every object B , there exists an isomorphism
!
?: C
A;B;C : HomC ((A B ); C )) ! HomC (A; (B ? C ))
2
which is natural in A and C , namely: for all A; B; C ObjC there exists the evalC ) B C such that, for all morphisms uation morphism evB;C : (B
?
7
!
f : (A B ) ! C , h : A ! (B ? C ) and g : (B ? C ) B ! C , there A;B;C (f ) : A ! (B ? C ) such that the following diagrams
exists a unique commute:
(f ) idB
-C 3 evB;C f
A B
?
B ? C ) B
(
- B ? C 3 h ? (g) (g(h idB ))
A
(
)
B ? C )
(
?
This implies that, given two objects A and B , the object (A B ) is an internalisation of HomC (A; B ). Furthermore, the identity object II play a rˆole similar to that of the terminal object in a cartesian closed category, because it can be shown A). Let notice that it is easy that every object A is isomorphic to the object (II to verify that by naturality derives:
?
A;B;C (evB;C (h idB )) = h: Given a monoidal category C, a comonoid in C is a triple (A; d; e) where A is an object of C and d : A (A A), e : A II are such that the following diagrams commute:
!
A A idA d
?
A (A A)
d
d
A
!
- A A
A
d idA
-
? @ ? d @ ?A @@ ? ? ? ? -@R ?A1
?
A A) A
1
A e idA A A idA e A II If C is also symmetric, then a comonoid (A; d; e) is a commutative comonoid if d commutes with , namely: A;A d = d. A;A;A
(
II
Given a category C (not necessarily monoidal), a comonad over C is a triple (T; ; ), where T : C C is an endofunctor, and : T : T 2 and : T : IDC are natural transformations, such that the following diagrams commute:
!
T3 T
6
T2
!
T
T2
T
6
T
!
T T 2 T - T @I@ 6 ?? ? idT @ @ ? idT T
!
Given an endofunctor T : C C, the category of T -algebras is defined having T -algebras (A; A ) as objects, where A is an object of C and A : TA A, and
!
8
as morphisms those arrows h : A
! A0 such that: TA
A
?
A
- TA0
Th
A0
h
- A?0
The set of such morphisms h is denoted by T -algC ((A; A ); (A0 ; A0 )). Let notice that every comonad (T; ; ), since the naturality of , gives us a category of T algebras with object (A; A ). The category of T -coalgebras has T -coalgebras as objects, namely, pairs (A; A ) where A : A TA, and morphisms h T -coalgC ((A; A ); (A0 ; A0 )) such that:
!
2
A A
h
- A0
A0
? - ?0 Th TA
TA
4 The Cbv category In this section we will define a class of categories which will be proved suitable for modeling the call-by-value lambda calculus. Following Scott [16], an untyped lambda calculus can be considered as the limit case of a typed one. So, we first consider a full typed version of the v -calculus, and we define a category for interpreting it. As second step we extend such a category in order to capture the meaning of all the untyped language. To this aim, we will follow a logical approach, i.e. we will interpret a term M with (M ) = x1 ;: : :; xn , by a judgement x1 : A1 ; : : : ; xn : An M : A proved in a suitable type assignment system. Such a judgement, in the categorical setting, represents a morphism from the object A1 An to the object A, where also the Ai ’s are objects and is a particular bifunctor. Hence, the first step of the whole construction is to take a suitable logic for building the typed version of the v -calculus. It is well known that, for the usual lambda calculus, this rˆole is played by the intuitionistic logic. Indeed, terms of simply typed lambda calculus can be viewed as proofs in the minimal intuitionistic logic in natural deduction formulation. The class of models of lambda calculus are cartesian closed categories (which are models for this logic), extended with a reflexive object in order to model the whole untyped language. In the typed setting, the -equality is modeled by the substitution property of derivations.
FV
f
g
`
9
?1 ; A; B; ?2 ` C (exc) ?1 ; B; A; ?2 ` C
A`A ?; A ` B ?1 ` A ? B ?2 ` A (? I ) (? E ) ? ` A ? B ?1 ; ?2 ` B ?; TA; TA ` B ?`B (c) (w) ?; TA ` B ?; TA ` B ? ` TA T ? ` A (TI ) (TE ) ?`A T ? ` TA Contexts ? are sequences of formulas. T is a modal operator and T ? denotes a (Id)
context where all formulas are modal. Figure 1: The logic of call-by-value types. Since the v -equality is a restriction of the -equality, we must look for a logic where the substitution property holds only partially. Let us consider the fragment of the multiplicative intuitionistic linear logic in natural deduction formulation as given in Figure 1, where we use for the modality the notation T instead of ! for sake of generality. It is well known that, for such a system, a substitution property restricted to modal formulas holds, namely: Property 4.1 If ?1 ; TA; ?2
` B and T ? ` TA, then ? ; T ?; ? ` B . 1
2
2
Let now define a typed term calculus, T , where terms are proofs of the given logic, but the rule (TI ) is restricted to arrow-types. The definition is in Figure 2. In this new type assignment system, the substitution property is: Property 4.2 If ?1 ; x
[N=x]M : B .
: TA; ?2
` M : B and T ? ` N : TA, then ? ; T ?; ? ` 1
2
2
Such a property allow to define a normalizing procedure of derivations, corrisponding to the v -rule on T . Indeed, a derivation with shape:
D .. .
1
?1 ; x : TA ` M : B ?1 ` x : TA:M : TA ? B (? I )
D
2
T ? ` N : TA
?1 ; T ? ` (x : TA:M )N : B 10
.. .
? E )
(
?1 ; x : A; y : B; ?2 ` M : C (exc) ?1 ; y : B; x : A; ?2 ` M : C
x:A`x:A ?; x : A ` M : B ?1 ` M : A ? B ?2 ` N : A (? I ) (? E ) ? ` x : A:M : A ? B ?1 ; ?2 ` MN : B ?; x : TA; y : TA ` M : B ?`M :B (c) (w) ?; z : TA ` [z=x; z=y]M : B ?; x : TA ` M : B ? ` M : TA T ? ` M : A ? B (TI ) (TE ) ? ` M : A T ? ` TM : T (A ? B ) (Id)
Figure 2: The typed call-by-value lambda calculus T
`
D
D
by replacing every axiom x : TA x : TA in 1 by a copy of 2 , once extended contexts in the obvious way, can be reduced to a derivation proving:
?1 ; T ? ` [N=x]M : B: But, let us consider the following derivation, where B is of the form B1
? B : 2
D .. .
.
.
.
.
.. .. .. .. T ?; x : TA ` M : B (TI ) x : C ? TA ` x : C ? TA y : C ` y : C (? E ) T ?; x : TA ` TM : TB ( ? I ) T ? ` x : TA:TM : TA ? TB x : C ? TA; y : C ` xy : TA (? E ) T ?; x : C ? TA; y : C ` (x : TA:TM )(xy) : TB In this case, if every occurences of the axiom x : TA ` x : TA in D were replaced by the derivation proving x : C ? TA; y : C ` xy : TA, the resulting derivation would be not legal, since the rule (TI ). Hence, this typed system does not model the -rule, but a proper restriction of it. From the above discussion, we can say that T is a call-by-value calculus, in the sense that modal types (i.e. types of the shape TA for some A) are value-types, and we say that a term is valuable iff it can be assigned a value-type in a context where all the variables have value-types. Notice that, since T is a strongly normalizing typed language (w.r.t. the v -reduction rule), valuable term have not a syntactical characterization. The restriction of the rule (TI ) to arrow-types takes into account that in the v -calculus all the abstractions are values. From the typed point of view, this can 11
be reflected by the fact that every term of T having an arrow-type (that is, a functional behaviour), if built out from variables which are values (hence, typed with modal types), is a value. Consequently, it can be “promoted” to be typed by a valuetype. Moreover, in restricting this rule we made an important choice. We consider as value every term typed by an arrow type. An alternative choice would be to conB , i.e., every term sider values just the terms having a type of the shape TA having the behaviour of a function from values of type A to objects of type B . This last choice would correspond to model the call-by-value using partial functions. We chosed a “total” approach, by the reason that it seems more general. Indeed, a partial function can always be simulated by a total one, if its domain and codomain are equipped by one (or more) element playing the roˆ le of the “undefined element.” An easy example is the set of strict functions from a cpo D to a cpo D 0 , which is isomorphic to the space of partial function from D D to D0 D0 . For interpreting the language T we know, from [10] and [2], that we need a category C with the following features:
?
n f? g
n f? g
it must be closed monoidal symmetric w.r.t. a tensor product , in order to interpret contexts as tensor product and correctly interpret rules (Id), ( I ), ( E ) and (exc),
?
?
it must have a comonad (T; ; ), for interpreting rules ( TI ) and (TE ), it must have a commutative comonoid (TA; DupA ; EA ) for every object A, in order to interpret rules ( w) and (c). Moreover, every EA of the comonoids must be an element of T -coalgC ((TA; A ); (II; mII )), in order to deal with some commuting conversion.
Notice that we need less conditions on T -coalg than [2], since we deal with a subsystem of the multiplicative intuitionistic linear logic. Now we want to extend such a category in order to interpret all the untyped language. This amount to extend the typed system in such a way that, for every term M there is at least one term M 0 of T , such that M is obtained from M 0 by erasing every type information. Mimicing the construction given for the classical lambda calculus, this can be achieved by restricting the syntax of types to a single basic constant, say D , and by adding two coercion functions relating D to a suitable function space. Since we choose a “total” approach, the considered function space must be D D. So, in the terminology of Definition 2.3, D plays the rˆole of the interpretation set S , while D D plays the rˆole of the value set V . Since the D) plays the rˆole of the subset of elements of definition of the modality T , T (D S belonging to V . Then the condition V S gives rise to the following retraction condition:
2
?
? ?
D . T (D ? D); 12
D is the object representing the type D. Indeed, since T forms the comonad ? D), the value space D ? D .
where
(T; ; ), makes possible to reach, from the “subspace” T (D
Summarizing, the categorical structure we need for interpreting the v -calculus is given by the following definition: Definition 4.3 A call-by-value category Cbv is a category such that:
Cbv is a closed monoidal symmetric category w.r.t.
.
In Cbv there is a comonad (T; ; ) such that: - the endofunctor T is a monoidal symmetric functor and the natural transformation and are monoidal natural transformations, through mII and mA;B for every A; B , - if KII is the constant II functor on the category Cbv, then there exist : K and Dup : T : T T such that, natural transformations E : T II for all A ObjCbv , (TA; DupA ; EA ) is a commutative comonoid, and EA is an element of T -coalgCbv((TA; A ); (II; mII )).
!
2
D D!
!
T (D ? D) is a retract of D, D . D ? D) and G : T (D ? D) ! D,
In Cbv there is an object such that T( T( ), under F : namely, F G = idT (D?D) .
D ? D We call D the model object of Cbv, and we denote by V the object (D ? D ).
In Appendix A there are the commuting diagrams for the particular monoidal natural transformations above. In the next section we will prove that every such a category leads to a pseudov -structure. Remark 4.4 A particular choice of the monoidal functor T of Definition 4.3 is the identity functor. In this case every object of the category induces a commutative comonoid and it is easy to check that the category becomes cartesian closed with a .( ). Hence, we have a pseudo-structure, or a combinatory retraction algebra, for the classical lambda calculus. This is not surprising since every formulas provable in the theory v is also provable in the theory . This implies that a -model is a particular case of a v -model. This is the semantic counterpart of the fact that, syntactically, the classical lambda calculus can be viewed as a callby-value lambda calculus where all the terms are values.
D
D ? D
13
5 The categorical pseudo-v -structure In this section we will prove that every Cbv category induces a pseudo-v -structure. First, let us introduce some useful notation. In the sequel we will deal simply with “the category”, instead of “one category belonging to the class Cbv”.
Let A1 ; : : : ; An be either morphisms or objects of the category. Notation 5.1 Since the associativity of and the coherence theorem cited in Section 3, A1 An can be used as an abbreviation for A1 (A2 (An?1 An and so on (modulo isoAn ) ) or else for ( (A1 A2 ) A3 ) morphisms).
Let A be either a morphism or an object of the category. By An we denote A, n times, where A0 = II if A is an object, the tensor product A 0 otherwise A = idII if A is a morphism.
2
For all A1 ; : : : ; An ObjCbv, let mA1 ;:::;An , n > 2, be the generalization of mA;B inductively defined as mA1 ;:::;An = mA1 ;A2 An (idTA1 mA2 ;:::;An ), implicitly exploiting the associativity of . We define: mnA : (TA)n T (An ) as
!
and mn
m0A = mII m1A = idTA mnA = mA;:::;A
for n > 1.
: (IIn ) ! T (IIn ) as: m0 = m1 = mII mn = mnII mnII for n > 1.
We now introduce some morphisms useful for defining the interpretation of a term in a concise way. Let notice that for interpreting the terms of the v -calculus we must be able to duplicate environments and to project arguments. In the next definition, the structure of the comonoids in Cbv helps us in the definition of projections and duplications. For all A1 ; : : : ; An ObjCbv and for every permutation of the sequence A
An 1 1; : : : ; n, we call ExcA(1)
An A(n) the natural isomorphism between A1 and A(1) A(n) . The isomorphism is defined using the isomorphism for the symmetricity of Cbv.
2
2
Definition 5.2 Let A1 ; : : : ; An ObjCbv . TAn . We define duplication A : A Duplications: Let A = TA1 as 0 DupAn ); ExcA A A (DupA1
14
!A A
where A0 = TA1 TA1 1 = ?II 1 . defined as II = ? II Projections: For every 1 i TAn TAi as
TAn TAn. In particular,
II
: II ! II II is
n, we define the projection Ai 1 An : TA
!
1
(EA1 EAi?1 idAi EAi+1 EAn ); where iso stands for the natural isomorphism between II II Ai II II iso
and Ai built out of and .
We now define the interpretation of terms of the v -calculus in Cbv with a model object . We follow [1] and [9], therefore, we will interpret a term M , with free variables x1 ; : : : ; xn , as a morphism from n to .
D f
g
D D Definition 5.3 Let M 2 such that FV (M ) fx ; : : : ; xn g. Let C (D ) be a Cbv category with D as model object. The interpretation function [ :] C D such that [ x ; : : : ; xn ` M ] C D 2 Hom(Dn ; D) is defined by induction on M as follows (remember that V denotes (D ? D )): 1
(
1
(
)
)
[ x1 ; : : : ; xn ` xi ] C (D) = G Vi n F n ; (1) C (D ) [ x1 ; : : : ; xn ` MN ] = (2) C (D ) C (D ) evD;D ((V F [ x1 ; : : : ; xn ` M ] ) [ x1 ; : : : ; xn ` N ] ) rn ; (3) [ x1 ; : : : ; xn ` x:M ] C (D) = C (D ) n G T (Dn ;D;D ([[x1 ; : : : ; xn; x ` M ] ) G ) sn; where
rn =(Gn Gn) (T V )n F n; sn = mn T V Vn F n :
Clause 1 defines a projection of the i-th variable in the sequence x1 ;: : :; xn . The interpretation of MN , defined through clause 2, is given in an almost usual way. It exploits the monoidal closure, namely, evD;D is used for applying the interpretation of M to the one of N . In particular, V extracts the functional behaviour of the interpretation of M . Moreover, r duplicates the environment so that it can be fed to both the interpretation of M and N . Clause 3 interprets x:M using the monoidal functor of the comonad T . In this way, the morphism interpreting an abstraction can be both erased and duplicated. Morphism sn merely serves for rightly composing the interpretation.
15
` M ] C D D ) : II !
D D 3 [ x ` M ] D D .
Remark 5.4 Let notice that, for n = 0, we take II;D;D ([[x , since [ x M ] C (D) Hom( ; ) Hom(II ; )
`
V
2
DD
(
)
The following two technical lemmas will be useful in the sequel. Their proofs can be found in Appendix B.
FV
f
g
Lemma 5.5 Let M be a term such that (M ) x1 ;: : :; xn . Let 1 and xn+1 (M ). The following equations hold: (exchange) [ x1 ; : : : ; xi ; xi+1 ; : : : ; xn M ] C (D) =
62 FV
i n?1
`
= [ x1 ; : : : ; xi+1 ; xi ; : : : ; xn ` M ] C (D) (idiD?1 D;D idDn?i?1 ): (weakening) [ x1 ; : : : ; xn ; xn+1 ` M ] C (D) = = [ x1 ; : : : ; xn ` M ] C (D) Dn (idnD (EV F )): Lemma 5.6 Let rn be as in Definition 5.3. The interpretation of the application of a lambda-abstraction to a term has the forms: for n > 0: [ x1 ; : : : ; xn (x:M )N ] C (D) =
`
= [ x1 ; : : : ; xn ; x ` M ] C (D) (idnD [ x1 ; : : : ; xn ` N ] C (D) ) rn ; for n = 0: [ ` (x:M )N ] C (D) = [ x ` M ] C (D) [ ` N ] C (D) :
Now we define the notions which corresponds, in the categorical setting, to that one given in Definition 2.3.
D CD
Definition 5.7 Let ( ) denoting a Cbv category with a model object fine C (D) = S C (D) ; V C (D) ; C (D) ; C (D) , where:
M
-
E
I
D. Let de-
S C(D) = Hom(II; D) (Notice that Hom(II; D) Hom(IIn ; D) for all n
1.) - V C (D) = ff j f 2 Hom(II; D ) and 9h 2 Hom(II; V ):f = G Th mII g, - f C (D) g = evD;D ((V F f ) g ), for every pair of morphisms f; g 2 Hom(II; D ), - I C (D) [M ] = [ x1 ; : : : ; xn ` M ] C (D) ( (x1 ) (xn )), where FV (M ) dom( ) = fx1 ; : : : ; xn g. We call every (xi ) environment component. Since maps variables to values, every environment component (xi) is of the form
G Thi mII for some hi .
As consequence of the definition of the set of semantic values V , an interpretation [ x1 ; : : : ; xn M ] C (D) is a value iff C (D) [M ] = G Th mn for . each and for some h : IIn
`
I
? V
We are now able to prove that every Cbv category induces a pseudo-v -structure. 16
C (D) be a Cbv category. MC D is a pseudo-v -structure. Proof. We shall prove that MC D satisfies the first part of Definition 2.3. We skip the index C (D ) for sake of clarity. To prove condition var we use the definition of (
Theorem 5.8 Let
(
)
)
and both the naturality and the monoidality of E . Condition app comes from the
definition of essentially using the naturality and the monoidality of Dup. Condition eval is proved as follows. Let (x:M ) = x1 ; : : : ; xn , and denote every (xi) (i = 1; : : : ; n) by i . Let also d V . Step by step, we have that:
FV 2
f
g
I [x:M ] d = = ev (( F [ x ; : : : ; xn ` x:M ] C D ( n )) d) (
1
)
1
(by Diagram 4 in the proof of Lemma 5.6
) ` n)) d) C D = ev (Dn ;D;D ([[x ;: : :; xn ; x ` M ] ) id) (( n) d) = [ x ; : : : ; xn ; x ` M ] C D ( n d) = I xd [M ]:
and exploiting the fact that i ’s have form G = ev ((Dn ;D;D ([[x1 ; : : : ; xn ; x M ] C (D) ) (1 (
1
(
1
)
)
1
1
is easily satisfied. To n), and f = Dn ;D;D ([[x1 ; : : : ; xn ; x ` M ] C(D) ) Gn :
Conditions ceq follows from Lemma 5.5, while condition show condition abs, assuming i = G Thi mII (1 i
I [x:M ] = = G Tf mnT V Vn F n ( n) = G Tf mnT V ((V Th m ) (V Thn m )) 1
(by Naturality of )
1
II
II
= G Tf mnT V ((TTh1 II mII ) (TThn II mII )) (by monoidality of )
= G Tf mnT V ((TTh1 TmII mII ) (TThn TmII mII )) = G Tf mnT V (T (Th1 mII ) T (Thn mII )) mnII (by Naturality of mA;B )
= G Tf T ((Th1 mII ) (Thn mII )) mnII mnII (by definition of m)
= G T (f ((Th1 mII ) (Thn mII ))) mn ;
2
hence, we have the shape of a value.
17
6 The categorical v -model It is well known that a cartesian closed category with a reflexive object, which is a pseudo--structure, in order to be a -model needs to satisfy the property of having enough points (see [9]). Also for the v -calculus, we will prove a similar condition. Namely, we will prove that a Cbv category, in order to satisfy also condition of Definition 2.3, must satisfy the property of having enough values, i.e. two morphisms in the model object of a pseudo-v -structure can be different only if they have a different behaviour on at least one value. This property is the natural restriction of the property of having enough points to a setting where the -rule is restricted to arguments which are values. Formally:
D
Definition 6.1 Let ( ) be a Cbv category. Let C (D) be the pseudo-v -structure C (D) has enough values iff: defined as in Definition 5.7.
CD
M M 8f; g : D ! D:9h 2 V:(f 6= g ) f h 6= g h)
In fact, for proving the following theorem we use a generalization of the previous property. This is because we do not manage morphisms from to , but from a tensor product of objects to . Therefore, we say that C (D) has enough values iff:
D
M
D D
8n 1:8i n:8f; g : IIi D II n?i? ! D: 9h 2 V:(f 6= g ) f idi h id n?i? 6= g idi h id n?i? ): Theorem 6.2 Let C (D ) be a Cbv category. A pseudo-v -structure MC D with (
II
( II
1)
1)
II
( II
1)
(
)
enough values is a v -model.
Proof. We must prove Condition of Definition 2.3. Let M and N be two terms. V: xd [M ] = xd [N ], this means that, using the notation introduced in If d Definition 5.7 and in the proof of Theorem 5.8,
8 2 I
I
[ x1 ; : : : ; xn ; x ` M ] C (D) ((x1 ) (xn ) d) = [ x1 ; : : : ; xn ; x ` M ] C (D) ((x1 ) (xn) idD ) (idII idII d) = [ x1 ; : : : ; xn ; x ` N ] C (D) ((x1 ) (xn ) idD ) (idII idII d): Since MC (D) has enough values, we have [ x1 ; : : : ; xn ; x ` M ] C (D) ((x1 ) (xn ) idD ) = (1) [ x1 ; : : : ; xn ; x ` N ] C (D) ((x1 ) (xn ) idD ): The thesis, I [x:M ] = I [x:N ], holds in the following way: I [x:M ]= GT (([[x1 ; : : : ; xn; x ` M ] C(D) ((x1 ) (xn) idD ))) mk ; I [x:N ]= GT (([[x1; : : : ; xn; x ` N ] C(D) ((x1) (xn) idD ))) mk ; using the same steps in the proof of Theorem 5.8 and the naturality of Dn ;D;D , i.e. (g (h id)) = (g) h. Then we exploit (1). 2 18
Remark 6.3 Remark 4.4 underlies the fact that a cartesian closed category is a particular instance of Cbv. This implies that every pseudo-structure for the classical -calculus is a pseudo-v -structure, but it does not imply that every model for the classical -calculus is a v -model too, since the condition of having enough values is stronger than the condition of having enough points. This reflects the fact that Condition of Definition 2.3 is stronger than the corresponding condition defining a model for the classical -calculus. For example, let us consider a Scott Domain solution of the equation
D
D (D ! D) f?; >g where ? is less than >, is the smash sum and D ! D is the domain of continuous functions from D to itself. In order to interpret the v -calculus, a natural choice is
V
D!D
). The resulting domain, although to take the set of semantic values as = ( it is built in a cartesian closed category with enough points, has not enough values. Indeed, for example, the two functions:
f = x 2 D: g = x 2 D:
if if
x=> x=>
then then
d1 d2
D
else d0 ; else d0 ;
where d1 and d2 are two incomparable elements of , are different but equal on every values. This does not imply that cannot give a v -model. Indeed, it can give a v -model if every pair of functions like f and g are not interpretations of any term. Obviously, this can be proved only with an ad-hoc study of the interpretation, and not in a general categorical setting.
D
7 Extensionality and v The notion of extensionality in a given semantics is relative to the extensional behaviour of the applicative structure. If an applicative structure D; ; is a model for the classical lambda calculus, then the extensionality can be expressed in the D, if for all d3 D we have d1 d3 = d2 d3 , usual way as: for all d1 ; d2 then d1 = d2 . In a call-by-value setting, instead, the extensionality is a property concerning the behaviour of a “function” w.r.t. the values, namely:
h Ii
2
2
hS; V; ; Ii is extensional iff: 8d ; d 2 S:((8v 2 V: d v = d v) =) d = d ):
Definition 7.1 A pseudo-v -structure 1
2
1
2
1
2
Since the extensionality of a pseudo-v -structure implies condition of Definition 2.3, we have: 19
Proposition 7.2 Every extensional pseudo-v -structure is an extensional v -model.
2
From a syntactic point of view, in the classical lambda calculus the extensionality is represented by the -rule, that is x:(Mx) M if x (M ). Indeed, every extensional -model is a model also for the equivalence relation generated by the -rule, and viceversa. But, if we consider the -rule together with the v -rule in the call-by-value lambda calculus, the resulting term rewrite system looses the Church-Rosser property. In order the Church-Rosser property holds, Plotkin in [14] proposed the following rule, extending the theory v to the theory v v :
!
(M
2 Val)
62 FV
(x 62 FV (M )) (v ) (x:(Mx)) =v M and
The equality in this theory becomes v v -equality and will be denoted with:
Definition 7.3 terms M; N ,
v v ` M =v N: A v -model M = hS; V; ; Ii is a v -model if for every pair of
v v ` M =v N =) M j= M =v N: An obvious result is that every extensional v -model is a v -model.
Differently from what happens for models of the classical lambda calculus, the convers is not always true, that is there are non-extensional v -models, as we will see in Example 8.9. C (D) as defined in the previous We now prove that a categorical v -model ) is an isomorphism (i.e. G F = section, such that the retraction . T ( idD ) is a v -model.
D
D ? D
Theorem 7.4 A categorical v -model v -model.
MC D (
)
M
such that
D T (D ? D), is a I
I
Proof. It is sufficient to proof that for all environments , [x:yx] = [y ]. Applying the interpretation function, we can see that: [ y x:yx] C(D) = G T (D;D;D ([[y; x yx] C(D) ) G) F . Let us see the form of [ y; x yx] C(D) . By Lemma 5.5,
`
`
[ y; x ` y] C (D) = = [ y ` y] C (D) D (idD (E F )) = G F D (idD (E F )) = D (idD (E F )): 20
`
[ y; x ` x] C (D) = = [ x; y ` x] C (D) D;D = D (idD (E F )) D;D (by naturality of )
= D II;D ((E F ) idD ) = D ((E F ) idD ); hence, we have
[ y; x ` yx] C (D) = = ev ((V F D (idD (EV F ))) (D ((EV F ) idD ))) r2 = ev ((V F ) idD ) (D D ) (idD (E F )2 idD ) (G2 G2 ) (idT V T V ;T V idT V ) (Dup Dup) F 2 (by naturality of )
= ev ((V F ) idD ) (D D ) (G id2II G) (idT V II;II idT V ) (Dup Dup) F 2 (by the comonoid and the fact that II;II = idII II ) = ev ((V F ) idD ) (D D ) (G id2II G) (?T V1 ?T V1 ) F 2 (by naturality of and )
= ev ((V F ) idD ) (D D ) (?D1 ?D1 ) G2 F 2 = ev ((V F ) idD ): Substituting:
[ y ` x:yx] C (D) = = G T (D;D;D (ev (( F ) id)) G) F (by naturality of ) = G T ( F G) F = G T () F (by the comonad)
= G F = [ y ` y] C (D) :
2 The following proposition shows that the behaviour of the interpretation of the term (z:z ) (namely, the identity of the classical lambda calculus) is always that 21
one of the identity morphism in a v -model. This is a witness of the fact that the class of models that we defined is the class of the “total” ones.
(z:z) and let M 2 a generic term (may be not valuFV fx ;: : :; xng. In the categorical v -model MC D , [ x ;: : :; xn ` IM ] C D = [ x ;: : :; xn ` M ] C D :
Proposition 7.5 Let I (M ) able) such that
(
1
(
1
)
1
(
)
)
Proof. Step by step:
[ x1 ;: : :; xn ` IM ] C (D) = (by Lemma 5.6)
= [ x1 ;: : :; xn ; z ` z ] C (D) (idnD [ x1 ;: : :; xn ` M ] C (D) ) rn n+1 (idn [ x1 ;: : :; xn ` M ] C (D) ) = G Vn+1 n+1 F D (Gn Gn) (T V )n F n = G iso ((E F )n (F [ x1 ;: : :; xn ` M ] C (D) )) (Gn Gn) (T V )n F n = G iso (idnII (F [ x1 ;: : :; xn ` M ] C (D) )) (E n Gn) (T V )n F n (Exploiting the technique used in the proof of Theorem 7.4 and the coherence theorem)
= G F [ x1 ;: : :; xn ` M ] C (D) Gn F n
D T V) = [ x ;: : :; xn ` M ] C D : (Since 1
(
)
2 8
Instances of Cbv
The definition of a categorical v v in different settings.
v -model allows to characterize some models of
8.1 A Scott-domain instance of Cbv In this subsection we prove that every model of v belonging to the class defined in [3] is a categorical v -model. Let CPOS be the category such that:
22
the objects are the complete partial orders (cpo) or Scott domains, the morphisms are the strict continuous functions, namely those continuous functions that always take the bottom element of the source object to the bottom element of the target object.
!
Let D1 ; D2 be two cpo’s. (D1 ? D2 ) is the cpo of the strict continuous functions from D1 to D2 ordered pointwise. We denote with D the bottom element of a cpo D. The bottom element of (D1 ? D2 ) is the function constantly equal to D2 . Moreover, with D? we denote the cpo (the lifted of D ) obtained from D adding a new bottom element .
?
!
?
?
Lemma 8.1 Let CPOSD be the category CPOS equipped with a retraction ( ? )?. The category CPOSD is a Cbv category.
D! D
D.
Proof. Let us take:
as the functor for the smash product, namely D D = fhd ; d i j d 2 D ; d 2 D ; d = 6 ?D1 ; d 6= ?D2 g[f?D1 D2 g; its unity is II = f?; 1g where ? is smaller than 1, and if f : D ! D and g : D ! D then f g : D D ! D D is defined as 8 >< hf (d ); g(d )i if d = hd ; d i and f (d ) =6 ?D2 ; f (d ) =6 ?D4 f g(d) = > ? if d = hd ; d i and f (d ) = ?D2 or f (d ) = ?D4 :? if d = ? ? as the functor for the strict continuous functions !?, T as the lifting monoidal functor ?, namely: 1
2
1
2
1
1
2
2
1
2
1
3
4
1
1
3
2
3
- TD = D? , D2 then Tf - if f : D1 f (d) if d D1 while f?(
! 2
4
1
3
1
1
3
1
= f? : D1 ?
?) = ?,
2
3
3
! D ? is such that f?(d) = 2
D : D? ! D is defined as D (d) = d if d 2 D while D (?) = ?D , D : D? ! D??0 is defined as D (d) = d if d 2 D while D (?) = ?0, mD1;D2 : D ? D ? ! (D D )? and m : II ! II? are defined as 8 >< hd ; d i if d = hd ; d i and d =6 ?D1 ; d =6 ?D2 mD1 ;D2 (d) = > ? if d = hd ; d i and d = ?D1 or d = ?D2 :? if d = ? m (1) = 1 m (? ) = ?; 1
1
2
1
2
2
II
II
1
2
1
1
2
1
II
23
II
2
2
ED : D? ! II is defined as ED (d) = 1 if d 2 D while ED (?) = ? , DupD : D? ! D? D? is defined as DupD (d) = hd; di if d 2 D while DupD (?) = ?D? D? , evD1;D2 : (D !? D ) D ! D is defined as evD1 ;D2 (hf; d i) = f (d ) while evD1 ;D2 (? D1 !? D2 D1 ) = ?D2 , : Hom((D D ); D ) ! Hom(D ; (D !? D )) is such that (f ) is a function defined as (f )(?D1 ) = ? D2 !? D3 while (f )(d ) is the 6 ?D2 and (f )(d )(?D2 ) = function (f )(d )(d ) = f (hd ; d i) if d = ?D3 . If, in addition, there is an object D having (D !? D )? as a retract, then it is routine II
1
2
1
(
1
2
1
1
)
2
3
1
2
3
(
1
2
1
2
1
)
2
1
2
to prove that all the diagrams for having a Cbv category commute.
At this point we can use the Cbv category just introduced for defining a pseudoLet us see how the set of semantic values V is defined. Starting from a strict continuous function h : II ( ? ), we have that this function relates 1 II to an element d ( ? ). Furthermore, h? : II? ( ? )? is different from the function constantly equal to , since h?(1) = d = . (Let notice that d can be (D!?D) , that is different from .) Hence, the function h? mII pick out an element d ( ? )? different from . Finally, since the presence of the retraction F G = id((D!? D)? ) , we have that different from D . The a semantic value G h? mII pick out an element d following remark enlights this fact:
v -structure as in Definition 5.7.
! D! D 6 ?
?
! D! D 2 D! D
2
?
2 D! D
?
2D
?
?
Remark 8.2 Let C (D) = S; V; ; be the pseudo-v -structure built out from the proof of Lemma 8.1. The set V , of semantic values, is the set of morphisms v : II such that:
M
h
!D
where d is in the image of G.
Ii
v(1) = d 6= ?D v(?II ) = ?D ;
D
Theorem 8.3 Let be a Scott domain such that a categorical v -model.
D (D !? D)?. Then D gives
Proof. Let us place in the category CPOSD with ( ? )?. Lemma 8.1 C (D ) = D; V; ; . and Definition 5.7 imply that we have a pseudo-v -structure C (D ) has enough values. To this aim, let us take two difWe must prove that ferent strict continuous functions f; g : . Since they are strict, if they are such that f (d) = g (d). From Remark 8.2 different then there exists D = d
D D! D M h
M
? 6
2D
D!D
24
6
Ii
2
D! D D D! D 2
6 ?
we have that every d G(( ? )?) and such that d = D is equal to v(1) for some v V . Furthermore, if ( ? )?, then every d = D is equal to v (1) for some v V . Hence, there exits v V such that v (1) = (d), and so f v = g v. By Theorem 5.8. it follows that we have a categorical v -model, moreover, ( 2 since ? )?, by Theorem 7.4 a categorical v -model.
2
6
2
6 ?
D D! D
In [4] the initial solution to D is extensively studied.
(D !? D)? in the category of Scott domains
8.2 Coherence semantics of v In this subsection we introduce an instance of Cbv in the coherence spaces setting. 8.2.1
Coherence spaces
In this subsection we recall the notions of coherence space and stable and linear function together with some basic constructions.
j j
j jj j j j j j
A A be a Definition 8.4 Let A be a set of elements called atoms. Let cjAj symmetric and reflexive relation, called compatibility relation. Given A and cjAj , a coherence space A is the set of all sets of compatible atoms in A , namely, A a; b :cjAj(a; b). ( A ) and A
2 ,8
Pj j
2
Let observe that if A is a coherence space, then
; 2 A.
Definition 8.5 Let A and B be two coherence spaces. i) A function f
: A ! B is continuous iff:
f is monotonic, namely: for every ; 0 2 A, if 0 , then f () f (0 ), – if (i )i2I is a directed family in A, then: f (Si2I i ) = Si2I f (i). A continuous function f : A ! B is stable iff: for every ; 0 2 A, if [ 0 2 A, then f ( \ 0 ) = f () \ f (0 ). A stable function f : A ! B is linear iff f preserves arbitrary unions, –
ii) iii)
f (S2A ) = S2A f () for every A A.
namely:
25
;) = ;.
Let notice that every linear function is strict, in the sense that f (
!
Let A; B be two coherence spaces. (A s B ) denotes the coherence space of the stable functions from A to B ordered by the Berry’s order, namely given two stable functions f; g (A s B ):
2
f g
iff
!
8; 0 2 A:( 0 ) f () = g() \ f (0)):
(A ? B ) denotes the coherence space of the linear functions from A to B ordered like the stable ones.
Notation Let A be a coherence space. Atoms of A will be ranged over by a; b; : : :, while elements of A (i.e. sets of atoms) will be ranged over by ; ; : : : . With 1 we denote the unique atom of II, namely II = ; 1 . c(a; a0 ) means that a and a0 are compatible. Let , !, s and be the functors over coherence domains such that:
!
-
f; f gg
?
jA B j = f[a; b] j a 2 jAj and b 2 jB jg, where c([a; b]; [a0 ; b0 ]) iff both c(a; a0 ) and c(b; b0 ).
j!Aj = fd j d is a finite element of Ag, where, if d; d0 2 j!Aj, then c(d; d0 ) iff d [ d0 2 A. the functor !s builds the coherence domains of stable functions where jA !s B j = f(; b) j 2 A and b 2 jB jg, where c((; b); (0 ; b0 )) iff [ 0 2 A implies both c(b; b0 ) and if b = b0 , then = 0 .
!
The elements of A s B are traces of stable functions from A to B . If f : A B is a stable function, then its trace is denoted by tr(f ) and it is used as follows: f () = bi (i ; bi ) tr (f ); i .
!
f j
2
g
? builds the coherence domains of linear functions where jA ? B j = f(a; b) j a 2 jAj and b 2 jB jg, where c((a; b); (a0 ; b0 )) iff c(a; a0 ) implies both c(b; b0 ) and if b = b0 , then a = a0 . The elements of A ? B are linear traces of linear functions from A to B . If f : A ! B is a linear function, then its linear trace is denoted by ltr(f ) and it is used as follows: f (fai j i 2 I g) = fbi j (ai ; bi ) 2 ltr(f )g.
- the functor
8.2.2
The linear instance of Cbv
Let Lin be the category such that:
the objects are the coherence spaces, 26
the morphisms are the linear functions.
Let
, !, and ? be as in the previous subsection.
Lemma 8.6 Let LinD be the category Lin equipped with a retraction ). The category LinD is a Cbv category.
D
D. !(D ?
Proof. We have a Cbv category if we take ! as the monoidal functor T and we use the following definitions: - The linear traces of the monoidal closure are
f( ([a; b]; c) ; (a; (b; c)) ) j ([a; b]; c) 2 j(A B ) ? C jg ltr(evB;C ) = f([(b; c); b]; c) j (b; c) 2 jB ? C jg
ltr(A;B;C ) =
- If f is a linear function from A to B , then ltr(!f )
=
f(fai1 ; : : : ; aik g; fbi1 ; : : : ; bik g) j (aij ; bij ) 2 ltr(f ) and fai1 ;: : : ;aik g; fbi1 ;: : : ;bik g are finite (perhaps empty) sets of compatible elementsg:
- The linear traces of the natural transformations for the comonad are ltr(A ) =
f(
[
; ) j 2 j!!Ajg;
ltr(A ) =
f(fg; ) j 2 jAjg:
- The linear traces of the morphisms making ! monoidal are
f(1; ;); (1; f1g)g f([ ; : : : ; n]; f[a ; : : : ; an]; : : : ; [ak ; : : : ; akn]g) j aji 2 i g: ltr(mII ) =
ltr(mA1 ;:::;An ) =
1
1 1
1
1
Remember that mnA and mn are defined starting from mA1 ;:::;An . - The linear traces of the morphisms giving the comonoid are ltr(EA ) =
f(;; 1)g;
ltr(DupA ) =
D
f(; [ ; ]) j [
D ? D
1
2
1
2
= 2 j!Ajg:
If, in addition, there is an object having !( ) as a retract, then it is routine to prove that all the diagrams for having a Cbv category commute. 2
27
The resulting Cbv category can be used to define a pseudo-v -structure C (D) = S; V; ; as in Definition 5.7. Let us see how the set of semantic values V is defined. Let us take a linear function h : II ( ) such that
h
M
Ii
! D ? D
f(1; (d ; d )); (1; (e ; e ))g: In this case we have that h relates f1g 2 II to the element f(d ; d ); (e ; e )g 2 (D ? D). Furthermore, since ltr(!h) = f(;; ;); (f1g; f(d ; d )g); (f1g; f(e ; e )g); (f1g; f(d ; d ); (e ; e )g)g; ltr(h) =
1
1
2
2
1
1
2
2
1
2
1
2
1
2
1
2
and ltr(!h
m ) = f(1; ;); (1; f(d ; d )g); (1; f(e ; e )g); (1; f(d ; d ); (e ; e )g)g; II
1
2
1
2
1
2
1
2
we have that
(!h mII )(f1g) = f;; f(d1 ; d2 )g; f(e1 ; e2 )g; f(d1 ; d2 ); (e1 ; e2 )gg: Generalizing this discussion, we obtain the following characterization of the semantic values: Remark 8.7 Let C (D) = S; V; ; be the pseudo-v -structure built out from the proof of Lemma 8.6. The set V , of semantic values, is the set of morphisms v : II such that:
M
h
Ii
!D
v(f1g) = G(P (d)) v(;) = ;; where P (d) is the power set of a given atom d of !(D ? D ).
D
Theorem 8.8 Let be a coherence space such that a categorical v -model.
D !(D ? D). Then D gives
Proof. Let us place in the category LinD with !( ). Lemma 8.6 and C (D ) = D; V; ; . Definition 5.7 imply that we have a pseudo-v -structure We must prove that C (D) has enough values. To this aim, let us take two different linear functions f; g : and let us confuse with !( ) (thanks ), i.e. finite linear traces, to the isomorphism), namely let us take atoms of !( instead of atoms of . If f and g are different, then their linear traces are different. Hence there exists some atom d such that f ( d ) = g ( d ). Among these atoms, let us take the much small as possible, namely let us take an atom d such that f ( d ) = g ( d ) and every other atom d such that f ( d ) = g ( d ) is such that the cardinality of d is less or equal than the cardinality of d. We have two cases:
M
D D ? D M h
D!D
D D ? D
D
fg 6
fg 6
fg
D ? D
fg
fg 6
28
Ii
fg
d 6= ; or else d = ;. In the first case we have that every atom d0 d is such that f (fd0 g) = g(fd0 g). Hence, by linearity, f (P (d)) = f (fdg) [ (
[
d0 d
f (fd0 g)) = f (fdg) [ (
f;g 6 6
f;g P
[
d0 d
g(fd0 g)) 6= g(P (d)):
In the second case, f ( ) = g ( ). By the way, in both cases, there exists an atom d such that f ( (d)) = g ( (d)). From Remark 8.7 follows that (d) = v( 1 ) for some semantic value v, hence there exists a semantic value v such that f v = g v. By Theorem 5.8 follows that we have a categorical v -model, moreover, since !( ), by Theorem 7.4, we have a categorical v -model. 2
P
fg 6
P
D D ? D
D D ? D
Let us note that, although !( ) gives a v -model, this model is not extensional, as showed by the following example: Example 8.9 Let C (D) = D; V; ; be the pseudo-v -structure of Definition 5.7 based on LinD . The binary operation , making D; an applicative structure, is defined as: f g = evD;D ((V f ) g ), for every pair of morphisms f; g Hom(II; ), where, for simplicity, we have omitted F since the isomorphism. The behaviour of V in this coherence space setting is such that the two following morphisms, f1 ; f2 Hom(II; ) whose linear traces are:
M
h
D
Ii
h i
2
2 D ltr(f ) = f(1; ;); (1; f(d ; d )g); (1; f(e ; e )g); (1; f(d ; d ); (e ; e )g)g; ltr(f ) = f(1; ;); (1; f(d ; d )g); (1; f(e ; e )g)g; (where we identify atoms of D with atoms of !(D ? D )) have the same behaviour, 6 f. 2 namely for all g 2 Hom(II; D ) we have f g = f g but f = We conclude this section giving an example of interpretation in D . Example 8.10 Let ! = (x:xx)(x:xx). From Lemma 5.6 we have [ ` ! ] C D = [ x ` xx] C D [ ` x:xx] C D . Since [ ` x:xx] C D =!(([[x ` xx] C D )) m , let us see the form of [ x ` xx] C D . [ x ` xx] C D = = ev (( [ x ` x] C D [ x ` x] C D ) Dup = ev (( id) id) Dup = ev ( id) Dup: Since the linear trace of id is of the form f([f(a; b)g; c]; [(a; b); c]); : : : g, we have ltr(ev ( id)) = f([f(a; b)g; a]; b); : : : g, hence ltr([[x ` xx] C D ) = 1
1
2
1
2
1
1
2
1
2
1
2
2
1
2
2
1
2
(
(
)
(
(
)
(
(
)
(
)
II
)
)
(
)
(
)
(
29
)
)
f(f(a; b)g [ a; b); : : :g. Moreover, ltr([[` x:xx] C D ) = f(1; ;); (1; f(f(a; b)g [ a; b); : : :g); : : :g, with f(f(a; b)g [ a; b); : : :g finite. This finiteness implies that [ ` !] C D = ;, hence for every environment we cannot have a semantic values. (
2
(
)
)
9 Conclusions and comparisons with related work As we said in Section 4, the definition of a Cbv category for modeling the v calculus corresponds to define “total” models. Indeed, the category is equipped . T( ). This corresponds to choose , as with a retraction the set of semantic values, i.e., the set of all morphisms from to . In this way, the partial behaviour of the v -calculus is mimiced by the behaviour of the elements of the function space, hence by total functions in some sense. The behaviour of the interpretation of the identity I (z:z ) is a witness of this fact, as showed in Proposition 7.5. All the total models we know turn out to be Cbv categories. Let we refer again the model , in the Scott domain setting, based on the domain equation D (D ? D )? studied in [4], and that one in the coherence space setting based on the domain equation !( ) studied in [15]. Remark 4.4 together with the fact that “enough values” becomes “enough points” in the -calculus setting and that a cartesian closed category is a particular Cbv category, implies that every model of the -calculus is a total model of the v calculus too. The above discussion brings us to the conjecture that our characterization is complete for the total models. Formally:
D
D ? D
D ? D D D
Conjecture
!
P
D D ? D
Every total model of the v -calculus is a Cbv category.
In the literature, also partial models of the v -calculus have been studied. In [4] a partial model is built, which is fully abstract with respect to the SECD operational semantics. is obtained from the total model above, through a notion of call-by value applicative bisimulation. A further partial model, also fully abstract, was defined by Pino-Perez [13], using a purely syntactical construction. In the coherence domains setting, a partial model was built by Honsell and Lenisa [7], by defining a new notion of coherence domain, the pointed one. Each one of these partial models can be extended to be total, and we conjecture that each one of the total extensions is a Cbv category. Moggi, in [12], in order to define a general categorical setting for modeling different calculi, introduced the notions of “value” and “computation”. Roughly B is a function speaking, a computation (in a given typed calculus) of type A from values of type A to computations of type B . So, in a categorical setting, there
H H
P
!
30
is a functor T , such that B is the value corresponding to the computation of type TB , and it turns out that T must be the functor of a monad. The point of view of Moggi is, in some sense, dual to our point of view. Indeed, using his terminology, we start from computations, and define a functor T “promoting” a computation to be a value, while he starts from values, and define a functor T transforming a value in the corresponding computation. This is reflected by the fact that we need T to be a comonad, while he need T to be a monad (remember that the two notions are dual in category theory). Using this approach, Moggi can model very different notions of computation, as partial computations, computations with side effects, with exceptions, and others. It is possible to extend the approach based on monads to the untyped languages; so it is natural to ask what is the relation between our approach and the Moggi’s one for modeling the v -calculus. The Moggi’s approach turn out to be a partial one, in principle. Indeed, the natural choice that all the terms with functional behaviour must be value leads to the following recursive definition of values:
V V ! T V:
D
V
Hence, the whole interpretation domain of the v -calculus will be = T . Notice that, in the Scott domain setting, the natural choice for T is the lifting functor. So the isomorphism above is equivalent to the one:
D (D !? D)? which we proved to be a Cbv category. So the two approaches can give rise to the same domain equation. Acknowledgments We would like to thank Jean Yves Girard, Yves Lafont, Furio Honsell and Eugenio Moggi for very stimulating and useful discussions on the topic of this paper.
References [1] A. Asperti and G. Longo. Categories,Types and Structures. Foundations of Computing. The MIT Press, 1991. [2] N. Benton, G. Bierman, V. de Paiva, and M. Hyland. Term assignment for intuitionistic linear logic. Technical Report 262, Computer Laboratory, University of Cambridge, August 1990. [3] M. Dezani-Ciancaglini, F. Honsell, and S. Ronchi della Rocca. Models for theories for functions strictly depending on all their arguments (abstract). The Journal of Symbolic Logic, 51(3):845 – 846, 1986. 31
[4] L. Egidi, F. Honsell, and S. Ronchi della Rocca. Operational, denotational and logical descriptions: a case study. Fundamenta Informaticae, 16(2):149 – 169, February 1992. [5] G. Gonthier, M. Abadi, and J.J. L´evy. The geometry of optimal lambda reductions. In Proc. 19th Symp. on Principles of Programming Languages (POPL 92), 1992. [6] J. R. Hindley and G. Longo. Lambda-calculus models and extensionality. Z. Math. Logik Grundlag. Math., 26:289 – 310, 1980. [7] F. Honsell and M. Lenisa. Some results on the full-abstraction problem for restricted -calculi. In LNCS 711: Proceedings of 18th. Symposium on MFCS’93 (Poland), pages 84 – 104. Springer-Verlag, 1993. [8] G. M. Kelly. On MacLane’s conditions for coherence of natural associativities. Journal of Algebra, 1:397 – 402, 1964. [9] C.P.J. Koymans. Models of the lambda calculus. Information and Control, 52(3):306 – 332, 1982. [10] Y. Lafont. Introduction to linear logic. Lecture notes for the Summer School on Constructive logic and Category theory (Isle of Thorns), August 1988. [11] P.J. Landin. The mechanical evaluation of expressions. Computer Journal, 6(4), 1964. [12] E. Moggi. Notions of Computation and Monads. Information and Computation, 93:55 – 92, 1991. [13] R. Pino-Perez. A strict partial combinatory algebra which modelizes partial lambda calculus. In A. Tarlecky, editor, MFCS’ 91, LNCS 520, pages 387 – 396. Springer Verlag, 1991. [14] G. Plotkin. Call-by-name, call-by-value and the -calculus. Theoretical Computer Science, 1:125 – 159, 1975. [15] A. Pravato, S. Ronchi della Rocca, and L. Roversi. Categorical semantics of the call-by-value lambda-calculus. In LNCS 902: Proceedings of TLCA ’95, Edinburgh, U.K., pages 302 – 318. Springer-Verlag, 1995. [16] D. Scott. Some philosophical issues concerning theories of combinators. In LNCS 37: Proceedings of -calculus and computer science theory, pages 346 – 366. Springer-Verlag, 1975. 32
A Commuting diagrams
!: IDC is monoidal if the following two diagrams
The natural transformation : T commute: mA;B
TA TB
QQ Q A B
- T A B (
)
-T QQ idQQ QQs ? mII
II
A B QQQ s ?
II
II
II
A B II : The natural transformation : T ! TT is monoidal if the following two diagrams
commute:
TA TB A B
mA;B
- T A B (
?
-T
II
II
?
T II
A B
?
mII
II
mII
TTA TTB mTA;TB
)
TmII
- TT? II
?
T (TA TB) Tm - TT (A B) A;B Notice that the TmA;B mTA;TB and TmII mII are, respectively, the mA;B and
mII of the monoidal functor TT . : The natural transformation E : T ! KII is monoidal if the following two dia-
grams commute:
TA TB EA EB II
?
II
- T A B
mA;B
(
)
II
EA B
II
-?
-T QQ E idQQ QQs ? mII
II
II
II
II
II
moreover, it is an element of T -coalgCbv ((TA; A ); (II; mII )) if the following diagram commutes: EA
-
TA
A
?
TTA
II
mII
? T TEA II
33
The natural transformation Dup diagrams commute:
- T A B
mA;B
TA TB DupA DupB
(
? ?
)
m2A;B
II
-T
mII
II
DupA B
-
TA TB)2
(
T is monoidal if the following two
?II 1
TA TA) (TB TB)
(
: T !: T
II
DupII
?
? T
T m m
II
II
II
II
II
?
T A B))2
( (
Let notice that naturality of , E , Dup, and mA;B implies that, for all f and g : C D, the following diagrams commute:
!
A
TA Tf
-A
f
?
TB
B
- B? Tf
TA A
TA
?
TTA
Tf
TA
@@ EA ? @-@R
TB
Tf
- TB
TA TC Tf Tg
B
? TTB TTf
- TA TA
DupA
Tf Tf
?
?
-B TB TB TB Dup
II
EB
:A!B
?
TB TD
- T A C
mA;C
(
)
T (f g)
- T B ?D
mB;D
(
)
B Proofs of technical lemmas 5.5 and 5.6
FV
f
g
(M ) x1 ;: : :; xn . Let 1 Lemma 5.5 Let M be a term such that n 1 and xn+1 (M ). The following equations hold: (exchange) [ x1 ; : : : ; xi ; xi+1 ; : : : ; xn M ] C (D) =
?
62 FV
i
`
= [ x1 ; : : : ; xi+1 ; xi ; : : : ; xn ` M ] C (D) (idiD?1 D;D idDn?i?1 ): (weakening) [ x1 ; : : : ; xn ; xn+1 ` M ] C (D) = = [ x1 ; : : : ; xn ` M ] C (D) Dn (idnD (EV F )): Proof. Exchange can be proved by induction on M substantially using the naturality of . 34
M.
Much work must be done for proving weakening. We proceed by induction on
Let M
= xi , for 1 i n ? 1. [ x1 ; : : : ; xn ; xn+1 ` xi ] C (D) = = G Vi n+1 F n+1 (by naturality of )
= G Vi n (T V )n (idnT V EV ) F n+1 = G Vi n (T V )n (F n (E F )) (by naturality of )
= G Vi n F n Dn (idnD (E F )) = [ x1 ; : : : ; xn ` xi ] C (D) Dn (idnD (EV F )): Let M
= PQ.
[ x1 ; : : : ; xn ; xn+1 ` PQ] C (D) = = ev (( F [ x1 ;: : :; xn ; xn+1 ` P ] C (D) )
[ x1 ;: : :; xn ; xn+1 ` Q] C (D) ) rn+1 (by inductive hypothesis)
= ev (( F [ x1 ;: : :; xn ` P ] C (D) Dn (idnD (E F )))
([[x1 ;: : :; xn ` Q] C (D) Dn (idnD (E F )))) rn+1 = ev (( F [ x1 ;: : :; xn ` P ] C (D) )
[ x1 ;: : :; xn ` Q] C (D) ) (Dn (idnD (E F )))2 rn+1 ; to conclude, it is sufficient to show that
(Dn (idnD (E F )))2 rn+1 = rn Dn (idnD (E F )): Without loss of generality, we proceed for n = 1:
(D (idD (E F )))2 r2 = = (D (idD (E F )))2 (idT V T V ;T V idT V ) Dup2 F 2 (by naturality of )
= 2D (idD D;II idD ) (G2 E 2 ) Dup2 F 2 (by the comonoid and naturality of ?1 ) 35
= 2D (idD D;II idD ) (G2 ?II 1 ) (Dup E ) F 2 (by naturality of and definition of )
= G2 (T V )2 (Dup E ) F 2 (by naturality of )
= D2 (G2 idII ) (Dup E ) F 2 = D2 ((G2 Dup F ) (E F )) = D2 (r1 (E F )) (by naturality of )
= r1 D (idD (E F )): Let M
= x:P .
[ x1 ;: : :; xn ; xn+1 ` x:P ] C (D) = = G T (([[x1 ;: : :; xn ; xn+1 ; x ` P ] C (D) ) Gn+1) sn+1 (using exchange)
= G T (([[x1 ;: : :; xn ; x; xn+1 ` P ] C (D) (idnD D;D )) Gn+1) sn+1 (by inductive hypothesis)
= G T (([[x1 ;: : :; xn ; x ` P ] C (D) Dn+1 (idnD+1 (E F )) (idnD D;D )) Gn+1) sn+1 (by naturality of )
= G T (([[x1 ;: : :; xn ; x ` P ] C (D) Dn+1 (idnD ( II;D ((E F ) idD )))) Gn+1) sn+1 (since D II;D = D and Dn+1 = idDn D ) = G T (([[x1 ;: : :; xn ; x ` P ] C (D) (idDn (D ((E F ) idD )))) Gn+1) sn+1 (let us suppose n > 0. If n = 0 the proof is simpler and uses Remark 5.4) = G T (([[x1 ;: : :; xn ; x ` P ] C (D) Dn+1 (idDn?1 D ) (idnD (E F ) idD )) Gn+1) sn+1 = G T (([[x1 ;: : :; xn ; x ` P ] C (D) Dn+1 (idDn?1 (D (idD (E F ))) idD )) Gn+1 ) sn+1 (by naturality of and functoriality of T ) = G T (([[x1 ;: : :; xn ; x ` P ] C (D) Dn+1 )) T (Dn (idDn (E F )) Gn+1 ) sn+1 ; 36
to conclude it is sufficient to prove that
T (Dn (idDn (E F )) Gn+1 ) sn+1 = T (Gn) sn Dn (idDn (E F )): Step by step:
T (Dn (idDn (E F )) Gn+1 ) sn+1 = = T (Dn ) T (Gn E ) m(n+1)T V n+1 F n+1 (by naturality of m2;) = T (Dn ) mDn ;II (mnD idT II ) ((TG)n TE ) n+1 F n+1 = T (Dn ) mDn ;II (mnD idT II ) ((TG )n (TE )) F n+1 (since EA is an element of T -coalgCbv ((TA; A ); (II; mII ))) = T (Dn ) mDn ;II (mnD idT II ) ((TG )n (mII E )) F n+1 = T (Dn ) mDn ;II (mnD idT II ) ((mnD (TG )n ) E ) F n+1 (by monoidality of T ) = T (Dn ) ((mnD (TG )n ) E ) F n+1 (by naturality of ) = mnD (TG )n ) F n Dn (idnD (E F )) (by naturality of m2;) = T (Gn ) mnT V n F n Dn (idnD (E F )) = T (Gn ) sn Dn (idnD (E F )):
2 Lemma 5.6 Let rn be as in Definition 5.3. The intepretation of the application of a lambda-abstraction to a term has the forms: for n > 0: [ x1 ; : : : ; xn (x:M )N ] C (D) =
`
= [ x1 ; : : : ; xn ; x ` M ] C (D) (idnD [ x1 ; : : : ; xn ` N ] C (D) ) rn ; for n = 0: [ ` (x:M )N ] C (D) = [ x ` M ] C (D) [ ` N ] C (D) : Proof. We proceed step by step. For n > 0:
[ x1 ; : : : ; xn ` (x:M )N ] C (D) = = ev (( F [ x1 ; : : : ; xn ` x:M ] C (D) ) [ x1 ; : : : ; xn ` N ] C (D) ) rn (by Diagram 4 below) 37
= ev ((Dn ;D;D ([[x1 ; : : : ; xn ; x ` M ] C (D) ) Gn F n )
[ x1 ; : : : ; xn ` N ] C (D) ) rn = ev (Dn ;D;D ([[x1 ; : : : ; xn ; x ` M ] C (D) ) id) ((Gn F n ) [ x1 ; : : : ; xn ` N ] C (D) ) rn (by naturality of ) = [ x1 ; : : : ; xn ; x ` M ] C (D) ((Gn F n ) [ x1 ; : : : ; xn ` N ] C (D) ) rn (collapsing Gn F n in rn , exploiting F G = id) = [ x1 ; : : : ; xn ; x ` M ] C (D) (idn [ x1 ; : : : ; xn ` N ] C (D) ) rn For n = 0 we have:
[ ` (x:M )N ] C (D) = = ev (( F [ ` x:M ] C (D) ) [ ` N ] C (D) ) ?II 1 (by Diagram 5 below)
= ev ((II;D;D ([[x ` M ] C (D) D )) [ ` N ] C (D) ) ?II 1 = [ x ` M ] C (D) D (idII [ ` N ] C (D) ) ?II 1 (by naturality of )
= [ x ` M ] C (D) [ ` N ] C (D) : T V )n
(
id
-
T V )n
(
([[x1 ;:::;xn ;x`M ] C(D) )Gn
- D ? D 6
n
V
?
n TT V )n mn TV T ((T V ) )
(
id
II
?
??
?
mII
(4)
- TV
T (([[x1 ;:::;xn ;x`M ] C(D) )Gn )
??
II
- D ? D 6
([[x`M ] C(D) )
V
-T
II
(5)
- TV
T (([[x`M ] C(D) ))
Diagrams 4 and 5 commute because they are essentially instances of Diagrams 6 and 7 below, that can be proved to commute using the comonad and both the natu-
38
rality and the monoidality of .
- TA TB 3 6 TA TB TA TB A B ? TTA TTB mTA;TB T TA TB TA TB
g
id
(
C
)
3 6 id -T m II
Tg g
II
II
39
Tg
(6)
- TC -C 6
C
II
II
-C 6
- TC
(7)
2