11
Setnantics for Modules in Functional-Logic Programming * Juan M. Molina-Br avo Ernesto Pimentel _ Dept. Lenguajes y Ciencias de Ia Computation. University of Malaga. Campus de 29071 Ma.J.a ga. Spain e-mail: {jmm b,ernesto }@lcc.uma.es Abstract In this paper we present our work about modularity in declarative progra m- ming based on Constructor-Based Conditional Rewriting Logi c. This logic has been studi ed by Gonzalez Moreno and others and proposed as a general framework for i nteg r ating first-order functional and logic programming, giving an algebraic semantics for programs. We have extended this formalism with constructs for modularization, that allows to express hiding, ex po rt/import, generidty and in- heritance; and several semantics for modules based on an immediate consequen ce operator Tp defined for each program module Pin the logic programming style. Keywords: Functional-Logic Programming, Modules, Semantics, Rewriting Logic. 1 Introduction Constructor-Based Conditional Rewriting Logic ( CRWL), is a general approach to declar- ative programming combining functional and logi c paradigms by means of the notion of non-determinist ic lazy function from which both relations and dete rministic lazy func- tions are particu l ar cases. This approach, presented in [ 5], re tains t he advantages of determinist ic f unctions whi le adds tne possibility of modeling non-dete rm inistic func- ti on s by means of non-confluent constructor-based term rewriting systems, where a given term may be rewritten to constructor t erms (possibly with variables) in more than one way. A fundamental notion is that of joinability: two terms a,b are joinable iff th ey can be rewritten to a common - but not necessarily unique- constructor t erm. ln [ 5], all these notions are int roduced together with a model-t heoretical semantics for CR WL-programs, t wo equivalent proof calculi. and a sotUld and complete lazy narrowing calculus. Mo dularity in logic programming has been the objective of different proposals, see [3] for a survey a bout t he subject. ln functional programm i ng and algebraic spec ification, the modularit y issues have been generall y addressed from a category-t heoretic point of view ([4 , 6]) giving functorial semanti cs to modu les. We have adopted a notion of modu le - toget her with a set of constructs- close to that proposed in [. 1] . dealing with t he inherent characterist ics of CRWL- programming . We con sider [10] modules as open programs that can be combined by m eans of a set of operations that a ll ow us to express some typical modular cons t ru cLions. For each module P, we introduce a 11 consequence operator Tp in the logic progr amming "Th is work has been partially supported by the CI CYT project TIC!l5-0<133-C03-02 259

Setnantics for Modules in Functional-Logic Programming · bu~ dealing with the inherent characteristics of CRWL-programming. We consider [10] modules as open programs that can be

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Setnantics for Modules in Functional-Logic Programming *

Juan M. Molina-Bravo Ernesto Pimentel _ Dept. Lenguajes y Ciencias de Ia Computation. University of Malaga.

Campus de Teat~os. 29071 Ma.J.aga. Spain

e-mail: {jmm b,ernesto }@lcc.uma.es

Abstract

In this paper we present our work about modularity in declarative program­ming based on Constructor-Based Conditional Rewriting Logic. This logic has been studied by Gonzalez Moreno and others and proposed as a general framework for integrating first-order functional and logic programming, giving an algebraic semantics for programs. We have extended this formalism with constructs for modularization, that allows to express hiding, export/import, generidty and in­heritance; and several semantics for modules based on an immediate consequence operator Tp defined for each p rogram module Pin the logic programming style. Keywords: Functional-Logic Programming, Modules, Semantics, Rewriting Logic.

1 Introduction

Constructor-Based Conditional Rewriting Logic (CRWL), is a general approach to declar­ative programming combining functional and logic paradigms by means of the notion of non-deterministic lazy funct ion from which both relations and deterministic lazy func­tions are particular cases. This approach, presented in [5], retains the advantages of deterministic functions whi le adds tne possibility of modeling non-deterministic func­tions by means of non-confluent constructor-based term rewri t ing systems, where a given term may be rewritten to constructor terms (possibly with variables) in more than one way. A fundamental notion is that of joinability: two terms a,b are joinable iff t hey can be rewritten to a common - but not necessarily unique- constructor term. ln [5], all these notions are int roduced together with a model-theoretical semantics for CRWL-programs, t wo equivalent proof calculi . and a sotUld and complete lazy narrowing calculus.

