inclusions and subtypes ii: higher-order...

32
Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER, SRI International, Menlo Park, CA 94025, USA, and Center for the Study of Language and Information, Stanford University, Stanford, CA 94305, USA. E-mail: {narciso, meseguer} @ csl. sri. com Abstract The first-order theory of subtypes as inclusions developed in Part I is extended to a higher-order context This in- volves providing a higher-order equational logic for (inclusive) subtypes, a categorical semantics for such a logic that is complete and has initial models, and a proof that this higher-order logic is a conservative extension of its first- order counterpart This higher-order categorical semantics includes a new notion of homomorphism between models that is both very natural in terms of its preservation properties and substantially more general than other notions of higher-order homomorphism proposed previously. The categorical semantics of higher-order inclusive subtypes is then generalized to a notion of model with two subtype relations r <r' (inclusion) and r <• T' (implicit conversion) thus reconciling and relating the two different intuitions that have so far prevailed in the first-order and higher-order cases. Axioms are then given that integrate the < and <: relations in the unified categorical semantics. Besides en- joying the benefits provided by each of the notions without their respective limitations, this framework supports rules for structural subtyping that are more informative and can discriminate between inclusions and implicit conversions. Keywords: Subtype, inclusion, coercion, overloading, typed A-calculus, Cartesian closed categories. 1 Introduction We extend the first-order theory of subtypes as inclusions developed in Part I [25] to a higher- order context. The higher-order extension applies to the language, the logic, and the seman- tics. The language extension makes available at a higher-order level all the convenient prop- erties of order-sorted algebra; in particular, it supports the extra generality and convenience of equationally definable first-order types, for which subtype relations and overloaded operation symbols can be specified as in [ 19]. Such overloaded operation symbols support both subtype polymorphism, as when + is defined for naturals, integers, rationals, and complex numbers, and also ad hoc polymorphism, as when + is defined for unrelated types such as Booleans and naturals. Several examples of higher-order order-sorted modules are given to illustrate the advantages of our approach. Based on this higher-order language an equational logic of inclusive subtypes with very nice properties, including the 'no loss of information' property, is proposed. Explicit formulations of higher-order equational logics of subtypes seem to be absent in other higher-order approaches, which tend to concentrate on typing issues only. Having a higher-order logic available, it is then possible to define a semantics for it Our semantics is a natural extension of the categorical semantics for the first-order case and makes precise the notion of a Cartesian closed category with a class of inclusive subtypes. Models are interpretations of a higher-order order-sorted signature in such categories that satisfy the axioms of the theory in question. An additional contribution is a new notion of homomor- phism between such models that is both very natural in terms of its preservation properties and substantially more general than other such notions proposed previously. The categorical J. Logic Computat., Vol. 6 No. 4, pp. 541-572 1996 © Oxford University Press at Mathematics Library, University of Illinois at Urbana-Champaign on October 10, 2015 http://logcom.oxfordjournals.org/ Downloaded from

Upload: others

Post on 30-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-orderCaseNARCISO MARTI-OLIET and JOSE MESEGUER, SRI International,Menlo Park, CA 94025, USA, and Center for the Study of Language andInformation, Stanford University, Stanford, CA 94305, USA.E-mail: {narciso, meseguer} @ csl. sri. com

AbstractThe first-order theory of subtypes as inclusions developed in Part I is extended to a higher-order context This in-volves providing a higher-order equational logic for (inclusive) subtypes, a categorical semantics for such a logicthat is complete and has initial models, and a proof that this higher-order logic is a conservative extension of its first-order counterpart This higher-order categorical semantics includes a new notion of homomorphism between modelsthat is both very natural in terms of its preservation properties and substantially more general than other notions ofhigher-order homomorphism proposed previously. The categorical semantics of higher-order inclusive subtypes isthen generalized to a notion of model with two subtype relations r <r' (inclusion) and r <• T' (implicit conversion)thus reconciling and relating the two different intuitions that have so far prevailed in the first-order and higher-ordercases. Axioms are then given that integrate the < and <: relations in the unified categorical semantics. Besides en-joying the benefits provided by each of the notions without their respective limitations, this framework supports rulesfor structural subtyping that are more informative and can discriminate between inclusions and implicit conversions.

Keywords: Subtype, inclusion, coercion, overloading, typed A-calculus, Cartesian closed categories.

1 Introduction

We extend the first-order theory of subtypes as inclusions developed in Part I [25] to a higher-order context. The higher-order extension applies to the language, the logic, and the seman-tics. The language extension makes available at a higher-order level all the convenient prop-erties of order-sorted algebra; in particular, it supports the extra generality and convenience ofequationally definable first-order types, for which subtype relations and overloaded operationsymbols can be specified as in [ 19]. Such overloaded operation symbols support both subtypepolymorphism, as when + is defined for naturals, integers, rationals, and complex numbers,and also ad hoc polymorphism, as when + is defined for unrelated types such as Booleansand naturals. Several examples of higher-order order-sorted modules are given to illustratethe advantages of our approach. Based on this higher-order language an equational logic ofinclusive subtypes with very nice properties, including the 'no loss of information' property,is proposed. Explicit formulations of higher-order equational logics of subtypes seem to beabsent in other higher-order approaches, which tend to concentrate on typing issues only.

Having a higher-order logic available, it is then possible to define a semantics for it Oursemantics is a natural extension of the categorical semantics for the first-order case and makesprecise the notion of a Cartesian closed category with a class of inclusive subtypes. Modelsare interpretations of a higher-order order-sorted signature in such categories that satisfy theaxioms of the theory in question. An additional contribution is a new notion of homomor-phism between such models that is both very natural in terms of its preservation propertiesand substantially more general than other such notions proposed previously. The categorical

J. Logic Computat., Vol. 6 No. 4, pp. 541-572 1996 © Oxford University Press

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 2: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

542 Inclusions and Subtypes II: Higher-order Case

higher-order semantics thus defined has also very good properties, including the existence ofthe classifying category of a theory that is initial in the class of all models of such a theory,and the soundness and completeness of the logic relative to this semantics.

Two important conservativity results are also proved. First, we prove that higher-orderorder-sorted equational logic is a conservative extension of first-order order-sorted equationallogic; therefore, our extension is fully satisfactory from both the logic and—given the com-pleteness results—the semantic points of view. A second conservativity result makes availableat the higher-order level the additional typing flexibility of the 'retracts' technique [15, 19]which has proved very useful and convenient in its first-order version in the OBJ2 and OBJ3implementations [14, 16, 20]. Under very general assumptions it is proved that the additionof retracts to a higher-order order-sorted theory is a conservative extension.

The integration of the < and <: relations is treated in Section 3, and we discuss a very nat-ural example of this integration for partial equivalence relation (per) models; however, a fulltreatment of the combined system with both relations will have to wait for a future publication.In the concluding remarks we discuss some research directions suggested by the present workthat we would like to explore in the future. In particular, the theory developed in this paperis the most basic possible, namely a typed lambda calculus with products and with subtypesas inclusions. However, the extension to richer calculi should not present special difficultiesfollowing lines analogous to those already developed for the subtype as implicit conversionnotion in works such as [9, 6, 3, 7, 12,1] among others.

The exposition assumes familiarity with the notation, concepts, and results for the first-order case presented in Part I [25], which are generalized here to a higher-order context.

2 Higher-order order-sorted algebra

In this section, we will study an extension of order-sorted algebra corresponding to a (simply)typed lambda calculus with products and subtypes. We arrive at this extension by allowing twoconstructors for types: ifr and T7 are types, TXT'and T =>• r 'are also types; in this setting, weuse 'sort' as meaning 'basic type'. At the same time, we introduce new term constructors toform terms of the new types: projections and pairing for products, and lambda abstraction andapplication for function spaces. Categorically, a type r >̂- r ' is interpreted as the exponentialor function space of the objects interpreting r and r7; thus, we go from categories with finiteproducts to Cartesian closed categories.

This section can be seen as a generalization of the well known correspondence between(simply) typed lambda calculus with products and Cartesian closed categories [24, 11], thattakes into account the subtype relation.1

2.7 Signatures, terms, equations and deductionDEFINITION 2.1

Given a set 5 , we denote by 5M the set generated from 5 and the constant 1 by the operationsx and =>:

l .SCS" .2. A special symbol 1 G S".

1 Although the following study could be carried out without products appearing explicitly in terms, the correspon-dence between Cartesian closed categories and typed lambda calculus would then become more cumbersome.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 3: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 543

3- If TI ,T 2 6 SM, then n x r2 G S".4. If n , r2 € S", then n => r2 £ S".

If (5, <) is a poset, (S*\ <") is the poset with order <M defined by:

1. If s < s' in 5, then s < " s' in S™.

2. 1 < " 1.

3. If n < " T/ in S " (t = 1,2), then TJ x T2 < " T{ X T'2 in S".

4. If r < " T' in S " and r " £ S", then r" => r < " r " =*• r ' .

We will use the name sorts or boric types for the elements of S and ryp« for the elements ofS".

The availability of products at the level of types makes it possible to consider just 'unary'operations in the signature.

DEFINITION 2.2

A higher-order order-sorted signature, or hos signature for short, consists of a poset(5, <) together with a coherent order-sorted signature (S*, <*, S) such that ET,T i1 0 im-plies length(T) = 1.

We usually denote an hos signature by (5M , <M, E) or just E if 5 and < are clear; also, wewill often write just < for <M .

Notice that the order is given just for the basic types and it is extended 'structurally' to therest of types; therefore, if r, T1 ,T" £ 5, we do not have order relations of the form r" < (r ^>T'), (T x T1) < (T =$• T') or T" < (T x T1). Note also that we have imposed the restrictionon coherence from the beginning, because it is required for a treatment of equations similarto the one carried out in Part I for order-sorted algebra.

As it is well known, the main syntactic complication in dealing with lambda calculi is thedistinction between free and bound variables. Therefore, if we want to use the usual lambdacalculus syntax, we cannot use the approach of first defining ground terms and then definingterms with variables by simply adding more 'constants' to the signature, as we did in Part Ifor (first-order) order-sorted algebra. Instead, given a set 5, we consider fixed an 5M-sortedset Vs of variables such that for each type r € S* the set Vs,T is countably infinite.

DEFINITION 2.3

Given an hos signature (S*, <M, E), the 5^-sorted set Tj; of hos terms (with variables inis defined as the least 5M-sorted set satisfying the following conditions:

1- Vs.r CT S > T .2. TS,T C TE,T. i fr < V i n 5 M .

3. If a e T,T,T> and t G TE>T, then a{t) € TS ,T ' .

4- <> € T E i l .5. If U € TE,Ti (i = 1,2), then (tut2) € TE,TlXT3.6. If t € TE,TlXT2, thenpi(t) G TE,Tl (i = 1,2).7.1ft e TS)T=>T- and t' G TE, T , then tt' G TEiT-.8. Iff € TS>T. andx G VS<T, then Ax: r.t G TE)T=>r..