Modularity in logic programming has been the objective of different proposals, see [3] for a survey a bout the subject. ln functional programm ing and algebraic specification, the modularity issues have been generally addressed from a category-t heoretic point of view ([4, 6]) giving functorial semantics to modules.

We have adopted a notion of module - together with a set of constructs- close to that proposed in [.1] . bu~ dealing with t he inherent characteristics of CRWL-programming. We consider [10] modules as open programs that can be combined by means of a set of operations that allow us to express some typical modular const rucLions. For each module P , we introduce a11 immediate~ consequence operator Tp in the logic programming

"This work has been partially supported by the CICYT project TIC!l5-0<133-C03-02

259

style and some semantics for modules: the fixpoin t semantics or M-semantics, the 7 -semantics, and the (Tp T w )-semantics obtained by denoting each module P by means of 7'P and 7 T w respectively, and the .CM-semantics using the set of all its term-models as the denotation of a module: and we study properties as compositionality, full abstraction and functorial behavior for these semantics. In this way, by means of the operator 7., , we relate the semantics given to modules in the maio declarative paradigms. In the next section we introduce the basic features of the CRWL approach to declar­ative programming. In Section 3, we introduce the rnodel-throretic and the fixpoint semantics. Our not ion of module is given in Section 4 together with a set of operations on modules, and the 7-semantics in order to provide modules with a compositional and functorial semantics. Also the (7 T w)-semantics is introduced in this section. Jn Sec­tion 5, we introduce the .CM-semantics that is compositional and fully abstract. We finish with some conclusions in Section 6.

2 An Introduction to CRWL Programming In this section we give a reduced presentation of CR'vVL - for a detailed presentation see [5, 9J.

A signature (with constructors) is a pair E = (DCr;,FSr.), where DCE and FS'f. are countable disjoint sets of strings h/n with n E N . Each c such that c/n E DC"£ is a constructor symbol with arity nand each f such that f /n E FSr.. is a (defin ed) function symbol with arity n. DC£ and FS£ denote the sets of all constructor and function symbols, respectively, with ari ty n. Toget.her wi th a signaLure E. we also assume a countable set V of variable symbols, disjoint from all of the sets DC¥_ and FS¥_. [n a signature E with a set V of variable symbols. each symbol in V and each symbol in DC'g is a E-terrn and, for each h E DC£ U F 8£ and t 1 , ••• , tn E-term, h( t1 , .. • , tn ) is a ~>term, and there is no other !:-term. We will write Term!: for the set of all E -terms and CTerm!: for the subset of those !:>terms (called constructor terms) built up only with symbols in DCr. and V. Adding a new 0-arity constructor symbol J. to a signature E we obtain an extended signallu·e E.1.. whose terms are called pa1·tial E-terms. When the signature E is clear, we will omit explicit reference to it, and we will write Term and CTerm or Term.1.. and CTerm.1.. respectively. Terms t E CTerm are intended to represent totally defined values and terms t E CTerm.1 represent partially defined values (to model the behavior of non-strict functions). We consider two kinds of atomic CRWL-for·mulns: reduction statements a -+ b. for a, b E Term.L, with the intended meaning "'b approximates a possible value of a", and j oin11bility statements a !)q b, for a, b E Term.~. , with the intended meaning ''a and b can be reduced to a common value in CTerm". C-substitutions are mappings 8: V -+ CTerm, which have a natural extension to CTerm, also wri tten as 8: CTerm -+ CTerm. Analogously, partial C-substitutions are mappings 8: V -+ CTerm.L. The set of all C-substitutions (partial C-substitutions) is written as CSuhst (CSubs t l.)· A CRWL-pmgram is a CRWL-theory n defin~d as a signature~ together with a set of conditioual rewrite rules of the form f(t) -+ r <=C. where J(I) is the left hand side (/Its), r the right band side ( rhs), and C the condition o[ the rule. f is a function symbol with ari ty n. I is a linear n-luplc (i.e. without repeated variables) of fully defined constructor terms, and C consists of fini tely many {possibly zero) joinability statements bet.wecn full y

260

defined terms. The set of possibly partial constructor instances of the rewrite rules of a

program R is wrillen

[n]l = {(!-+ r {:::: C)O I (I-+ T {:::: C) En, 0 E CSubst.d

Formal derivability of CRWL-statements from a given program n is governed by the

so-called Goal-Oriented Proof Calculus (5J, which focuses on top-down proofs of reduction

and joioability statements:

(Bo)

(RR)

(DC)

(OR )

(Jo)

e~ .L

e -e,

c:(e1 , •• • , e,.) - c(t1 , .•• , t,.) '

e, - t 1 ••• en - t,. C r- I

/(el, .. . , en) - t

a-1 b-t al><lb

fore E TermJ. ;

for e E V U DC0 ;

for c E DC" and e;, t; E Term1.;

if t E CTerm and a, b E Term1.;

Rule (BO) shows that a CRWL-reduction is related to the idea of approximation, and rule

(OR) states that only constructor instances of rewrite rules are allowed in this calculus

reflecting the so-called "call-time-choice" [7] for non-determinism (values of arguments

for functions are chosen before the call is made). As a consequence of this, outermost

rewriting is not sound in this framework and the lazy narrowing calculus presented in

[5] incorporates sharing. When a statement <p is derivable from a program 'R we write

'R f-cRWL t.p.

3 Model-theoretical and Fixpoint Semantics.

Given a signature ~ and a set V of variable symbols, we interpret CRWL-programs over

algebraic structures A = (D.A , {c.A} ceDCl: • {f.AJteFsr.) where D.A is a poset wid1 bottom

j_.A (their elements are thought of as finite approximations of possibly infinite values in

the poset 's ideal completion [11]) and for each f E F S£ , JA is a rnono1 on ic mapping

from D':._ to the set. of cones C(D,~,) (to express non-determinism) and for each c E DCf , c-4 is also a monotonic (deterministic) mapping from D':._ lo the set of ideals I(D,~, ) that

computes principal ideals (v). i.e. generated by one element v E D.A- and such that v is

maximal (totally defined ) when all arguments of c-4 are maximal. 'When n = 0. mappings

reduce to elements in the respective target sets. The class of all the CRvVL-algebra of

signature ~ is denoted by AlgE. As a specially kind of CRWL-algebras we have CRWf,-lerm algebras, which are struc-

tures A:::::: (CTermJ., {cA}cEDC!:· {!A}JeF'S~;)

with the carriN CTerm.l- ordered by the app1·oximation ordering "!;;;;", defined as the

leasl partial ordering satisfying the following properties:

(a) j_!;;;; t, 'VIE CTermJ. (b) c(t., ... , t , ) ~ c(s1 . .•. , Sn) if t, !;;;; s; , Vc E DC~ and t, s, E CTerm .J.

261

and fixed interpretation for constructor symbols

c-4 = (c), Vc E DC~; C'A(tt, ... , tn) = (c(t1 , .• . , i 11 )), Vc E DC~ and t; E CTerm.1. .

So, two CRWL-term algebras only differ in the interpretations of the function symbols. A valuation over a structure A E AlgE is any mapping 11: V-+ DA. A valuation "lis

totally defined when TJ(X) is maximal for all X E V. We denote by Val( A ) the set of all valuations over A, and by DefVal(A) the set of all totally defined valuations. Given a valuation TJ we can evaluate each partial E-term in A as follows:

[1.]~ [X]: [c]:

[ h(eh ... , en)]~

Where hA is defined as

=def

=def

=def

=de/

VXEV;

Vc E DC~ UFS~; Vh E DC£UFS£,n > 0.

"A u h (Ct, ... 1 Cn) = f(ut , ... 1 Un)

for cones Ch ... , Cn in C(DA)· In this way each partial E-term is evaluated to a cone.

3.1 Model-theoretical Semantics.

Approximation statements in a CRWL-a.lgebra A are interpreted as approximation in the sense of A's partial ordering, and joinability statements as asserting the existence of some common totally defined approximation. \Vitl1 Lhis idea in mind, we define

• A 1='1 (a-+ b) for a 1J E Val(DA) , iff[ a]~ 2[b]::

• A F •l (a lXI b) in "l E Val(D.A ), iff [an: n [ b n: contains a maximal element in D,A;

• A f= (l--> r ~C), iff A f=,1 C implies A f=11 (l-+ r) , for all valuation TJ E Val (D.A)i

• A is a model of a program 'R., i.e. A f= 'R., iff A satisfies all rules in 'R..

For each program 'R. there is a particular CRWL-term algebra 1\.1n characterized by the following interpretation for each defined function symbol f E FSf. , n 2: 0

JMn(t1, ... , ln) =def {t E CTerml. I 'R.I-c RWL /(f.J , · · ·, l,) -+ l} ,

for all t; E CTerm.1. , i = 1, . .. , n, that is a model of the program and is freely generated by the seL V of variable symbols in the category of all models of n w]th the following notion of homomorphism (loose element-valued homomorphism in [7])

D efinition 3.1 A homomorphism h: A -+ 8 from a CRWL-algebra A to another CRWL­

algebra 8 is a monotonic June/ion h: A -+ I(8), that is element-t1alued (produces prin­

cipal ideals} , strict (h( l.A ) = (.ia)J and pl'Csc·rve.s consl1"uc/m·s h(cA('uh ... , ·un)) =

c6 (h(ti.J ), ... 1 h('u,,)) I for all c E vcn and ~ E DA ; and loosely P1'CSC1'tles functions

h(.fA(uJ .... ,tt,.)) ~ f 6 (h(-ut) , . ... h(un)), fo1' all f E FS"' , nndu; E D.A. We also re-

quire totally definition: for all variable symbol X E V , h(X) = (hx) is generated by a

totally de.finP.d term hx.

262

According to these results, Mn is taken in [5] as the crLTwnic model of the program R or its model-theoretical semantics that we call M-semantics: [ R] = de/ Mn.

3.2 Fixpoint Semantics.

Given a signature I: with a set of variable symbols V, we consider the set TAlgr: of all CRWL-Cerm algebras of signature E with the relationship A~ B between two algebras A, B E TAlgr; defined by JA(t1, ... , t,.) ~ f 6(tt, ... , tn), for all t; E CTerm.L and f E FS£. (TAlgr; , ~) js a complete lattice, with bottom .L1:: and a top Tr;, respectively characterized by the interpretations

and /Tr:(t1, ... , tn) =dcf CTerm.L

, for all l; E CTerm.1 and f E F S£, n ~ 0; and least upper bound US and greatest lower bound ns of any subset S ~ TAlg"E, given by

.rus(tl' ... ' t,.) = def U.Aes JA(tt , ... 'tn), fns(ft, ... , tn) = de/ n.AeS JA(t~, .... tn),

for all t; E CTerm.L and j E F Sr_. For every CRWL-program n, with signature I: and variables in V, we can define an

algebra transformer Tn: TAlgE --> TAlgr;, similar to the immediate consequence operator used in logic programming, by fixing the interpretation of each function symbol f E F SF_ , in a transfom1ed algebra Tn(A) , as the result of the one step application of rules of R satisfied in A:

JT<~ (.A) (t l ) -1 > • • •' n - dej

{t I 3(J(sl, ···· s,.)--> r ~C) E [R.].L ,s; ~t ;, A Fid C,t EUrll~} U {1.1,

for all t; E CTerm.l and f E FS£. Tn is continuous and satisfies the following results

Lemma 3.2 (Model characterization) Given a program 1?..,

M ·is a term-model for R ¢:=::? Tn ( M ) ~ M .

Proposition 3.3 For evr.·ry CRWL-pmgram R, M n is the least ftxpoint of Tn.

So. if we consider the meaning of a program R as the least fixpoint of its associated transformer Tn, then this semantics coincides with the J\.11-sernantics as occurs in logic programming.

4 Modules in CRWL Programming

With the aim of structuring large CR'vVL-programs in small pieces a.nd composing pro­grams from other ones using traditional techniques as importat ion, instantiation and inheritance we introduce in [10] the following elementary not ion of module in a global signature E = (DC-,; , FS'~), witb a countable set V of variable symbols.

263

D efini t ion 4.1 A module is a program P over the sign ature E that declares a set of rules

rl(P) and a proper subsignature of defined function symbols sig(P) ~ FS'f. that includes

all function symbols with a definition rule in rl('P). So we can imagine a module. 'P as a

pair ( sig('P ), ri('P)).

Nevertheless, we can assume the whole set F Sr. decla.red in 'P - although not produced

by the sig operator- simply by assuming an implicit rule f(l) - .L for all those defined

function symbols not explicitly decla.red in 'P .

4.1 Module Composition in CRWL Programming

Following the approach in [1 , 2], we define three operations: union of modules, closure

w .r.t. a subsignature, and deletion of a subsignature.

Definit ion 4.2 (Union) Given two modules 'P1 = (u1o 'RJ), 'Pz = (u2 , 'Rz). their union

is defined as the module: 'P1 U 'Pz =de/ ( O'J U 0'2 , 1?.1 U 'R2).

The arguments in this operation can be considered as open programs that can be

extended or completed with other programs, possibly with additional rules for their

function symbols. So, we could imagine t he union as an "open" im portation of modules.

The second operation is the closur-e of a module w.r.t. a signature, that is defined

as a new module in which the rest of the sigr1ature has been hidden, and the mentioned

signature is only accessible in an extensional way.

D efinition 4.3 (Closure w.r.t. a signature) The closure of a module 'P w.r.l. a sig­

nature u , of function symbols. is defined as the module:

15" =de f (sig(P) n u, {f(T) .... r If /n E a, t;, r E CTermE,~. , ri(P ) 1-c RWL J(t) - r} ).

wher·c t; stands for· each component of the tuple I.

The closure of a module is a program with a possibly infinite set of rules equiva lent

to the union of the graphs of all the functions defined in 'P and contained in 0'. As a

l · · lili · ·u · -n · d f p•ia(P J syn act1c s1mp tcatiOll we w1 wnte r mstea o .

Module closure provides us with a means of expressing encapsulation and restricting

the signature (of defined fu nction symbols) available outside a module. We can define an

exporl - with encapsulation- operaLion 0, in t his simple wa.y:

We can obtain a -closed" import operation ~ between modules as:

M ~N=M UN.

This represents global importation from N ; but we can express selective impo1'tation of

a signature u by combining importation with exportat ion, and restricting the visible

signature of the imported module:

M ~ (uDN) = M U 7J"'.

264

Multiple impm·tation or selective importation from a number of modUles can be written

as

because the importation order is not relevant. So, a typical module M , in the sense of stand.ard modular programming, is built up from a plain module P, several partially imported modules N1 , .•• ,.Nk and an exported signature q as

Our third operation is the deletion of a signature in a module.

Defini tion 4A (Deletion) Given a module P , the deletion of a signature of functwn

symbols q i.s the module: P \ q =de/ (sig(P) \ tJ, rl(P) \ tJ), where ri(P) \ q denotes the

set of those rules in P defining functions not appearing in q .

1\ote that t he deletion of a signature removes all rules defining function symbols in the signature, maintaining the occurrences of these symbols in the rhs of the other rules; this represents a sort of paramete1·i::ation in a signature that we denote by

M (q) = M \ u.

The instantiation of this module with another module N could be represented by

M (q ) <. N = def M \ u UN,

and this instantiation could be partial depending on the function symbols defined in N. Also, with this operation, it is possible to model a sort of inheritance between modules. Inheritance with overriding M iMuV may be captured by means of the union and deletion of a signature

M isaN = M u (N \ sig(M )).

In this case, overriding is captured by deleting the signature of the inherited class before adding it to the dedved class.

4 .2 A Compositional Semantics for CRWL-Program Modules.

In order to state the compositionality and full abstractiou for a semantics, we need a pair ( Ob, Op) where Op is a set of operations and Ob a notion of observable behavior. A semantics S is compositional w.r.L. ( Ob,Op) iff it is a congruence w. r.t. Op, i.e.

S('P;) = S(Qi)(i = 1 ... n) => S(O(P1, ... , Pn)) = S(O(QJ ... . , Q,))

. for aJJ programs P; and Q; and for aJJ 0 E Op, and pteserves Ob, i.e.

S(P ) = S(Q) => Ob(P) = Ob(Q),

for aJl programs P and Q. In our context the natural choices for t he observable behavior of a program module P

and for the sel of operations are Ob(P) =d•/ M-p and Op =clef {U, IT, ( · )\tJ } . Notice that J\11 -p captures the grapb of a ll functions defined in 'P , whereas functions not included in

265

the program are considered totally undefined (~). With this notion, the M -semantics for CRWL-modules is not compositional w.r.t. ( Ob,Op) -see [10) for an counter-example. We get compositionality if we think about programs as open in the sense that we can build up programs f:rom other programs adding rules for new functions and for already defined functions, and take them as algebra transformers as is suggested in [12} and proposed in [8, 1} for logic programming. In other words, it can be proved [10) t hat the T -semantics defined by

{ 'P ll =d~J Tp,

where Tp means 'Trt(Plo is compositional w.r.t. ( Ob,Op), as it is stated in t he next theorem. Previously, we have to note that the set [TAlgE ~ TAlgE} of all conti nuous functions from TAlgE to TAigi:, pointwise ordered by Ti J; 'Tz iff VA E TAlgt . (Ti (A ) J; 'Tz(A)), with the lub and the glb, of a set {7i}ieJ of functions, pointwise defined as

(U;et7i)(A) = U;eJ(T;(A)) and (n iei7i)(A) = n ;ei(T;(A ))

respectively, and with bottom T .L and top 1' E so t hat

T .L(A ) = J..t and T E(A ) = T t VA E TAlgt,

is a complete lattice as a consequence of (TAlgE, J;) being a complete lattice.

Theorem 4.5 (Composit iooality of { ·») For all progr·ams 'P , P 1 and P2 defined over E, and all signature of function symbols r7 ~ F Sr. we have

(a)

(b)

(c)

« 'P. u P2 n = « P. n u« 'Pd;

« 15" D = ~A. (H P D i w(l. m,;

{ P \ (j ~ ={ P ll n T.;.~~cPl\cri

where. for A E TAlgE and r7 ~ FSt , A la is the CRWL-algebra characteri:ed by

!AI.,( ) _ { JA(t., ... , tn) for all .f E r7, and t; E CTerm!:J.. l1 .... , in -

· { .L} othe1·wise

and, f or each signahtre <T ~ F S't, T" is lhe constant fun ction defined as

VA TAl /'i'v(A l( ) _ { CTerm~J.. iff E r7 E g E, t1, ... , Ln - •

{ .L} otherwzse

4.3 Tl1e Functorial Nature of the T -semantics. In functional languages like ML -see [6]- functors are used to denote parameterized structures, characterized by an input. and an output signature. The application of t.he functor to a structure matching the input signature yields a structure with the out put signature. T hcrf'fore, these functors can be considered a.s algebra transformers. ln our context, the custinction between input and output signatures has no sense because we work with a global signature, but. our immediate consequence operator has a functorial behavior.

First, we have to note that, given a signature 1: with a set of variable syrnbols V, TAlg~ is the set of objects for a category whose homomorphisms are totally defined.

266

Proposition 4.6 The set TAJgE of all CRWL-term algebras with signature :S together

with the sets of Clll totally defined homomorphism between two algebras constitutes a cat­

egory Ter mAigE.

Proof. There is no problem in proving that the composi~ion of two totally defined

homomorphism h.: A -+ B and k: 13 -+ C, defined as {k · h)(t) = k(h(t)) , is a totally

defined homomorphism that satisfies the associative property. Also, it is easy to see that,

for each A E TAlg l:, the homomorphis!!l id..4: A~ A , defined as id..4 (t) = (t), is totally

defined a.nd verifies h · idA = h and id..4 · k = k for all homomorphisms h: A -+ B and

k:B-+ A. • To prove that T., is a functor we need a previous lemma.

Lemma 4. 7 Given an homomorphism h: A ....... B the following statements are t1·ue

(a) h induces a substitution 0,. E CSubst1 defined as Oh(X) = hx, where h(X) = (hx),

such that h(t) = (t8h} for all t E CTerm .L;

(b) t E IT r D~ :::} u8h E IT rOh D~;

(c) if h is totally defined then A Fid s t><J t :::} B J=;d sOh t><J tOh.

P roof. Statements (a) and (b) are proved by induction on the structure of t and r

respectively, and (c) is derived from (b) and the fact that. oh is a totally defined valuation,

which maps maKimal elements into maximal elements. • With this lemma we ca.n prove the following result. , extending the immediate con­

sequence operabor in such a way that it could be considered as an endofunclor in the

category Term A lg!:.

P rop osition 4 .8 For each module P we can extend the tmnsformer Tp to a functor

from TermAlgt to Ter mAlg!: that coincides with T., on the ob;ects of the category and

maps each homomorphism into itself: T-p(h) = h , for· all homomorphism h: A-+ 13.

Proof. We only need to prove that h(f7r>(.Al(t1 , ••• , t,)) ~ f 7vlt3l(tdJ11 , ••• , t,fh) for ail

homomorphism h: A -+ B in order to show that his also an homomorphism from T.,(A )

to Tp(B). But this follows from the above lemma taking an element in the left cone and

proving that it is in the right one. The other functorial properties are immediate. •

The functorial semantics used in algebraic specilication languages. in a simplified way.

denotes modules by functors which maps initial models of the input specification into

initial models of the output specification [4}. Thus, a module importing another module

can be considered as a transformer, which maps initial models of imported modules into

initial models of the resulting module. In our context, we can express this behavior by

requiring free term models of imported modules to be mapped into free term models of

the resulting module (both with the same global signature). This requirement is cot

satisfied by our 7 -semantics. However, we can see that the Tp T w operator is still a

functor like Tp, and moreover il fits the requiremenl.

P roposition 4.9 For each module P the power T., T w of the lransforme1" T., i.~ nlso a

functor· ]1-om TermAlg!: to TermAig!:, defined fo't each A E TAlg!: as the function thai

prculucesthe tenn (L/gebra (T'P T w)(A) chamcterized by the ju11clions J(7 r> l"")(.A)(I. 1, ... , tn) = UneN fTv"CAl(t 1, ••• , tn)- and for each homomorphism h: A -+ 13 as (T'P T w)(h) =h.

267

P r oof. This proposition, like the one above, only need to be proved "that

and this is easy to do knowing t hat Tp is a functor. • With our constructs for modularization we can consider several modes of importing a

module Q: open importation (or union) P U Q, where we can think about bot h modules as imported by the unjon module; closed importation P «: Q = P U Q; and instantiation 1>((1) «: Q = (P \ u) U Q. In a ll these modes the resultant module is obtained as the union of Q, open or closed (but witl1 the same free term model), with other module. So, the corresponding immediate consecuence operator associated to is, basically, the union of two operators, one corresponding to Q or Q, and the other one corresponding to the other module. With this idea we can proof the following proposition.

Propos it ion 4.10 Given a module N that import another module Q in any of the above modes the functor T~o~ T w maps the free term model of Q into the free term model of N

Proof. In all cases M Q I; T~o~(MQ) , the set {Tx"(MQ) I n E N } is a chain and its supremum UT~o~"(JV1 Q) = (T,v T w)(MQ) is a fixpoint for TN and a model for N; so M11 I; (Tx T w)(M Q)· As Mx is a model of Q and a fixpoint for T.v, we have that (T11 T w}(MQ) ~ M11 and so (TNT w)(MQ) = JViN. •

5 . A Compositional and Fully Abstract Semantics.

To introduce the notion of full a.bstraction we need some way of distinguishing program modules. Two modules 'P and Q are distinguishable under a notion of observable behavior Ob and a set of operations Op if there exists a context CIT· ] (constructed by using operations in Op), such that C [ P] and C [ Q] have different external behavior, i.e. Ob(C[P]) =I Ob(C[ Q]). We denote by P =: Q when P and Q are indistinguishable under (O b, Op). A semantics Sis fully abstract w.r.t. (Ob, Op) iff for all modules P and Q, P:! Q implies S(P ) :::: S(Q)

Although the T-semantics is compositional w.r.t. (Ob,Op) it is not fully abstract, as we can sec with the foUowing counter-example. Let ~ be a signature ({ c/ 0, d/0}, {! / 0}) and let P and Q be t.he programs:

rl(P) = {! -t c, f--+ d}, rl(Q) = {! __, c, f--+ d <= f t><1 c}.

They a re indistinguishable under Op, but they lla.ve not the same meaning wi th the T -semantics; in fad, the graph off interpreted in 7-p(l.!:) is {{!, {l., c,d} )} whereas in TQ{l.~) is (f, {l., c}). This is because of the T-sernantics distinguishes more than the model-theoretic semantics, since the T-operator captures what is happening in each reduction level. We obtain a compositional and fully abstract semantics w.r.t. (Ob, Op), by considering the set. of aU its term models aS-the meaning of a module P

{ P » =deJ {M : M is a term-model of P}

which will be called loose model-ihr,oretic sernanttcs or .CJ\1-semantics. We derive com­positionality and fully abstraction for this semantics as two theorems proved in [9].

268

6 Conclusions.

Functional-logic programs can be semantically characterized by applying the usual logical

approach, based on an immediate consequence operator. T his semantic characterization

is convenient (compositional) for a particular (elementary) notion of module, when a

set of bask operations are considered for composing modules. In this paper. we have

shown a more functional reading for t his semantics, proving the functorial nature of the

immediate consequence operator T'R and its power T'R T w that have a transformational

behavior between free term models as Is usual in the algebraic and funct ionaJ style, but

unfortunately it is not compositional.

References

[11 A. Brogi. Program Construction in Computational Logic. Ph.D. Thesis: TD-2/93. Univ.

Pisa-Genova-Udine, 1993.

[2] A. Brogi and F. Turini. Fully Abstract Compositional Semant ics for an Algebra of Logic

P rograms. T CS 149 (2), pp. 201-229, 1995.

[3] M. Bugliesi , E. Lamma and P. Modularity in Logic Programming. Journal of Logic Pro­

gramming 19,20, pp. 443-502, 1994.

[1] H. Ehrig and B. Mahr. Fundamentals of Algebmic Specification 2. Springer-Verlag, 1990.

[5] J .C. Gottzale?.-Moreno, M .T. Hortala-Gottzalez, F.J. Lopez- Fraguas and M. Rodrfguez­

Artalejo. A Rewriti11g Logic for Declarative P rogramming. ln H. R. Nielson (ed.) Proc.

ESOP'96, LNCS 1058, pp. 156-172. Springer. 1996.

[6] R. Harper. D.B. MacQueen and R. YLilner. Standard /1/L. Reporl ECS-LFCS-86-2. Univ.

of Edinburgh, 1986.

(7) H. Hussmann. Non-determini.ml in Algebmic SpecificCitions and Algebraic Programs.

Birkanser Verlag, 1993.

(8) P. Manca.rella aud D. Pedreschi. An Algebra of Logic Programs. In R. A. Kowalski , A.

Bowen (ed.) Proc. Fifth ICLP. pp. 1006-1023. MIT Press. 1988.

(9] J.M. Mollila Bravo and E. Pimentel. Modu/Cirity in CRWL-pl'ogramming. Teclt. Rep., Dep.

Leugua.jcs y C.C., Univ. rle Malaga, 1996.

jlO] J .M. Mojjna Bravo a.rtd E. Pimentel. "Modularity in Functional-Logic Programming". To

appear iu Fou,.teenth Prrx:. of JCLP, MIT Press. 1997.

jl L) B. Moller. On the Algebraic Specification of Infinite Objects - Ordered and Continuous

Models of Algebraic Types. A cta Informatica 22. pp. 537-.)78, .1985.

[12] R. O'Keefe. "Towards an Algebra fo r Constructing Logic Programs". l n Proc. Second

IEEE Symr>Osium on Logic Pmgmmming, pp. 152-160, 198.5.

269