We usually do not mention the set of variables Vs.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 4: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

544 Inclusions and Subtypes II: Higher-order Case

PROPOSITION 2.4

Given an hos signature (5M , <*, £) , every term t in Ts has a least type denoted lt(t).

PROOF. TO the cases in the proof of Proposition 2.8 of Part I we need to add the followingcases:

I./<(()) = 1.

2.lt((t1,t2)) = lt(t])xlt(t-2).

3. lt{Pi(t)) = rt (i = 1,2) if lt(t) = n x r2.

4.lt(tt') = T if tt(t) = p=*- r.

5. Zi(Ax:ri) = r =*•/«(*)• •

The definition of free and bound (occurrences of) variables is as usual. We follow the sameconventions as in Part I concerning the representation of terms; however, it is important tonote that now t(x :T):T denotes a term t of type r whose free variables are included in thelist x : T. The substitution t(t'/x) oft' for free occurrences of x in t is also defined as usualin this setting, involving the renaming of bound variables in t in order to avoid the capture offree variables in t'.

When convenient, we will adopt the same conventions with terms as with morphisms, writ-ing ( t i , . . . , tn) and pt(t) (i = 1,. . . ,n) for generalized pairing and projections, respec-tively.

The definition of equation is as for the first-order case in Part I, i.e. an equation comes witha context of typed variables and relates terms whose least types are in the same connectedcomponent of 5M . The rules for equational deduction from a set F of hos equations are Re-flexivity, Symmetry, Transitivity, Congruence and Substitutivity as in Part I, together withthe following rules (where we assume that the hos terms and equations that appear are alwayswell-formed):

Terminal:

Projections: r\-(x :T)P-"*- *-" - * (i = 1 - 2 ) -

Pairing: r u / - • ^\ /„ h

Alpha: , - , . / _ _^ . -, r ./ ; \ where y is not free in t.v Th (x : T) Xx.T.t = Xy.T.t(y/x) y

X i . r\-(x:T,y:p)t = t'

Beta:T\-{x:T){Xx:T.t)t' = t{t'/x)-

Eta: ^n—1- -\ > m 7 where x is not free in t and t : r ^ r ' .F h ( i : T)Xx:T.(tx) = t

The additional condition in the Eta rule concerning the type of t is in order to avoid the fol-lowing situation, pointed out to us by Simone Martini.

Consider two different types a, r with a < T and variables y : a,x : r. Then the termXy : a.(Ax : T.x)y is well-formed and has least type a => r. Applying the Beta rule we getthe term Ay: cr.y with least type (a => a) < (a => T); SO the type has decreased but there isno problem. However, by applying the Eta rule we would obtain the term Ax: r.x with leasttype T =̂ - T which is not in the same connected component as the other types. The restrictionin Eta rules out this last possibility.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 5: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 545

DEFINITION 2.5

An hos theory consists of an hos signature (S*, <M , E) and a set F of hos E-equations.

EXAMPLE 2.6

In Example 2.15 of Part I, we mentioned that using order-sorted algebra we can easily specifya number hierarchy from the positive natural numbers to the quaternions [19], and we showedin particular an order-sorted theory specifying the rational numbers. Using higher-order order-sorted theories, we can furthermore specify higher-order functions involving those numbers.For example, a summation function can take as arguments a function from the natural num-bers to the rationals and a natural number, producing a rational number. Assuming that thespecification of the natural numbers includes a successor operation s_, we have the followingspecification using an OBJ-like notation [16, 20].

hospec SUM i sp r o t e c t i n g RAT .op sum : (Nat => Rat) x Nat -> Rat .var F : Nat => Rat .var N : Nat .eq sum(F, 0) = F 0 .eq sum(F, s N) = sum(F, N) + F (s N) .

endhos

A term well-formed under the SUM theory is sum (AN: Nat. (N / (N + s 0 ) ) , s s s 0) ,which in traditional mathematical notation is written £n=o ^xj -

An hos equation in the same context is

(H:Nat)sum(AN:Nat.N, M) = (M • (M + s 0)) / s s 0,

representing the mathematical formula 5Z^-0 n = M(M+i)

EXAMPLE 2.7

We can also specify higher-order functions involving lists, like for example map and reduce[39, Chapter 11], as follows.2 As we have already mentioned in Example 2.16 of Part I, OBJ-like parameterization mechanisms should be used in order to make these specifications moregeneral; we consider here these functions only in the context of lists of numbers.

The function map takes as arguments a unary function on numbers and a list, and appliesthe given function to each element, producing another list, that is

map(F,[a1,...,an]) =

using the obvious notation for lists. This is the corresponding ML program [39]:

map(F,ni l) = n i lI (F,R::L) = F(R)::map(F,L)

and this is the complete hos theory defining the same function:

hospec LIST-HAP isprotecting RAT .3Although in the general treatment a constant is considered as a unary operation with arity I, we do not write

empty (<>) in the terms appearing in the specification, but prefer the simpler empty.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 6: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

546 Inclusions and Subtypes II: Higher-order Case

sort List .op empty : 1 -> List .

op cons : Rat x List -> List .

op map : (Rat => Rat) x List -> List .

var F : Rat => Rat .

var L : List .

var R : Rat .

eq map(F, empty) = empty .

eq map(F, cons(R, D ) = cons(F R, map(F, D ) .

endhos

The function reduce takes a binary function F on numbers and a list [ 01 , . . . , On], and itsresult is F{a\, F(o2, F(..., F ( a n _ i , On) ...)))• Usually F is assumed to be associative andhave a neutral element (these requirements could be specified using OBJ-like parameteriza-tion), but we do not consider such a case in order to illustrate how the key idea of the exceptionhandling mechanism of ML [30, 39] can be expressed in our framework.

This is the ML program for reduce taken from Ullman's book [39]:

except ion EmptyList;fun r educe (F ,n i l ) = r a i s e EmptyListI r educe(F , [a ] ) = aI reduce(F ,x : :xs ) = F(x, r educe (F ,xs ) ) ;

Note that when the list is empty an exception is raised. In ML, an exception stops the com-putation and is propagated through a term (like error constants in the specification LIST-ERRof Example 2.16 in Part I), unless the exception is explicitly handled. For example, if p lus isthe addition function on numbers, we can define the following ML function

fun sumlist(L) = reduce(plus ,L) handle EmptyList => 0

which sums all the numbers in a list, and if the list is empty returns zero.The following hos theory defines the reduce and sumlist functions under the same condi-

tions. Of course, as we already showed in the order-sorted theory LIST-ERR of Example 2.16in Part I, the arithmetic operations on the rational numbers must be overloaded and extendedto Rat? in order to propagate the exception when necessary. Assuming that the operation +has been so extended to Rat?, we can then define the operation plus used below by meansof the hos equation

plus = AP:'Rat? x Rat?.p!(P)

hospec REDUCE isprotecting RAT .sorts List Rat? .subsort Rat < Rat? .op empty : 1 -> List .op cons : Rat x List -> List .op exception : 1 -> Rat? .

op reduce : ((Rat x Rat) => Rat) x List -> Rat?op handle : Rat? -> Rat .op sumlist : List -> Rat .

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 7: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 547

var F : Rat x Rat => Ratvar L : L i s t .var R : Ratvar R : Rat .eq reduce(F, empty) = exception .eq reduce(F, cons(R, empty)) = R .eq reduce(F, cons(R, L)) = F(R, reduce(F, D )eq handle(except ion) = 0 .eq handle(R) = R .eq sumlis t (L) = handle(reduce(plus ,L)) .

ldhos

In general, an ML term exception E of Type used in a function f : Tl => T2 is in-terpreted by means of a new operation symbol E : Type -> T2? where T2? is a new errorsupertype of T2. Then an ML term of the form

t handle PI => t l I . . . I Pn => t n

where Pi are exceptions in T2? is interpreted as the term handle( t ) for a new operationsymbol handle : T2? -> T2 such that

var X : T2 .eq handle(PI) = t l .

eq handle(Pn) = tn .eq handle(X) = X .

2.2 Higher-order algebras in a Cartesian closed category

Notation: Given a Cartesian closed category3 C, we use the notation 1 for the terminal ob-ject, x for products and iti for projections, as in Part I, with the same conventions for gen-eralized products, pairing and projections; moreover, => is used for the exponential functor,A/i,B,c(f) • A —¥ (B =>• C) for the currying of / : A x B -t C, and evA,B '• {A =>B) x A —> B for the evaluation map. We sometimes omit the subscripts in AA,B,C and

DEFINITION 2.8

An inclusion structure in a CCC C is an inclusion structure J in the category C that, in addi-tion, satisfies the following condition: if j : A -> B is a morphism in J and C is an object,then idc =>• j : (C ^ A) —> (C ^- B) is also a morphism in J.4

We call the pair (C, J) a CCI-category.

For the rest of this section we fix a CCI-category (C,J).

DEFINITION 2.9

Given an hos signature (S*\ <M, E), an hos (S*", <™,Y,)-algcbra in C is an order-sorted (5 M ,<M , S)-algebra A in C such that

'Abbreviated to CCC from now on.4 If j is a raonomorphism, then idc =* J is also a monomoiphism, because the functor C => . is a right adjoint

and therefore preserves limits.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 8: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

548 Inclusions and Subtypes U: Higher-order Case

1. Ay = 1.

2. "TiXrj = AT\ X AT2.

3. J4 T =>T' = AT =>• /1T<.

Given an hos E-term £ and an hos E-algebra A in C, the meaning of t is defined as a mor-phism [t]A in C, inductively on the structure of t. Since an hos term may be constructed inmany different ways, we must prove that [t\A is independent of the construction of t.

DEFINITION 2.10

Given an hos (S*, <M , E)-algebra A in C, the derived operation associated to an hos E-termt(x : T) : T is the morphism [t : r\A • AT —> AT in C defined by the clauses in Definition 3.6of Part I together with the following additional clauses:5

l . I f i = <>, [t:r]A = ()AT.

2.lft = Pi(t') with f : p1 x p?, [t : T]A = [t' : px x p2\A; m.

3. If t = (tuh), wi th U:pi (* = 1 ,2 ) , lt:T\A = {[tl:pl]A,[t2:p2\A).

4 . If t = ft" wi th f : T' => r and t" : T', t hen

[t : T]A = ([t1 : T' ^ r]A,[t" : T']A);evAT,,Ar.

5. If t = XX:T'.f with f : T" and T = T' =$• r", and the variable set i : r is empty, then

[t : r ] ^ = A i , ^ , , ^ , , (7r2; [t'(a: : r ' ) : r " ]^ ) ,

where 7T2 : 1 x AT> —• Ar> provides the expected isomorphism 1 x AT< S AT< (withinverse given by ( O ^ . i d ^ , ) : AT >lx AT-).

6. If t = \X:T' .t' with*' : r " andr = / =>• r", and the variable set x : r is not empty, then

[t(x : r ) : r j ^ = hAr,AT.,AT..(\t'& -r^-.T1): T")A).

As expected, most proofs are by structural induction adding all the cases in the previousdefinition to the cases already considered in the order-sorted setting. Most calculations arestraightforward and we only display one or two cases to give the general feeling of the proof.

Again, as in the first-order case, it is important to realize that [t] does not depend on thenames of the variables that appear in t, but only on their types, because variables are just pro-jections. Therefore, satisfaction of the Alpha axiom will be trivial.

LEMMA 2.11

Given an hos E-algebra A in C and an hos E-term t,

[t:T]A = [t:lt(t)]A;Alt{t)<T.

Therefore, the meaning of t is independent of the construction of t.

PROOF. We need to add several cases to the ones in the proof of Lemma 3.7 of Part I. Thecases t = (), t = Pi{f), and t = (ti, i2) are left to the reader.

B As in Definition 3.6 of Part I, [t : T]A depend* on a context x : ? of free variables for the term t(x : T) : rwhich is left implicit

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 9: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 549

If t = ft" with lt(t') = p => r ' < p => T and t" : p,

([«' : p => T], AP^T.<P^T, [t" :p]);ev =

<[*' = P => T 1 ] , [t" : pi); ( X P = > T . < P = > T X idAf); ev =

([? • P => T ' ] , [«" : p]>; ((.d^i, =• i4T.<T) x idAp)-evAn,Ar =

([t':p=>T'l[t":p]);evAl,,AT,;AT.<T =

[t:lt(t)];Am<T.

If t = Xx : p.t' with T = p ^ T' and /t(i') = f < r7, and the variable set i : r is notempty,

[t(x:T):T] = AA_Ap<AT,([t'(x:r,x:p):T']) =

A A T , A p , A ( ( [ t ' ( x : T , X : p) :

A{[t'{x : r , x : p ) : ^ ] ) ;

[ t : l t ( t ) ] ; A u { t ) < r -

The case in which the variable set x : r is empty is similar. I

PROPOSITION 2.12

Given an hos S-algebra A in C and hos terms ti(yi : pi,...,yk '• Pk) '• n (i = 1 , . . . ,n)and t'(xi : T\,..., xn : rn) : r ' , we have

[t'(t/x) : T] = ([ti : T J , . . . , [tn : TB]>; [i' : r'J : i4Pl x . . . x APL —y AT,.

PROOF. TO the cases in the proof of Proposition 3.8 of Part I we need to add the followingcases: t' = (), t' - p,(t"), ? = (t[,t'2), t' = uv, and t' = \z : f.u. We only considerthe last case, where we can assume that z does not appear either in u or in the variable list(x : T,y : p), because the meaning of terms does not depend on the variable names. Then,we have

AA-A(tATl([uCt/x)(y:p,z:O]) =

A([u(t/xtz/z)(v:p,z :£)]) =

A«[*i(» :p,z: 0], • • •, [UV ••?,*•• O)MV ••?,*•• 0]>;I«(x : r,z : 0 ] )

A ( ( ( T T I , . . . , 7Tfc); [ < ! ( y : p ) ] , . . . , ( n x , . . . , 7i>); [ t n { y : )5)] , n k + 1 ) ; [u(x : T , Z :

<[*i], • • •. [*nl>; ^AT,At,AT, ([n(x :T,Z: 0 ] ) =

Note that if the variable set x : r is empty, the equation to be proved becomes trivial. I

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 10: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

550 Inclusions and Subtypes II: Higher-order Case

The definition of satisfaction of an equation by an algebra is exactly as for the first-ordercase, and then we have the following result.

PROPOSITION 2.13 (Soundness)Let (S*\ <" , E,T) be an hos theory and A an hos (E, r)-algebra in C. If T h (x : T) t = t',then A (= ( i : r) t = t'.

PROOF. TO the cases in the proof of Proposition 3.13 of Part I we need to add the followingcases.

Terminal: [(> (x : 1)] = <)i = tdi = [x(x: 1)].

Projections: foi((*i,ta»] = ([h], [ ia ] ) ;^ = [t,].

Pairing: [(pi(t),«»(*)>! = <M;*i,M;w2) = W i ^ i . ^ ) = [*].Alpha: We have already pointed out that the meaning of terms is independent of the variable

names, because variables are projections.

Xi: Obvious.

Beta: {(x : T) not empty}

[(Xx:T.t)t'(x:T)] = (A([t(x:T,x:T)]),[t!(x:f)])]ev =

(id,[t'(x:r)]);[t(x:T,x:T)] =

( T T X , . . . , 7Tn, [f (x : T ) ] > ; [ t ( x : T , x : r)] =

[t(x/x,t'/x)(x:r)] =

[t(t'/x)(x:r)].

{(x : T) empty}

[(Xx-.T.t)t'] =

Eta: {(x : r) not empty}\Xx:T.{tx) {x : T ) \ = A { [ t x ( x : r , x : r ) ] ) =

A ( ( [ t { x : T,X:T)],[X{X :T,X : r ) ] ) ; e

A(((7Ti,..., 7rn>; [t {x : T)] ,7r n + i ) ; ev)

A(([t(x:T)]xid);ev) =

[t(5:r)].

{(5:r) empty}

[\x:r.(tx)] = A{n2;[tx(x:T)]) =

A(ni;([t(x:T)l[x(x:T)]);ev) =

A(7ra;«>;[t],td>;e«) =

A((It]xtd);«;) =

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 11: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes Q: Higher-order Case 551

We have not yet defined the notion of homomorphism for hos algebras. Intuitively, an hoshomomorphism should be an order-sorted homomorphism that, in addition, preserves the newoperations on terms. There is no problem with products or application; however, lambda-abstraction requires making reference to arbitrary terms.6 Following a suggestion of ValBreazu-Tannen, we present below an equivalent—yet more compact—formulation of our def-inition in terms of combinators [22,29]. Of course, together with the classical combinators Kand S, we must use combinators corresponding to projections, pairing, and operation symbolsin a signature.

DEFINITION 2.14

Given an hos signature (S*, < * , E ) , the family of (5 M , <* ,T,)-typed combinators, or simplyY.-combinators, is defined as follows:

KP'T = Xx:p.Xy.T.x

5^,P,T _ \x:£ =j> ( r ^ . p).Xy:f => T.Xz:£.(xz)(yz)

PP'T = Xx:pxr.pi(x)

P^'T = Xx:p x T.p2(x)

Ep'T = Xx:p.Xy:r.(x,y)

F£'T = Xx:p.o(x), for each operation symbol a 6 EPiT .

FACT 2.15

Given an hos E-algebra A in C, it is routine to follow Definitions 2.10 and 2.14 in order tofind that the derived operations associated to the E-combinators, in the empty variable set, arethe following (omitting the type information for brevity):

[S]A =[Pi]A = A(7T2;7r,) (i =

[E]^ = A(7T2;A(td))

DEFINITION 2.16

An hos term t(x : T) : r in T^ is said to be in combinatory form if it falls in one of thefollowing cases:

1. If t is (), a variable or a E-combinator, then it is in combinatory form.2. If t : T' is in combinatory form, and r' < T, then t: T is in combinatory form.

3. If t' : T' => T and t" : r1 are in combinatory form, then t't" : r is in combinatory form.

DEFINITION 2.17 ([22,29])

Given an hos term t : r in combinatory form and a variable x : p, the abstraction of t : r withrespect to x : p is the term in combinatory form (x : p)t : p •=$• T defined as follows:

1. (x : p)t = KT>pt if the variable x is not free in t.

6 More precisely, we need a condition stating that on hos E-homomorphism h must satisfy for any hos D-termt(x : r , y : p) : T the equation (/»r, x . . . x /»,•„); A([t : T]B) = A([t : T ] A ) ;/!,,=> T .

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 12: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

552 Inclusions and Subtypes II: Higher-order Case

2. {x : p)x =3. (x : p)t't" = {Sp*'T(x : p)t')(x : p)t" if t = ft" with t' : £ =>• T and t" : f, and case 1

does not apply.

LEMMA 2.18

For any hos term t(x : 7) in combinatory form,

h (x : T)(X : p)t = Xx.p.t.

PROOF. Omitting the type information in terms and combinators for brevity, we have:

1. Kt = (Xy.Xx.y)t - Xx.t.2. (SK)K = {{Xy.Xz.Xx.(yx){zx))K)K = Az.(Kz)(Kz) = Xx.x.3. (5(x)t')(x)t" = (S(Xx.t'))(Xx.t") = ((Xy.Xz.Xx.(yx)(zx))(Xx.t'))(Xx.t") =

Xx.((Xx.t')x)((Xx.t")x) = Xx.t't". I

PROPOSITION 2.19

Given an hos term t(x : 7) : r in T E , there is an hos term in combinatory form tc(x :T):Tin T E such that I- (x : r) t = tc.

PROOF. By induction on the structure oft, we have the following cases (where we generallyomit the type information for brevity):

t = x

t.T1 <T

t = a{f)

t=Pi(f)

t=(f,t")

t = ft"

tc

tc

tc

tc

tc

tc

= X

: T '

= F

= p

= *:

°tc

t":lc

t = Xx:p.f tc = (x:p)fc.

Using induction and Lemma 2.18, it is easy to check that h (x : 7) t = tc. I

DEFINITION 2.20

Let (S"", <M , E) be an hos signature. Given two hos E-algebras A and B in C, an hos E-homomorphism h : A -> B is given by an S^-sorted family of morphisms h = {hT : AT ->BT | T 6 S™} in C such that

1. If T < T1, hr\BT<T< = AT<T<\hT, : AT -T BT..

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 13: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 553

2. ftrlXT,;ii = iTi;hTi (i = 1,2) (equivalently, hTl*Tl = hn x

TI X

BTl X B r 2 -

3. ,,AT;hT (equivalently,hp=>T;(hp => idBr) = idAi, => hT).

(Ap => AT) x Ap ^ AT

(Bp => BT) x Bp- ev

K

BT

4. For any E-combinator C of type rc, [C : TC]A ; hTc = [C : TC]B •

[C TC]A

[C r c ] B

This defines a category denoted HOSAlg(C, J) and, for each set F of hos E-equations, afull subcategory HOSAlg(C, J) defined by those E-algebras that satisfy T.

If each hT is an isomorphism, then hpz>T = h~l => hT; in this case, a homomorphism iscompletely determined from its components at basic types s € 5. This is the very particularcase of higher-order many-sorted algebra studied by Pitts in [34] and Crole in [11]. That thedefinition given above, besides being fully general, captures the somewhat evasive notion ofhigher-order homomorphism is attested to by the following lemma.

LEMMA 2.21

Given an hos homomorphism h : A -> B between two hos E-algebras A and B in C, and anhos E-term t(x : T) : T, we have

( / i r , x . . . x h T J ; [ t : T ] B = l t : T ] A ; h T .

PROOF. Because of Propositions 2.19 and 2.13, for each hos term t there is an hos term tc incombinatory form such that [t] = [tcj; therefore, it is enough to prove the lemma for termsin combinatory form.

The basic cases forcombinators, variables and () are all obvious from the definition of hoshomomorphism. Now suppose that hy, fit' : p =J> T]B = [f '• P => T]A; hp=>T and /i-; \t" :

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 14: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

554 Inclusions and Subtypes II: Higher-order Case

P\B = [t" '• P]A', hp, where we write /i^for hTx x ... x hTi%. Then, we have

hr\ [ft" :T]B = hr, {[t']B, [t"]B); evBp,Br =

(hr,[t'h,hT;[t"]Bhev =

,[*"]>i>;(/ip=*r x hp);evBl,,BT =

,[t"]A);evAftAT;hr =

[t't"lhT. I

COROLLARY 2.22

As a particular case of this lemma, we get hT; BTa'

T' = ATa'

T'\hT> for a € ET|T ' , becauseAT

a'T' = [o(x) (x : T)]A and analogously with B. Therefore, an hos E-homomorphism h :

A -> B is an order-sorted E-homomorphism between the underlying (5M , <*, E)-algebras.

It is interesting to compare our definition of higher-order homomorphism, when interpretedin categories whose objects are sets, with the notion of logical relation [35, 31]. On the onehand, we are interested in functions instead of relations, and from this point of view our notionof homomorphism is more restrictive than that of logical relation. On the other hand, the com-ponents of a logical relation at higher types are completely determined from the componentsat basic types, whereas in our approach this does not hold, except in very particular cases as,for example, the already mentioned one in which all the components are isomorphisms; in thissecond regard, our notion is less restrictive. Theorem 2.27 below will give further evidencethat our notion of homomorphism is very natural, by showing that in the functorial semanticshomomorphisms exactly correspond to natural transformations.

2.3 Classifying categories for hos theoriesDEFINITION 2.23

A CCI-functor F : {C,J) —> (C',J') between CCI-categories (C,J) and (C ' , J ' ) is afunctor F : C —> C that preserves the Cartesian closed structure 'on the nose'7 and suchthat F(J) C J'.

We denote by CCI{(C,J),{C',J')) the category whose objects are CCI-functors between(C, J) and (C, J') and whose morphisms are natural transformations between such functors.

With this definition, we have the following results.

PROPOSITION 2.24

Let F : (C, J) —>• (C, J') be a CCI-functor. Then,

1. As in Proposition 3.15 of Part I, application of F defines a functor

F* : HOSAlg{C,J)r —> HOSAlg{C'tJ\.

2. If A is an hos E-algebra in C, and t(x : r) : r is an hos E-term,

[t:T]F*A=F{[t:T]A).7This means that F preserves finite products 'on the nose' and, moreover, F(A => B) — F(A) => F(B) and

F(evA,B) = "T(/»),F(fl)- Then, one deduces also that F(AA,B,c(f)) = A-F(A),FiB),F(C)(F(f))-

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 15: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 555

3. Given an hos theory (S, <, E, F), F* restricts to a functor

F* : HOSAlg(C,J)rr —> HOSAlg(C',J%x.

PROOF. Since F is aCCI-functor, if A is an hos E-algebra, then F*A is also an hos E-algebra.Then, one easily proves [t : T]F -A = F([t : T]A) as in Lemma 3.16 of Part I. This equationis needed to prove that if h : A -» B is an hos S-homomorphism, then F*h is also, becauseof the condition concerning preservation of combinators in Definition 2.20: if [C : r c j s =[C : Tc]A;hTc, then F([C : r c]B) = F([C : TC]A);F{hrt); equivalently, [C : r c ] F . B = [C :TC]F-A; (F*/I)T C , as desired.

Because of 2, F* preserves satisfaction, and we get the result in 3 as in Proposition 3.17 ofParti. •PROPOSITION 2.25

Let (C, J) and (C, J') be two CCI-categories and let A be a (S, F)-algebra in C.

1. For TJ a natural transformation between CCI-functors F, G : (C,J) —> (C',J'),\hefamily r]A = {T)AT : ^(^4,-) -> G(ylT) | r £ 5M} is an hos E-homomorphism betweenF*AandG*AinC.

2. The assignments F i—^ F*A and r? i—> r)A define a functor

A" :

PROOF. AS in Proposition 3.18 of Part I, the conditions for r]A being a homomorphism areinstances of the naturality of r?. I

DEFINITION 2.26

Given an hos theory T = (S*, <*, E, T), a CCI-category (C, J ) is called a classifying cat-egory of T if there is an hos E-algebra G in C, called a generic algebra, such that for anyCCI-category (C, J ' ) the functor

),(C',J')) —> HOSAlg(C',J')vx

is an isomorphism.

Classifying categories for an hos theory are, as in the first-order case, unique up to isomor-phism and we can speak about the classifying category of T, denoted Cb

T, and the genericalgebra of T, denoted G^.

THEOREM 2.27 (Existence of classifying categories for hos theories)Given an hos theory T = (SM, <M, E, F), there exist a classifying category Cb

T and a genericalgebra G^.

PROOF. The proof follows the same steps as the proof of Theorem 3.22 of Part I.

1. The category C\- is constructed as follows:Objects: Elements of S".Morphisms: Morphisms with domain r and codomain T1 are generated by hos terms t(x :

T) : T \ subject to the equality relation

t(x : T) :T' = t'(y : r) : r ' <=• F h (x : T) t = t'(x/y).

Thus, except for the variable names, a morphism with domain r and codomain r7 is anequivalence class [t(x : r)] together with the specification of its domain and codomain.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 16: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

556 Inclusions and Subtypes II: Higher-order Case

Identities: The identity for r is given by [x(x : r)] : r —» r.Composition: The composition of [t(x : r)] : r —> p and [t'(y : p)] : p —)• f is given by

the substitution

Products: The terminal object is 1, and the unique morphism from r to 1 is

The product of ri and T2 is T\ x T2 . Projections are of the form

[pi(i) ( i : Ti x r2)] : fa x T2) -> Ti (t = 1,2).

Given [U (x : p)\: p -* Ti (i = 1,2), the induced morphism is

[(t1,t2)(x:p)\ : p - > ( n x r 2 ) .

Exponentials: The exponential object of r and r ' is r =*• r ' . The evaluation map (rT7) x r —>• T7 is defined by

[pi(a;)P2(a;)(a;: (T =^ T') X T)].

And currying of [t (x : r x r')] : ( r x r ' ) -> p is the morphism

Inclusion structure: Morphisms in j \ are of the form [x(x : r)] : r -> T' for T < M T'in5 M .

It is routine to prove that the previous construction defines a CCI-category. The most in-teresting part is the proof that the definitions above indeed provide an exponential object.First, given [t(y : r)] : r -> p and [t'(z : T')] : r ' ->• p', the morphism [t(y : r)] x [i'(z :T')] : (r x T') —>• (p x p') is given by

[{t(p1(x)/y),t'ip2(x)/z))(x:rXT')}.

Now, given [t(x : p x r)] : (p x T) —• T', we have to prove

(AP,T,r'([t(a; : P x T)]) x tdT);euT,T' = [<(a; : p x T)] (f)

equivalently/,z>/a;)] x [w]);\p1(a)p2(a)} = [t]

or[(Az:r.t({p1(a;),z)/x),p2(x))];bi(a)P2(a)] = [t].

Let's calculate:

p1((Az:r.t({p1(i),2)/x),p2(a;)))p2((Az:r.t((Pl(x),z)/i),p2(a;))) =

{Projections} (Az:T.t({pi(i),z)/a;))p2(a;) =

{Beta} t((p1(x),z)/a;)(p2(i)/z) =

t((Pl(x),p2(x))/x) =

{Pairing} t(x/x) = t.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 17: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 557

Uniqueness of A([i\) with respect to the property (f) is shown as follows. Suppose that[t'(y : p)] : p -* (r => T') also satisfies (f); then,

that is, using the Projections rule,

Applying the substitution x >-> (y,z) and the Projections rule, we get

r\-(y:p,z:T)(t'(y/y))z = t{(y,z)/x),

and by the Xi rule,

T\-(y:p) \z-.T.(t'z) = Xz:T.t((y,z)/x).

Finally, the Eta rule gives the desired equation

r\-(y:p)t' = \z:r.t((y,z)/x).

2. The generic algebra G^ is defined by:(a) (G^)T = T.

(b) {G'YS = [o{x) {X:T)):T-+ T ' .

( c ) ( G ^ ) T < T - =[X(X:T)] -T^T1.

The monotonicity condition is again trivial.It is routine to prove that

[t(x : T) : T]G>T = [t(pi(x)/xi,.. .,pn(x)/xn) (x : n x . . . x rn)],

by induction on the structure oft. For example,

[Xz:p.t(x:r)] = A([t (x : T,Z : p)\) =

M[t(pi(y)/xu- • • ,Pn(y)/xn,pn+i(y)/z)]) =

[\z:p.t(pi((x,z))/xi,... ,pn((x,z))/xn,pn+1({x,z))/z)] =

[\z:p.t(pi(x)/xu.. .,pn{x)/xn,z/z)} =

[(Xz:p.t)(pi(x)/xi,.. .,pn(x)/xn)].

Therefore, G^ satisfies all of the equations in F.

3. We define a functor (.)• : HOSAlg{C,J)^r —> CCI((CbT,J^),{C,J)).

Given an hos (E,r)-algebraBinC,thefunctorB# : £ ^ —¥ C is defined by B*(r) = 5 T

and B'([t(x : T)] : T -> r ' ) = [ t ( i : r ) : r ' ] B .B* is well defined on morphisms because B is a (E, r)-algebra, and it is a CCI-functorbecause of Definition 2.10 and Proposition 2.12.A homomorphism h : B -> C gives rise, by Lemma 2.21, to a natural transformation h'between B* and C, defined by h* = hT : BT —> CT.

4. Finally, the functor (G^)" : CCI((CbT, j | ) , (C, J)) —> HOSAlg(C,J)^, „ is an iso-

morphism, with inverse (_)• as in the proof of Theorem 3.22 of Part I. I

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 18: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

558 Inclusions and Subtypes II: Higher-order Case

PROPOSITION 2.28 {Completeness)Given an hos theory T = (S", < " , E, T),

GiT\={x:7)t = t' <=> V\-{x:7)t = t'.

PROOF. For the direction (•$=) use soundness (Proposition 2.13).For the direction (^>), by definition of satisfaction, Gb

T \= (x : T) t = t' iff [t : r]Gk =[t' : r ] G k for r a common type oft and t'\ this is equivalent to

x)/xt) (x-.T1x...XTn)] = [t'(pi(x)/xt) (x : n x . . . x rn)]

as morphisms in CbT. Hence,

r h (i : TI x . . . x rn) t{pi(x)/xi) = t'(pi(x)/xi).

Therefore, using the substitution x i-» ( i i , . . . , xn) and the Projections rule, we get

r\-{x1:n,...,xn:Tn)t = t'. I

PROPOSITION 2.29

Given an hos theory T = (S" , <", E, T), the category FunctHOSAlg^ p has as objects (XI-

functorsF : (CbT,J^) —>• (C, J ) (i.e. hos (S,r)-algebras in any CCI-category); a mor-

phismfromF : (£ bT , j£) —> ( C J ) t o F ' : (£ b

T , J r ) —» (C'.J"') is a CCI-functor/f : (C, J) —»• (C, J ' ) such that F ; F = F ' . Then, the CCI-functor 1 ^ corresponding to

the generic algebra G^ is initial in FunctHOSAlg- _.If we consider the category GrolHOSAlg^ „ with the same objects as PunctHOSAlg^, „,

but with a morphism from F : (CbT,J^) —>• ( C , J ) t o F ' : (Cb

T,J$,) —> (C',J') givenby a CCI-functor H : (C, J) —> (C, J') together with a natural transformation 6 betweenF ; H and F ' , then the CCI-functor lci corresponding to the generic algebra G^T is weaklyinitial in GralHOSAlg^ _.

2.4 Adjunction between theories and categories

As in the order-sorted case, given a small CCI-category (C, J) such that J is locally filtered,we can define an hos theory T^ such that C is (equivalent to) the classifying category ofBeforehand, we need to decompose morphism domains and codomains taking into account theadditional Cartesian closed structure of the category, and we have to reformulate the notionof regular family and labelling in this setting.

DEFINITION 2.30

Given a CCC C, there is an interpretation function |.| : Ob(C)™ —> Ob(C) obtained byinterpreting the formal operations x and =>• in Ob(C)M by the corresponding operations in thecategory C.

For each pair T,T' of elements of Ob(C)M and each morphism / : \T\ -* \TJ\ in C we denoteby /T,T' the morphism / in C together with the 'decompositions' r of its domain and r7 of itscodomain. We denote by DCMor(C) the collection of such morphisms.

Given a small CCI-category (C, J), the order < j in Ob(C) extends to < ^ in O6(C)M; no-tice that when r < ^ r ' in ObiC)1*, then there is a morphism j : \T\ -»• | r ' | in J.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 19: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 559

DEFINITION 2.31

Given a small CCI-category (C, J), a family of morphisms T C DCMor(C) is CCC-regulariff it satisfies the following conditions:

1. If/T,T' andgp^ are morphisms in T and r <* p(withji : |r | -> |p| in .7), then r ' <* p'(with j ' : | r ' | -> \p'\ in J7) and moreover j ; g = f;j'.

2. Given p, T G Ob^)1*1 with p < * T and a morphism /T|T- in 7", the set

{£ 6 O6(C)" \p<$Z and 3gu. € ^ }

has a minimum with respect to the order <* .

DEFINITION 2.32

Given a small CCI-category (C, JT), a CCC-labelling for it is given by a set E and a functionI : DCMor(C) -4- E such that for each a G E the family l~^(o) of morphisms is CCC-regular.

A small CCI-category (C, J) such that J" is locally filtered together with a CCC-labellingI for it is called an LCCI-category.

THEOREM 2.33

Given an LCCI-category (C, J, I : DCMor(C) -t E), there exists an hos theory T^ such thatC is equivalent to the classifying category £ ^ of T^.

PROOF. The hos theory 7^ = ((5, <) , S*\ <>\ E, T) is given by:

Sort Poset: Basic types are the objects of C, ordered by J.

Operation symbols: For each a € E and morphism /T)T- in l~1(a) there is an (overloaded)operation symbol a € £T,T '. The monotonicity and regularity conditions hold becausel~1(cr) is a CCC-regular family.

Equations: All the E-equations satisfied by the hos E-algebra D£. in C that assigns to eachtype T the object \T\ and to each operation symbol a £ ETjT< corresponding to a morphism/T>T< with l(fT,T') = cr the morphism / : \T\ -¥ |r ' | .

By Theorem 2.27, we have a CCI-functor

F = fc ^

defined by F ( T ) = |r | and F([« (a; : r)]) = [ t ] D k .

The 'inverse' functor is G : C —¥ £ L defined by G(A) = A for an object A in C and

G(/ ) = [/(//i,s)(x)] with i : A fora morphism / : A -t B in C.The functor G; F is the identity on C. Although F ; G is not the identity functor, because

G(F(T)) = G(|r|) = |T|, there is a natural isomorphism given by:

[l(idrtH)(x){x:T)]: T —> |r|

[^ | r | . r ) (»)( t fM)]: |r| - > r. B

DEFINITION 2.34

A morphism # between two hos theories T = (5M,<M, E,T) and V = (5/M, <'*, E',T')consists of

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 20: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

560 Inclusions and Subtypes II: Higher-order Case

1. a monotone function H : (5, <) -4 (5 ' , <'), freely extended to H™ : (S",<™) ->(S ' " ,< | M ) ,

2. a function / / : S -> E' such that, if a G ET|T-, then i/(cr) € E ' H M ( T ) H M ( T , ) ,

such that, if (a? : r) £ = (' is an equation in F, the equation (x : H™(T)) H(t) = H(t') isderivable from F", where //(<) denotes the 'renaming' oft induced by H.8

In this way we have a category denoted HOSTh.

DEFINITION 2.35

An LCCI-functor between LCCI-categories (C,J,l : DCMor(C) -> E) and (C, J ' , / ' :DCMor(C) -» E') consists of a CCI-functorF : (C)V7) -> (C, J ' ) and a function </>: S -^E' such that for all fT<T> in DCMor{C),

where F M : O6(C)M —Y ObiC')™ is the free extension of the object part of F, satisfying|F M ( r ) | =F(\T\) because F is a CCI-functor.

This defines a category denoted LCCICat.

PROPOSITION 2.36

The assignment of the hos theory T\ to an LCCI-category (C, J, I : DCMor(C) ->• S) ex-tends to a functor

Tb_ : LCCICat —»• HOSTh.

PROOF. Let (F,<j>) be an LCCI-functor from (C,J,l : DCMor(C) -> E) to (C',J'J' :DCMor(C) —t S'). We have already mentioned how the object part of F (which is a mono-tone function with respect to the orders provided by the inclusion structures) extends freely toF M : Ob{C)™ —> Ob(C')", satisfying |F" ( r ) | = F ( | T | ) .

The action of the theory morphism TV on operation symbols is simply given by the function

Then, for an hos term t, {Tp(t)]Di = F([i\D*) and this implies that if D^ satisfies an

equation (x : s)t = t', the 'translated' equation (x : TF(S))TF(t) = Tp(t') is satisfied by

THEOREM 2.37

The construction of the classifying category CbT for an hos theory T is free with respect to the

functor T^ : LCCICat —> HOSTh. Therefore, we have a functor

£b_ : HOSTh —> LCCICat

that is left adjoint to T\

PROOF. The proof is essentially analogous to that of Theorem 3.33 in Part I. To see that, givenH :T -> Tc> the LCCI-functor/ft : Cb

T —>• C is completely determined, one needs to checkmore cases due to the extra structure in terms; for example,

HH[tt']) =

(HH[t}),HH[t'}));ev.8ThU renaming is defined by H(x) = x, H(a(t)) = H(a)(H(t)), H(p{(t)) - Pi(H(t)), H(\x : r.t) =

Xx:HK(T).H(t), etc.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 21: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes U: Higher-order Case 561

In general, by defining #*([£]) = [ # ( 0 ] D C . one checks that H^ satisfies all the requiredproperties. I

The discussion at the end of Section 3.3 of Part I about the simplifications—expressed as acommutative diagram of adjunctions—that are possible for the above correspondencebetween theories and categories in the case of disambiguated theories also applies here, mu-tatis mutandis.

2.5 Conservativity of higher-order order-sorted logic over its first-ordercounterpart

It should be clear that order-sorted theories are a particular case of hos theories; there is asmall point, however, that must be clarified, due to our presentation of hos signatures withonly unary operation symbols. The idea is of course to encode n-ary operations in an order-sorted theory (whose language does not include products explicitly) into unary operations inan hos theory by means of products (that form part of the types).

We define a mapping that, given an order-sorted signature (S, <, E), produces an hos sig-nature ((5, <), S™, <M, Ep). Thus, an operation symbol a € £Sl...«,,,s is mapped to an oper-ation symbol ap € E p

i X ...XSn , ; in particular, in the case of a constant a £ Ee,,, ap € Ep .The rest of the sets in Ep are empty.

Also, an order-sorted E-term t(x : s) : s is mapped to an hos Ep-term tp as follows: ift = Xi thentp = Xi\ in the case of a constants = athen£p = crp(());andif£ = o{h,... ,tn).

Since all the rules of order-sorted equational deduction are also rules of hos equational de-duction, the following lemma is straightforward.

LEMMA 2.38

If F is a set of order-sorted E-equations and r h ( i : s ) ( = (' using order-sorted equationaldeduction, then Fp 1- (x : s) tp = t'p using hos equational deduction, where Fp is the set ofhos Ep-equations {(x : s) tp - t'p \ (x : s) t = t' € T}.

PROPOSITION 2.39

The assignment(S, <, E, r) —> ((5, <), S", <*, E", Tp)

extends to a functor (_)p : OSTh —> HOSTh.

PROOF. Let if : ( S , < , E , r ) —¥ ( S ' , < ; , E ' , r ; ) be a theory morphism in £>£2Vi- ThenH : (5, <) -> (5 ' , <') extends freely to H™ : (5M , <") -> (S'M, <'M) and we let Hp = Hon types.

Assume that a G E5l...,„,,; then, on the one hand, ap G Ept x . . . x , n y , on the other hand,

H{a) € S'H ( 8 i ) . . .H ( S i i ) i / / ( , ) . 'Hence,//(a)p £ ^{ai)x,..xH(Sn)tH{t) "and we define Hp(ap)

= H(a)p e £ ' ^ M ( , I X . . . X I B ) , H « ( , C

Let (x : s) tv = t'p be an hos equation in Fp . We must prove

T'p I- (x : H(5)) Hp(t") = Hp(t'p).

Since H isa theory morphism in OSTh and (x : s) t = t' is an order-sorted equation in F,we have F' h (x : H(s)) H(t) = H(t'); from this, by Lemma 2.38, we get

Vp I- (5 : H{1)) H(t)p = H(t')p,

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 22: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

562 Inclusions and Subtypes II: Higher-order Case

which is the desired result because HP{V) = H(t)p for all E-terms t. I

We are going to prove the converse of Lemma 2.38 by means of a semantic argument, thusobtaining a conservativity result. Given a E-algebra A in a CCI-category, we extend it to aEp-algebra Ap by defining

2. A\ = 1.

An operation symbol a 6 £«,...«„,, is interpreted as a morphism

A"'* -A x v A * A

On the other hand, at the higher-order level, we have ApjX x,n = ASl x . . . x A5ii, and the

semantic interpretation of ap G Epi X XlJti s is defined as ./!£,, = A*'5 : ^p

l X . . .x«H —> -4?-The constant case is handled similarly. In this situation, it is easy to see that [i]^ = [fj^i-and consequently that A (= (a; : s) t = t' iff A p \= (x:s)tp = t'p.

With these notions, we are ready for the main result:

THEOREM 2.40

Higher-order order-sorted algebra is a conservative extension (modulo (_)p) of order-sortedalgebra, i.e. given a set F of order-sorted E-equations, we have

r\-(x:s)t = t' <^> r p h (x : 5) tp = t'p.

PROOF. The direction (=>) is Lemma 2.38.For the direction (<=), assume Fp h (x : s)tp = t'p and consider the (E,F)-algebra

TE,V (X '• s) in ($£t, Incl) (see comments after Theorem 2.13 of Part I and the paper [ 19] fora detailed construction of this algebra).

By the reasoning above, 7s , r (^ : s)p is an hos (Ep, Fp)-algebra, and by Proposition 2.13,

n,r{x:s)p\={x:s)tp = t'p.

Again by the reasoning above, this is equivalent to

Tz,r{x:s))=(x:s)t = t'

and, by (the comments after) Theorem 2.13 of Part I, this is equivalent to F h (x : s) t — t',as desired. I

We can summarize this section by saying that we have defined a map of logics

OSEqtl —> HOSEqtl

between order-sorted equational logic and higher-order order-sorted equational logic in theprecise sense of [27] and, in addition, we have proved that this map of logics is conservative.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 23: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 563

2.6 Retracts

Given that in higher-order order-sorted algebra the typing of a term can range along a varietyof subtypes, and that functions can have subtype polymorphism, this type discipline is inher-ently more flexible than the typed lambda calculus that it generalizes.9 However, there maybe expressions which strictly speaking cannot be typed because the least type of a subterm istoo big, but that are nevertheless worth giving the benefit of the doubt because reduction ofsuch a subterm can decrease the type and produce a well-formed term. For order-sorted alge-bra this has been achieved by enlarging the original signature with additional operators called'retracts* that fill such typing gaps [15, 19] and has been implemented in the OBJ2 and OBJ3systems [14,16,20]. Under very mild conditions, such an extension with retracts is conserva-tive and permits evaluating a dubious term in such a way that if the term was really meaningfulthe retracts will disappear; however, if there was an essential gap, a retract will remain pro-viding a very informative error message. In this way, a very nice capability for runtime errorrecovery is obtained, and the typing flexibility is greatly increased while still remaining ableto discard truly nonsensical expressions such as the division of a Boolean value by a numberwhich will not type even when retracts are added. This section shows that all the nice resultsalready known about retracts at the first-order level do indeed generalize to higher-order, mak-ing the same techniques available in this more general context.

Consider for example the order-sorted theory for lists of numbers LIST in Example 2.16of Part I, whose signature £ includes sorts L i s t for lists and NeList for non-empty lists, aswell as operation symbols empty G E f ,LiBt ,cons € E»atLi»t,H.Li«t. head e £n.Li«t,ii«t. andt a i l € Eg.Li.t.Liit- Then, the term

head( ta i l (cons(0 ,cons(1 ,empty) ) ) )

is not well-formed because head has arity NeList while the subterm

ta i l ( cons (0 ,cons (1 ,empty) ) )

has sort Lis t , despite the fact that the entire term is completely meaningful.

DEFINITION 2.41 (Goguen and Meseguer [19])Given an order-sorted theory T - (S, S, T), we define a new theory T® = (5, E®, T®) byenlarging £ with new operation symbols »>,, £ E® for s < s' and s / 5', called retracts,and by adding to V corresponding retract equations

(x : s) r 8 > ( z ) = x.

In the example above, the term considered can be well-formed by inserting the retractn.i»t,n«Li»t. obtaining head ( r L i , t i B . U B t ( t a i l ( cons (0 , cons ( l , emp ty ) ) ) ) ) . We thenhave the following reduction sequence

head(rLiBt,H.u.t (tail (cons (0, cons (1, empty) ))))->-+ head(rLi5t,H.Liit(cons(1,empty))) ->

—> head (cons ( 1 , empty)) —> 1.

We refer the reader to the paper [19] for more details and motivation about retracts.The main result in [19] concerning retracts is thatT® is conservative overT, in the follow-

ing sense:

9Similarly, adding subtypes to richer calculi does result in more flexible type disciplines.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 24: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

564 Inclusions and Subtypes II: Higher-order Case

DEFINITION 2.42

Given order-sorted theories T - (S, <, E, T) and V = ( S \ < \ E', V) such that T is in-cluded in T" (i.e. (5, <) is a subposet of (S1, <'), E ? i , C Y,'la for s G 5* and s £ S, andF C r"), we say that T" is conservative over T iff for order-sorted E-terms t and t' (and there-fore also E'-terms),

r\-(x:S)t = t' < = ^ r'\-(x:s)t = t'.

The definition is completely similar for the case of hos theories.

PROPOSITION 2.43

If T is included in T", we have an inclusion morphism J : T -t T" in OSTh: this morphismgives rise to a functor Cj : CT —> Cv mapping a morphism [t]z,r in C-T to [i]£',r' inCT1 • Then, T" is conservative over T iff the functor Cj is faithful. (The same holds for thehigher-order case.)

PROOF. Given E-terms t and t', we know by Proposition 3.23 of Part I that T h (x : s) t = t'iff G r f= (x : s) t = t', that is, iff [t]j;,r = [*']E,r as morphisms in CT', with this, it is veryeasy to see that the conservativity condition is equivalent to faithfulness of Cj. I

In order to prove that T® is conservative over T, it is necessary to add a mild restrictionon the theory T, equivalent to the soundness of the following rule of deduction: for E-termst(x : s) and t'(x : s),

M ^ r h ( x :s,y :s')t = t'

Nonempty: rV (g ; j t i t' 'Then, the result was proved in [19] by showing that the E-homomorphism

that leaves X fixed and maps [f]j;,r to [ijsaja is injective, for X a variable set such thatX. ^ 0 f o r a l l s e 5.

In this section we prove a similar result for higher-order order-sorted algebra by usingHenkin models [31, 32], more precisely, a generalization of Henkin models to take into ac-count the subtype relation. Henkin models are more general than hos algebras in (5e£, Incl)because, instead of requiring the equalities ATlXT1 = ATl x AT2 and AT=>Ti = AT => AT<,one just requires inclusions ATIXT2 Q An x A^ and AT=>.T- C AT ^- AT<. An equivalent(up to isomorphism) definition of Henkin model is given in terms of an SM-sorted family ofsets A = {AT I T 6 SM} and families of functions appTT, : J4( T = > T . ) X T —> AT> and

ProJtTi,T2 '• ATlxn —> ATt (i = 1,2) subject to the conditions of extensionality and ex-istence of combinators (see [31, 32] for details). What matters for us is that the term modelconstruction for a theory such that the rule Nonempty above is sound and a big enough vari-able set X provides a free Henkin model over X [31, 32]. These results can be generalized tothe hos case as follows.

First, using soundness (Proposition 2.13), completeness (Proposition 2.28), and the ana-logue of Proposition 3.35 in Part I for the higher-order case, we can restrict our attention with-out loss of generality to disambiguated hos theories. Given a disambiguated hos theory T =(S" , < " , E, T), we define an order-sorted theory Th = (S" , <M, E \ Th), where

1. For each r, p e 5M , we have an overloaded operation symbol app 6 Ej=>.T p>T (it is easyto see that it is regular). We usually write tt' instead of app(t, t').

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 25: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 565

2. For each T,p 6 S", K»'T G E*,p=>{r=>p).

3. For each r ,p ,£ G S" . S < . " € E*(€=>(T=>p))=>((€=>r)=>(€=>p)).

4. For each r ,p G S". Pf-T € Sefc

t(pXr)=>p and 9? G Eeh,(pXT)=>r.

5. For each r ,p G S", E " 6 E*p = > ( T = > ( p x r ) ) .

6. For each operation symbol cr G EPiT, F£iT € E^ _>T.

7. There is a constant (> G E^ x.

8. The set of order-sorted E^-equations Yh contains the equations (x : r ) tc = ££. for eachequation (a:: r ) t = f' in F, where tc is as defined in Proposition 2.19, together with thefollowing families of equations:

p,y:T)(K<>'Tx)y = x

f =» (T =*/»),»: f =• T,Z : 0 ((S«-"-'-i)y)z = (xz)(yz)

p,y.T)Pp2'

T((E>>>Tx)y)=y

(x

(x

(x

(x

(x

An hos (E, T)-Henkin model H is an order-sorted (Eh , F^-algebra H in (Set.Incl) that inaddition satisfies the following extensionality condition: given f,g G HP=>T, if for all a GHp, Happ(f, a) = Happ(g, a), then f = g. Using Theorem 2.14 of Part I, for any variablesetX, wehaveafree(E / l,F' l)-algebra7i;;. i r/.(X);if XT / 0 for all r G 5M , we get a free(S, F)-Henkin model by imposing the extensionality condition on 7j> ^ {X). An isomorphicpresentation of this free Henkin model is given by imposing on the S^-sorted set Tj: of hosE-terms with variables in X as introduced in Definition 2.3 the congruence relation

t ~ s , r t' <=> r\-(x-.T)t = t'

for some finite variable set x : T included in X (soundness with respect to the rule Nonemptymakes this definition independent of the finite variable set considered). We denote by [t]^,rthe equivalence class of t with respect to ~£,r . and by 7iz,r(X) the quotient of Ts withrespect to the same congruence, which is our desired presentation of the free Henkin modelonX.

It is now clear that an hos theory T" is conservative over T iff the E^-homomorphism

that leaves X fixed and maps [t]xx to [£]s',r' is injective.

THEOREM 2.44

Given an hos theory T = (5M , <**, E, F) such that the rule Nonempty is sound, the homo-morphism

leaving V fixed is injective (remember that V is a SN-sorted set of variables such that for eachtype T G S* the set VT is countably infinite).

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 26: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

566 Inclusions and Subtypes II: Higher-order Case

PROOF. The key idea is to make the (E,r)-model Kz,r(V) into a (E®,r®)-model. First,pickforeachr G S™ avariablea;°. Then.forT < /.define a function rT<iT : Wzir(V)Ti —>^ E , r ( ^ ) r by mapping [t] £ W j ^ ^ J r to itself and the remaining elements to x°T\ this func-tion obviously satisfies the retract equations. Therefore, by freeness, the inclusion of V into

induces a homomorphism

which is the identity on V.Finally, the composition rp; x is a homomorphism from Hztr(V) into itself fixing V and,

again by freeness, it must be the identity. Hence, xj) is injective. I

3 Generalized subtypesIn this work we have studied in detail the categorical semantics of subtypes as inclusions, byinterpreting the subtype relation r < T7 as existence of a canonical monomorphism AT<T< :AT -> ATi in a poset subcategory J of C. This notion has been arrived at by generalizing theset-theoretic notion of subtype proposed in order-sorted algebra [19] first in Part I to generalcategories and then in Part II (this paper) to higher-order, while keeping all its nice properties.In particular, no information is lost when a data element is moved to a supertype, and equalityof data elements is independent of the type in which it is considered.

There are however situations in which a weaker notion of 'subtype' is desirable and nat-ural, namely one corresponding to an implicit conversion between types which needs not beinjective. Such implicit conversions may arise in answer to the need or convenience of con-verting data (perhaps with some loss of information) between some basic types, and also inthe context of function spaces when passing functions as arguments of higher-order functions.For example, a higher-order function / may require an argument of type p' =>• r but may in-stead receive an argument h of type p => r with p' < p (interpreted as before by a canonicalinclusion j : p' -t p). This may be easily resolved by restricting h to the domain p\ i.e. bycomposing it with the inclusion j to get j ; h : p' =• T; thus, we obtain an implicit conversion

jI =• r : (p => T) —> (/»' =• r)

which in general is not injective.

EXAMPLE 3.1

Consider again the summation operation

sum : (Nat => Rat) x Nat -> Rat

defined in Example 2.6. If we define double = AR: Rat. 2*R, then we would like to writeequations like (cf. Example 2.6)

(M:Nat) sum(double, M) =H * (M + 1).

However, this cannot be done in the setting of higher-order order-sorted algebra using onlyinclusive subtypes because the type of double is Rat => Rat, which is not a subtype of Nat=> Rat, and therefore the term sum (double, M) is not well formed. The problem disappearswhen we consider an implicit conversion that restricts the domain of double and allows thetyping

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 27: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 567

double : Nat => Rat .

By comparison with the case in which subtypes are interpreted as inclusions, some niceproperties are definitely lost; namely, information may be irrecoverably lost when moving adata element up to a 'supertype' by means of an implicit conversion, and identity of two dataelements is now crucially dependent on the type in which it is considered.

Therefore, it would be a serious mistake to conflate the 'subtype as inclusion' and the 'sub-type as implicit conversion' notions into a single notion of subtype, since the important ad-vantages and additional intuitions of the 'subtype as inclusion' case would then be lost. Ourproposal is to both distinguish and relate these two notions in a semantics that keeps all theadvantages of each of them. For the 'subtype as inclusion' notion we keep the subtype relation< as already formalized in this paper; for the 'subtype as implicit conversion' notion we intro-duce a generalized subtype relation <: different from the subtype relation <, yet containingit as a subrelation, i.e. the rule

TKT1

T<:T'

is satisfied.For function spaces, subtypes obey the restricted subtyping rule

T < T' p type

P => T < P =>• T1

whereas for generalized subtypes we have the more general

T <: T3 p' <:p

p => T <: p' => T''

For products, both relations behave similarly:

T < T' p<p' T <: T7 p<: p'

p x T < p' x r' p x T <: p' XT1

The advantage of the above typing rules is that they allow us to discriminate between the twosubtype relations and, therefore, support more careful and precise reasoning than would bepossible otherwise; addition of other type constructions to this framework is very natural andleads to similar typing rules discriminating between the two subtype relations for the construc-tion in question.

We can define generalized higher-order order-sorted signatures and algebras in a way thatextends naturally our treatment of subtypes as inclusions and satisfies all the typing rules men-tioned above. Given a set S of basic types, we consider the set SM of types generated fromS as before (Definition 2.1). Given two preorders10 (S, <, <:) with < C <: and < a partialorder, we can extend those preorders to 5 M by extending < exactly as before (Definition 2.1),and adding the additional clauses:

l . I f r < " r ' . thenT <:M r \2. If n <:" r[ (i = 1,2), then n x r2 <:* T{ X T^.

1 0 The reason for allowing < : to be a preorder is that, whereas type inclusions are naturally antisymmetric, it seemsquite natural to consider implicit conversions which are bidirectional. For example, one may want the flexibility ofimplicitly converting back and forth between Cartesian and polar coordinates when performing computations withpoints in the plane.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 28: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

568 Inclusions and Subtypes II: Higher-order Case

3. If r <:M r ' and p' <:M p, then p => r <:M p' =*• r7.

The preorder <:M in S* is usually denoted just <:.

DEFINITION 3.2

A generalized higher-order order-sorted signature, or ghos signature for short, consists of apair of preorder structures (S, <, <:) on a set 5 such that < C <: and < is a partial order,together with an order-sorted signature (S*, <M, E) which is regular and coherent for bothpreorders11 <M and <:M, and such that ST,T 5̂ 0 implies length(r) = 1.

The semantics of such ghos signatures is provided by CCC's with inclusion and implicitconversion structures, called CCIC-categories and defined as follows:

DEFINITION 3.3

A CCIC-category is a triple (C,J,fC) such that

1. (C, J ) is a CCI-category.

2. X! is a preorder subcategory of C containing J, called the category of implicit conversions.

3. K, is closed under _ x _, i.e. if ki : A{ —> 23, (i = 1,2) are morphisms in fC, thenk\ x k? : Ax x A^ —> B\ x B<i is also a morphism in fC.

4. JC is closed under _ => . , i.e. if ^ : > ! ; - > Bi (t = 1,2) are morphisms in AC, thenki =» Ai2 : B\ => A2 —^ -Ai =>• Bj is also a morphism in K,.

EXAMPLE 3.4

The category Per of partial equivalence relations on the natural numbers provides a very in-teresting example of a CCIC-category. The subcategory of implicit conversions is obtained asfollows: we have an implicit conversion A -> B iff nAm implies nBm, i.e. A C B as setsof pairs; this structure has already been studied in [6, 7], to which we refer the reader for moredetails. The subcategory of inclusions that we want to distinguish is the following: there isan inclusion A —¥ B iff given natural numbers n ,min the domain of A, nAm iff nBm (thisdoes not imply that A = B because B can have elements in its domain that are not in thedomain of A).

In his thesis [38], P. Taylor defines a coercion structure in a CCC as a preorder subcate-gory closed under _ x _ and _ => . (Definition 1.3.9). However, he does not distinguish thesubcategory of inclusions that we emphasize in the above definition.

DEFINITION 3.5

Given a ghos signature (SM, <M , <:M, E), a ghos algebra A in a CCIC-category (C, J, K.)consists of an hos (5M , <*\ E) -algebra A in the CCI-category (C, J) together with morphismsAT<;T' : AT -> AT' in K for r <: r7 in SM, subject to the following monotonicity condition:o € ET|T ' D EPiP< and T <: p imply

AT<:P\ A"/ = Ar/; AT.<:p. - . A T ^ A ^ .

The above definitions provide a basis on which to extend the categorical semantics of sub-types proposed in this paper to generalized subtypes. We intend to study in detail such a se-mantics in a subsequent paper. Since generalized subtypes are an intrinsically weaker notion,some important properties such as the 'no loss of information' property will not generalizeand will remain only valid in the subcategory of inclusions.

1 ' Although the regularity and coherence conditions have been defined for a poset of sorts, they can be generalizedto a preorder.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 29: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 569

4 Concluding remarks

We have presented a semantic approach to subtypes in which the two different notions of sub-types as inclusions and of (generalized) subtypes as implicit conversions are fruitfully distin-guished and nicely integrated. This approach exhibits the benefits of both notions with none ofthe drawbacks that adherence to either notion with exclusion of the other would create. Thiswork is a first step in the integration of both notions and much remains to be done. We list be-low some research directions that the present work suggests and that we feel should be furtherinvestigated:

1. Equational logic for generalized subtypes. Such a logic is missing in existing approachesand would be highly desirable; the need for this logic is also pointed out in [3] as a more di-rect way of reasoning about subtypes than translations into explicit coercion models whichmay introduce additional assumptions. The fully developed equational theory presentedhere for the < case should serve as a basis from which such a theory is obtained as a gen-eralization; this would also yield the appropriate generic model construction for the cate-gorical semantics sketched in Section 3.

2. Extensions to richer lambda calculi. As mentioned in the Introduction, this should followlines similar to those already developed by other researchers for generalized subtypes [9,6, 3, 7, 12, 1]. However, it would be desirable to provide a more axiomatic treatment bymeans of a general categorical semantics in the style of the one presented in this paper.For example, for dependent types it would be natural to require subcategory inclusions

J CfCCV

where the morphisms in J are inclusion maps, in K, are implicit conversions, and in T> are'display maps' [38, 26, 13, 37], with each of the categories being stable under pullbacksalong arbitrary morphisms in the ambient category C. The rules for structural subtypingfor different type constructions and different relations (< and <:) could then be derivedas consequences of the categorical axioms.

3. Operational semantics. With the exception of [5], very little has been done to developa precise operational semantics for higher-order subtypes. The present work provides anew connection with the fully developed first-order theory of operational semantics forsubtypes as inclusions [15, 23] which should be investigated. In this regard, the recentresults on the integration of rewrite rules and higher-order functions such as those in [2,4, 33] could be very useful.

4. Type checking. The elegant work of Curien and Ghelli [12], appropriately extended tothe present framework, should provide a general methodology for deriving type checkingalgorithms for specific calculi. An interesting question is how to make such algorithmseven more flexible by allowing insertion of retracts in the appropriate gaps.

5. Programming language design. The first-order approach to subtypes as inclusions hasgathered a rich experience in the design and implementation of functional languages thatare very expressive and flexible in their type structure [14, 16, 20] and that provide use-ful mechanisms for dealing with exceptions and partiality. An interesting research topicwould be the transfer of that experience to higher-order languages, integrating it with thetechniques already developed for languages with implicit conversions. Also, the first-order extensions of OBJ to relational, object-oriented and concurrent programming [17,36, 18, 28] could suggest similar extensions for higher-order languages.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 30: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

570 Inclusions and Subtypes II: Higher-order Case

6. Object-oriented programming. Since this is an area in which wide disagreement still ex-ists about basic concepts such as inheritance, we have preferred to develop our theory ina purely functional context, leaving open the matter of object-oriented applications; how-ever, such applications are indeed very relevant and important. A number of semanticproposals coming from both higher-order type theory ([40, 8, 10], among others) and thefirst-order theory of subtypes (for example [18, 21, 28]) have already been put forward.The present framework, by providing a conceptual link between these two lines of work,can offer a good basis on which to compare and relate proposals of this kind, and canalso suggest new solutions to the challenging problem of finding a good semantic basisfor object-oriented programming.

Acknowledgements

The authors wish to thank Val Breazu-Tannen for suggesting seeking a simpler presentationof hos homomorphisms in terms of combinators, Luca Cardelli, Pierre-Louis Curien, JosephGoguen, Simone Martini, John Mitchell, and Ralph Wachter for very helpful discussions onthe subject of subtypes, and Sam Owre for his comments on a draft of this paper. The workreported in this paper has been supported by Office of Naval Research Contracts N00014-88-C-0618, N00014-90-C-0210, and NOOO14-95-C-0225, and NSF Grants CCR-8707155 andCCR-9224005. The first author was supported by a Research Fellowship of the Spanish Min-istry for Education and Science. The first author's current affiliation is: Departamento de In-forma'tica y Automitica, Facultad de Ciencias Matema"ticas, Universidad Complutense, 28040Madrid, Spain.

References[I] R. Amadio. Formal theories of inheritance for typed functional languages. Technical Report TR-28/89, Dipar-

timento di Informatica, Univeisita di Pisa, July 1989.

[2] V. Breazu-Tannen. Combining algebra and higher-order types. In Proceedings of the Third Annual IEEE Sym-posium on Logic in Oimputer Science, pp. 82-90, Edinburgh, UK, 1988.

[3] V. Breazu-Tannen, T. Coquand, C. A. Gunter and A. Scedrov. Inheritance as implicit coercion. Information andComputation, 93, 172-221, 1991.

[4] V. Breazu-Tannen and J. Gallier. Polymorphic rewriting conserves algebraic strong normalization and conflu-ence. In Proceedings ofICALP'89, G. Ausiello, M. Dezani-Ciancaglini and S. Rondi Delia Rocca, eds. Vol. 372of Lecture Notes in Computer Science, pp. 137-150. Springer-Verlag, Berlin, 1989.

[5] V. Breazu-Tannen, C. A. Gunter and A. Scedrov. Computing with coercions. Technical Report MS-CIS-89-62Logic & Computation II, Department of Computer and Information Science, University of Pennsylvania, De-cember 1989.

[6] K. B. Bruce and G. Longo. A modest model of records, inheritance, and bounded quantification. Informationand Computation, 87, 196-240, 1990.

[7] L. Cardelli and G. Longo. A semantic basis for Quest. Journal of Functional Programming, 1, 417-458, 1991.

[8] L. Cardelli and J. C. Mitchell. Operations on records. Mathematical Structures in Computer Science, 1, 3—48,1991.

[9] L. Cardelli and P. Wegner. On understanding types, data abstraction and polymorphism. Computing Surveys, 17,471-522, 1985.

[10] W. Cook, W. Hill and P. Canning. Inheritance is not subtyping. In Proceedings of the 17th Annual ACM Sympo-sium on Principles of Programming Languages, pp. 125—135, San Francisco, CA, 1990.

[II] R. L. Crole. Categories for Types. Cambridge University Press, Cambridge, 1993.

[12] P.-L. Curien and G. Ghelli. Coherence of subsumprion, minimum typing, and type-checking in F< . Mathemat-ical Structures in Computer Science, 2, 55-91, 1992.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 31: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

Inclusions and Subtypes II: Higher-order Case 571

[13] T. Ehrhard. Une Simantiquc Catigorique des Types Dependants. Application au Calcul des Constructions. PhDthesis. University Paris VII, 1988.

[14] K. Futatsugi, J. Goguen, J.-P. Jouannaud and J. Meseguer. Principles of OBJ2. In Conference Record of the12th. Annual ACM Symposium on Principles of Programming Languages, pp. 52-66, New Orleans, LA, January1985.

[15] J. Goguen, J.-P. Jouannaud and J. Meseguer. Operational semantics of order-sorted algebra. In Proceedings ofICALP '85, W. Brauer, ed. Vol. 194 of Lecture Notes in Computer Science, pp. 221 -231. Springer-Verlag, Berlin,1985.

[16] J. Goguen, C. Kirchner, H. Kirchncr, A. Megrelis, J. Meseguer and T. Winlder. An introduction to OBJ3. InConditional Term Rewriting Systems, S. Kaplan and J.-P. Jouannaud, eds. Vol. 308 of Lecture Nous in ComputerScience, pp. 258-263. Springer-Verlag, Berlin, 1988.

[17] J. A. Goguen and J. Meseguer. Eqlog: Equality, types, and generic modules for logic programming. In LogicProgramming: Functions, Relations, and Equations, D. DeGroot and G. Lindstrom, eds. pp. 295-363. PrenticeHall, 1986.

[18] J. A. Goguen and J. Meseguer. Unifying functional, object-oriented and relational programming with logicalsemantics. In Research Directions in Object-Oriented Programming, B. Shriver and P. Wegner, eds. pp. 417-477. The MIT Press, 1987.

[19] J. A. Goguen and J. Meseguer. Order-sorted algebra 1: Equational deduction for multiple inheritance, overload-ing, exceptions, and partial operations. Theoretical Computer Science, 105, 217-273, 1992.

[20] J. A. Goguen, T. Winkler, J. Meseguer, K. Futatsugi and J.-P. Jouannaud. Introducing OBJ. Technical ReportSRI-CSL-92-03, Computer Science Laboratory, SRI International, March 1992. To appear in Applications ofAlgebraic Specification Using OBJ, J. A. Goguen, ed. Cambridge University Press, Cambridge, 1995.

[21] J. A. Goguen and D. Wolfram. On types and FOOPS. In Proceedings of IFIP TC2 Working Conference onDatabase Semantics: Object Orientated Databases. Windermcre, UK, July 1990.

[22] J. R. Hindley and J. P. Seldin. Introduction to Combinators and X-Calculus. Cambridge University Press, Cam-bridge, 1986.

[23] C. Kirchner, H. Kirchner and J. Meseguer. Operational semantics of OBJ-3. In Proceedings of ICALP '88, T. Lep-isttt and A. Salomaa, eds. Vol. 317 of Lecture Notes in Computer Science, pp. 287-301. Springer-Verlag, Berlin,1988.

[24] J. Lambek and P. J. Scott. Introduction to Higher Order Categorical Logic. Cambridge University Press, Cam-bridge, 1986.

[25] N. Martf-Oliet and J. Meseguer. Inclusions and subtypes I: First-order case. Journal of Logic and Computation,6,409-^38, 1996.

[26] J. Meseguer. Relating models of polymorphism. In Proceedings of the 16th Annual ACM Symposium on Prin-ciples of Programming Languages, pp. 228-241, Austin, TX, 1989.

[27] J. Meseguer. General logics. In Logic Colloquium'87, H.-D. Ebbinghaus et at., eds. pp. 275-329. North-Holland, 1989.

[28] J. Meseguer. A logical theory of concurrent objects and its realization in the Maude language. In Research Di-rections in Object-Based Concurrency, G. Agha, P. Wegner and A. Yonezawa, eds. pp. 314-390. The MIT Press,1993.

[29] A. R. Meyer. What is a model of the lambda calculus? Information and Control, 52, 87-122, 1982.

[30] R. Milner, M. Tofte and R. Harper. The Definition of Standard ML. The MIT Press, 1990.

[31] J. C. Mitchell. Type systems for programming languages. In Handbook ofTheoretical Computer Science, VolumeB: Formal Models and Semantics, J. van Leeuwen etal, eds. pp. 365-458. The MIT Press/Elsevier, 1990.

[32] J. C. Mitchell and P. J. Scott. Typed lambda models and cartesian closed categories. In Categories in ComputerScience and Logic Boulder, June 1987, J. W. Gray and A. Scedrov, eds. pp. 301-316. Contemporary Mathe-matics 92, American Mathematical Society, 1989.

[33] M. Okada. Strong normalizability for the combined system of the typed lambda calculus and an arbitrary conver-gent term rewrite I ystem. In Proceedings ofACM-SIGSAM International Symposium on Symbolic and AlgebraicComputation, pp. 357-363, Portland, OR, 1989.

[34] A. Pitts. Lectures on categories and types. In Lecture Notes for the Summer School on Constructive Logic andCategory Theory. Isle of Thorns, UK, 1988.

[35] J. C. Reynolds. Types, abstraction, and parametric polymorphism. In Information Processing 83, R. E. A. Mason,ed. pp. 513-523. North-Holland, 1983.

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from

Page 32: Inclusions and Subtypes II: Higher-order Casepdfs.semanticscholar.org/ed79/cc45466fa109a8e480669f93d...Inclusions and Subtypes II: Higher-order Case NARCISO MARTI-OLIET and JOSE MESEGUER,

572 Inclusions and Subtypes II: Higher-order Case

[36] G. Smolka. TEL (Version 0.9) report and user manual. SEKJ Report SR-87-11, FB Informattic, UniversitfitKaiserslautem, Germany, 1988.

[37] T. Streicher. Correctness and Completeness of a Categorical Semantics of the Calculus of Constructions. PhDthesis, Universitiit Passau, Germany, 1989.

[38] P. Taylor. Recursive Domains, Indexed Category Theory and Polymorphism. PhD thesis. University of Cam-bridge, UK, 1986.

[39] J. D. Ullman. Elements of ML Programming. Prentice Hall, Englewood Cliffs, NJ, 1994.[40] M. Wand. Type inference for record concatenation and multiple inheritance. In Proceedings of the Fourth Annual

IEEE Symposium on Logic in Computer Science, pp. 92-97, Asilomar, CA, 1989.

Received 3 April 1991

at Mathem

atics Library, U

niversity of Illinois at Urbana-C

hampaign on O

ctober 10, 2015http://logcom

.oxfordjournals.org/D

ownloaded from