• Aucun résultat trouvé

JOIN(X): Constraint-Based Type Inference for the Join-Calculus

N/A
N/A
Protected

Academic year: 2021

Partager "JOIN(X): Constraint-Based Type Inference for the Join-Calculus"

Copied!
16
0
0

Texte intégral

(1)

HAL Id: inria-00000029

https://hal.inria.fr/inria-00000029

Submitted on 16 May 2005

HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

Join-Calculus

Sylvain Conchon, François Pottier

To cite this version:

Sylvain Conchon, François Pottier. JOIN(X): Constraint-Based Type Inference for the Join-Calculus.

Proceedings of the 10th European Symposium on Programming (ESOP’01), Apr 2001, Genova,

pp.221–236. �inria-00000029�

(2)

SylvainConhonandFrançois Pottier

INRIARoquenourt,{Sylvain.Conhon,Franois.Pottie r}i nria. fr

Abstrat. We present a generi onstraint-basedtype system for the

join-alulus.Thekeyissueistypegeneralization,whih,inthepresene

ofonurreny,mustberestrited.Werstdenealiberalgeneralization

riterion,andproveitorret.Then,wendthatithinderstypeinfer-

ene,andproposearuderone,reminisentofML'svaluerestrition.

Weestablishtypesafetyusingasemi-syntati tehnique,whihwebe-

lieveis ofindependentinterest.Itonsistsininterpretingtypingjudge-

mentsas (sets of) judgementsin anunderlying system, whihitself is

givenasyntatisoundnessproof.

1 Introdution

The join-alulus [3℄ is a name-passing proess alulus related to the asyn-

hronous -alulus.Theoriginal motivation forits introdutionwasto dene

aproessalulusamenabletoadistributedimplementation.Inpartiular,the

join-alulusmergesreeption,restritionandrepliationintoasinglesyntati

form,thedefonstrut,avoidingtheneedfordistributedonsensus.Thisdesign

deisionturns outtoalsohaveanimportantimpatontyping.Indeed,beause

thebehaviorofahannelisfullyknownatdenitiontime,itstypeanbesafely

generalized.Thus,defonstrutsbeomeanalogoustoML'sletdenitions.For

instane,thefollowingdenition:

def apply(f,x) = f(x)

denesahannelapplywhihexpetstwoargumentsfandxand,uponreeipt,

sendsthe messagef(x).InFournetet al.'stypesystem[4℄,applyreeivesthe

parametritypesheme8:hhi;i, wherehiisthehanneltypeonstrutor.

1.1 Motivation

Whydevelopanewtypesystemforthejoin-alulus?Theuniation-basedsys-

tem proposed by Fournet et al. [4℄shares many attrativefeatures with ML's

typesystem:itissimple,expressive,andeasytoimplement,asshownbytheJo-

Camlexperiment[1℄.LikeML,itispresriptive,i.e.intendedtoinferreasonably

simpletypesandto enforeaprogrammingdisipline.

Typesystemsareoftenusedasanieformalbasisforvariousprogramanal-

(3)

on. These systems,however,tend to beessentiallydesriptive, i.e. intended to

inferaurate typesand to rejetasfew programsas possible. Toahievethis

goal,itisommonto desribethebehaviorofprogramsusingarih onstraint

language,possibly involvingsubtyping, set onstraints,onditionalonstraints,

et.Wewishto denesuh adesriptivetypesystemforthejoin-alulus,asa

vehileforfuturetype-based analyses.

FollowingOderskyetal.[6℄,weparameterizeourtypesystemwithanarbi-

traryonstraintlogiX,makingitmoregeneriandmoreeasilyre-useable.Our

workmaybeviewedasan attempt toadapt their onstraint-basedframework

tothejoin-alulus,muhasFournetetal. adaptedML'stypedisipline.

1.2 TypeGeneralization Criteria

The def onstrut improves on let expressions by allowing synhronization

between hannels. Thus, we an dene a variant of apply that reeives the

hannel fandtheargumentxfromdierenthannels.

def apply(f) | args(x) = f(x)

Thissimultaneouslydenesthenamesapplyandargs.Themessagef(x)will

beemittedwheneveramessageisreeivedonbothofthesehannels.

Ina subtyping-onstraint-basedtype system, onewould expet apply and

args to be given types hi and hi, respetively, orrelated by the onstraint

hi.Theonstraintrequiresthehannelstobeusedinaonsistent way:the

typeofxmustmaththeexpetationsoff.Now,ifweweretogeneralizethese

typesseparately,wewouldobtainapply:8[hi℄:hiandargs:8[

hi℄:hi, whih are logiallyequivalentto apply:8:hhii and args:8:hi.

Thesetypesnolongerreettheonsistenyrequirement!

To addressthis problem, Fournet et al. statethat any typevariable whih

isshared betweentwojointlydened names(here, applyandargs),i.e.whih

ours free in their types, must not be generalized. However, this riterion is

based onthe syntax of types, and makes littlesense in the presene of an ar-

bitraryonstraint logi X. In the example above, applyand args havetypes

hi and hi, sothey share notype variables. Theorrelation isonly apparent

in the onstraint hi. Whentheonstraintlogi X is known, orrelations

anbedeteted byexamining the(syntaxof the) onstraint,looking for paths

onnetingand .However,wewantourtypesystemtobeparametriinX,

sothesyntax(andthemeaning)ofonstraintsis,ingeneral,notavailable.This

leads us to dene auniform, logial generalization riterion(Set. 5.2), whih

weprovesound.

Unfortunately,andsomewhatsurprisingly,thisriterionturnsouttohinder

type inferene. As aresult, we will propose aruder one, reminisent of ML's

so-alledvaluerestrition [10℄.

1.3 Overview

Werstreallthesyntaxandsemantisofthejoin-alulus,andintroduesome

(4)

P jQQjP D1;D2D2;D1

P j0P D;D

P j(QjR )(PjQ)jR D1;(D2;D3)(D1;D2);D3

(defDinP)jQdefDin(P jQ) ifdn(D)\fn (Q)=?

defD

1

indefD

2

inPdefD

1

;D

2

inP iffn(D

1

)\dn(D

2 )=?

defD;J.P inQj'J!defD;J.PinQj'P ifdom(')=ln(J)

Fig.1.Operationalsemantis

alled B(T),andestablishitsorretnessin asyntatiway(Set. 4).Building

on this foundation, Set.5 introdues JOIN(X) and provesit orret withre-

spetto B(T). Set.6studies typereonstrution,suggestingthat arestrited

generalizationriterionmustbeadoptedinordertoobtainaompletealgorithm.

Bylakofspae,weomitallproofs,exeptthatofthemain typesoundness

theorem(Theorem5.9).Theinterestedreaderisreferredto[2℄.

2 The Join-Calulus

Weassumegivenaountable set ofnamesN,ranged overbyx;y;u;v;::: We

write~uforatuple(u

1

;::: ;u

n

)anduforaset fu

1

;:::;u

n

g,wheren0.The

syntaxofthejoin-alulusisasfollows.

P ::=0j(P jP)juh~vijdefDinP

D::=jJ.P jD;D

J ::=uh~yij(J jJ)

Thedenednames dn(J)(resp.dn(D))ofajoin-patternJ (resp.ofadenition

D)arethe hannelsdened byit. InaproessdefD inP,thedened names

ofD areboundwithinD andP.Moredetailsaregivenin[2℄.

Redution!isdenedasthesmallestrelationthatsatisesthelawsinFig.1.

(-onversionand ongruenerulesomittedforbrevity.) 'rangesoverrenam-

ings,i.e.one-to-onemapsfromN intoN.standsfor!\ .Itisustomary

todistinguishstruturalequivaleneandredution,butthisisunneessaryhere.

3 Notation

Denition3.1. GivenasetT,aT-environment,usuallydenoted ,isapartial

mappingfromN intoT.IfN N, j

N

denotestherestritionof toN. + 0

istheenvironmentwhihmapseveryu2N to 0

(u),ifitisdened,andto (u)

otherwise.When and 0

agreeondom( )\dom(

0

), + 0

iswritten 0

.

IfT isequippedwithapartialorder,itisextendedpoint-wisetoT-environments

(5)

Denition3.2. Given aset T,rangedover by t,

~

t denotes atuple (t

1

;:::t

n ),

of lengthn0; weletT

?

denote the set ofsuh tuples.If T isequipped witha

partialorder, itisextendedpoint-wise totuples of idential length.

Denition3.3. Given a set I,(x

i : t

i )

i2I

denotes the partial mapping x

i 7!

t

i

of domain x = fx

i

;i 2 Ig. (P

i )

i2I

denotes the parallel omposition of the

proesses P

i .(D

i )

i2I

denotesthe onjuntion of the denitionsD

i .

Denition3.4. The Cartesian produt of a labelled tuple of sets A = (x

i :

s

i )

i2I

,writtenA, isthe setof tuplesf(x

i :t

i )

i2I

;8i2I t

i 2s

i g.

Denition3.5. Givenapartially ordered setT andasubsetV ofT,the one

generated byV within T,denotedby "V,isft2T;9v 2V vtg. V issaid

tobe upward-losedif andonlyif V ="V.

4 The System B(T)

This setion denes an intermediate type system for the join-alulus, alled

B(T). It is aground type system: it does not have anotion of type variable.

Instead, it has monotypes, taken to be elements of some set T, and polytypes,

merelydenedas ertainsubsetsofT.

Assumptions. Weassumegiven aset T,whose elements, usuallydenoted by

t,arealledmonotypes.T mustbeequippedwithapartialorder.Weassume

givenatotalfuntion,denoted hi,from T

?

into T,suh thath

~

tih

~

t 0

iholdsif

andonlyif

~

t 0

~

t.

Denition4.1. A polytype, usually denoted by s, is a non-empty, upward-

losedsubset of T.Let S be the set of all polytypes. We order S by , i.e. we

writess 0

ifandonly ifss 0

.

Note that and hi operateon T. Furthermore,S is dened on top of T;

thereisnowaytoinjetS bakintoT.Inotherwords,thispresentationallows

rank-1 polymorphismonly;imprediativepolymorphismisruledout.Thisisin

keepingwiththeHindley-Milnerfamilyoftypesystems[5,6℄.

Denition4.2. Amonotypeenvironment, denotedby B,isaT-environment.

A polytypeenvironment,denotedby orA, isan S-environment.

Denition4.3. ThetypesystemB (T)isgiveninFig.2.Byabuseofnotation,

intherstpremiseofruleb-Join,amonotypebinding(u:t)isimpliitlyviewed

asthe polytypebinding (u:"ftg).

Every typing judgement arriesa polytype environment on itsleft-hand

side, representing a set of assumptions under whih its right-hand side may

be used. Right-hand sides ome in four varieties. u : t states that the name

u has type t. D :: B (resp. D :: A) statesthat the denition D gives rise to

(6)

Names

b-Inst

(u)=s t2s

`u:t

b-Sub-Name

`u:t 0

t 0

t

`u:t

Denitions

b-Empty

`::

~

0

b-Join

+(~u

i :

~

t

i )

i2I

`P

`(xih~uii) i2I

.P::(xi:h

~

tii) i2I

b-Or

`D

1 ::B

1

`D

2 ::B

2

`D1;D2 ::B1B2

b-Sub-Def

`D::B BB 0

`D::B 0

b-Gen

8B2A `D::B

`D::A

Proesses

b-Null

`0

b-Par

`P `Q

`P jQ

b-Msg

`u:h

~

ti `~v:

~

t

`uh~vi

b-Def

+A`D::A +A`P

`defDinP

Fig.2.ThesystemB (T)

onstrution,dn(D).Lastly,aright-handsideof theformP simplystatesthat

theproessP iswell-typed.

Themost salient aspet of these rules is theirtreatment of polymorphism.

Ruleb-Instperformsinstantiation byallowingapolytypestobespeializedto

anymonotypet2s.Conversely,ruleb-Genperformsgeneralization byallowing

the judgement ` D :: (x

i : s

i )

i2I

to be formed if `D ::(x

i : t

i )

i2I

holds

whenever (x

i : t

i )

i2I

2 (x

i : s

i )

i2I

, i.e. whenever 8i2 I t

i 2 s

i

holds. In

otherwords,thissystemoersanextensional viewofpolymorphism:apolytype

sisdenitionallyequaltothesetofitsmonotypeinstanes.

Rulesotherthanb-Gen,b-Instandb-Defarefairlystraightforward;they

involvemonotypesonly,andaresimilartothosefoundinommontypedproess

aluli. Theonly non-syntax-diretedrules arethe subtyping rules, namelyb-

Sub-Name andb-Sub-Def.Ruleb-Gen must(andanonly)beapplied one

aboveeveryuseofb-Def,soitisnotasoureofnon-determinism.

The following lemmas will be used in the proof of Theorem 5.9. The rst

oneallowsweakeningtypejudgementsbystrengtheningtheirenvironment.The

seondoneistehnial.

Lemma4.4. If `P and 0

,then 0

`P.

Lemma4.5. Assume `(D;J.P)::B 0

andB 0

j B.Then `J.P ::B.

(7)

We establish type soundness for B(T) following the syntati approah of

WrightandFelleisen[11℄,i.e.byprovingthatB(T)enjoyssubjetredution and

progress properties.

Theorem4.6 (Subjet redution). `P andP !P 0

imply `P 0

.

Denition4.7. Aproess of the formdefD;J.P inQjuh~viis faulty ifJ

denes amessageuh~yi where~v and~y have dierent arities.

Theorem 4.8 (Progress).Nowell-typedproessisfaulty.

5 The System JOIN(X)

5.1 Presentation

LikeB(T),JOIN(X)isparameterizedbyasetofgroundtypesT,equippedwith

a typeonstrutor hi and asubtyping relation . It is further parameterized

by a rst-order logi X, interpreted in T, whose variables and formulas are

respetively alled type variables and onstraints. The logi allows desribing

subsets of T as onstraints. Provided onstraintsatisabilityis deidable, this

givesriseto atypesystemwheretypehekingisdeidable.

Our treatment is inspired by the framework HM(X) [6, 9,8℄. Our presen-

tationdiers,however,byexpliitlyviewing onstraintsasformulasinterpreted

in T, ratherthan as elements of anabstrat ylindri onstraint system. This

presentation is moreonise, and givesus the ability to expliitly manipulate

solutions of onstraints, an essential requirement in our formulation of type

soundness(Theorem5.9).Eventhoughwelose somegeneralitywithrespet to

theylindri-systemapproah,welaimtheframeworkremainsgeneralenough.

Assumptions. Weassumegiven(T;;hi) asin Set. 4.Furthermore,we as-

sumegivenaonstraintlogiXwhosesyntaxinludesthefollowingprodutions:

C::=truej=h

~

ij jC^Cj9 :C j:::

(;;::: rangeoveradenumerableset oftypevariablesV.)Thesyntaxofon-

straintsisonlypartiallyspeied;thisallowsustomonstraintforms,notknown

in thispaper,tobelaterintrodued.

ThelogiX mustbeequipped withaninterpretation in T,i.e. atwo-plae

prediate`whoserstargumentisanassignment,i.e.atotalmappingfromV

into T,andwhose seondargumentis aonstraintC.Theinterpretationmust

bestandard,i.e.satisfythefollowinglaws:

`true

`

0

=h~

1

i i (

0

)=h(~

1 )i

`

0

1

i (

0 )(

1 )

`C

0

^C

1

i `C

0

^`C

1

0 0 0

(8)

(ndenotestherestritionofto Vn .) Theinterpretationofanyunknown

onstraintformsisleftunspeied.WewriteCC 0

ifandonlyifCentailsC 0

,

i.e.ifandonlyifeverysolutionofC satisesC 0

aswell.

JOIN(X)hasonstrainedtypeshemes,whereanumberoftypevariables

areuniversallyquantied,subjettoaonstraintC.

Denition5.1. Atypeshemeisatripleofasetofquantiers , aonstraint

C, and a type variable ; we write = 8[C ℄:. The type variables in are

bound in ; type shemesare onsidered equal modulo -onversion. By abuse

of notation,atypevariable may beviewedasatype sheme 8?[true℄:. The

setof typeshemesiswritten S.

Denition5.2. A polymorphityping environment, denoted by or A, is a

S-environment. A monomorphi typing environment, denoted by B, is a V-

environment.

Denition5.3. JOIN(X) is dened by Fig. 3. Every judgement C ; ` J is

impliitly aompaniedby theside onditionthat C mustbesatisable.

JOIN(X)diersfromB(T)byreplaingmonotypeswithtypevariables,poly-

typeswithtypeshemes,andparameterizingeveryjudgementwithaonstraint

C,whihrepresentsanassumptionaboutitsfreetypevariables.RuleWeaken

allowsstrengtheningthisassumption,while9Introallowshidingauxiliarytype

variableswhihappearnowherebutintheassumptionitself.Theserules,whih

areommontonames,denitions,andproesses,allowonstraintsimpliation.

Beausewedonothavesyntaxfortypes,rulesJoinandMsguseonstraints

oftheform =h~i toenodetypestrutureintoonstraints.

Ourtreatmentofonstrainedpolymorphismisstandard.WhereasB(T)takes

an extensional view of polymorphism, JOIN(X) oers the usual, intensional

view.TypeshemesareintroduedbyruleDef,andeliminatedbyInst.Beause

impliit -onversionis allowed, every instane of Inst is able to renamethe

boundvariablesat will.

Forthesakeofreadability,wehavesimpliedruleDef,omittingtwofeatures

presentinHM(X)'s8 Introrule[6℄.First,wedonotforetheintrodutionof

existentialquantiersinthejudgement'sonlusion.InthepreseneofWeaken

and 9 Intro, doingsowould not aet theset of valid typing judgements, so

wepreferasimplerrule.Seond,wemovethewholeonstraintCinto thetype

shemes 8[C℄B, whereas it would be suient to opy only the part of C

whereatuallyours.Thisoptimizationanbeeasilyaddedbakinifdesired.

5.2 A Look atthe Generalization Condition

The most subtle (and, it turns out, questionable; see Set. 6.1) aspet of this

systemisthegeneralizationondition,i.e.thethirdpremiseofruleDef,whih

determineswhihtypevariablesmaybesafelygeneralized.Wewillnowdesribe

(9)

Denition5.4. IfB=(x

i :

i )

i2I

,then8[C℄B isthepolymorphienviron-

ment(x

i

:8[C℄:

i )

i2I

.This mustnot be onfused with the notation 8[C ℄:B,

wherethe universalquantierlies outsideof the environmentfragmentB.

Names

Inst

(u)=8[C℄:

C ; `u:

Sub-Name

C ; `u: 0

C

0

C ; `u:

Denitions

Empty

C ; `::

~

0

Join

C ; +(u~

i :~

i )

i2I

`P 8i2I C

i

=h~

i i

C ; `(xih~uii) i2I

.P::(xi:i) i2I

Or

C ; `D1 :B1 C ; `D2:B2

C ; `D1;D2::B1B2

Sub-Def

C ; `D::B 0

CB 0

B

C ; `D::B

Proesses

Null

C ; `0

Par

C ; `P C ; `Q

C ; `PjQ

Msg

C ; `u: C ; `~v:~ C=h~i

C ; `uh~vi

Def

C ; +B`(Ji.Pi) i2I

::B \fv( )=?

8i2I C8[C ℄:Bj

dn(J

i )

8[C℄Bj

dn(J

i )

C 0

; +8[C℄B`P C

0

C

C 0

; `def(Ji.Pi) i2I

inP

Common

Weaken

C 0

; `J CC 0

C ; `J

9Intro

C ; `J \fv( ;J)=?

9:C ; `J

Fig.3.ThesystemJOIN(X)(withatentativeDefrule)

Theexisteneofthese twonotations,andthequestionofwhether itislegal to

onfusethetwo,ispreiselyattheheartofthegeneralizationissue.Letushave

alookatruleDef.Itsrstpremiseassoiatesamonomorphienvironmentfrag-

mentBto thedenitionD=(J

i .P

i )

i2I

.Ifthetypevariablesdonotappear

freein ,then itissurelyorretto generalizethefragmentasawhole,i.e. to

assertthatDhastype8[C℄:B.However,thisisnolongeravalidenvironment

fragment, beause the quantier appears in front of the whole vetor; so, we

(10)

quantier down into eah binding, yielding 8[C℄B , whih is awell-formed

environmentfragment,andanbeusedto augment .

However,8[C℄B maybestritly moregeneralthan8[C℄:B, beauseit

binds separately in eah entry,rather thanone in ommon.We must avoid

this situation, whih would allow inonsistent uses of the dened names, by

properlyrestriting. (When isempty,thetwonotionsoinide.)

Toensurethat8[C℄B and8[C℄:B oinide,previousworks[4,7℄propose

syntati riteria, whih forbid generalization of a type variable if it appears

free in twodistint bindingsin B. Inan arbitraryonstraintlogi, however,a

syntatiourreneof atypevariable doesnotneessarilyonstrainitsvalue.

So,itseemspreferabletodenealogial,ratherthansyntati,riterion.Todo

so,werstgivelogialmeaningto thenotations8[C ℄B and8[C℄:B.

Denition5.5. The denotation of a type sheme = 8[C ℄: under an as-

signment,writtenJK

,isdenedas"f 0

();( 0

n=n ) ^ 0

`Cgif this

setis non-empty;itisundenedotherwise.

This denition interprets a typesheme asthe set of its instanes in T,

or, more preisely, as the upper one whih they generate. (Taking the one

aountsforthesubtypingrelationshipambientinT.)Itisparameterizedbyan

assignment,whih givesmeaningtothefreetypevariablesof.

Denition5.6. The denotation of an environmentfragment A= (u

i :

i )

i2I

under anassignment , written LAM

, isdened asJAK

=(u

i : J

i K

)

i2I

.

The denotation of 8[C℄:B under an assignment , written L8[C℄:BM

,is de-

nedas"f 0

(B);( 0

n=n ) ^ 0

`Cg.

This denition interprets environment fragments as a whole, rather than

point-wise. Thatis,LM

maps environmentfragmentstosetsoftuplesofmono-

types. A polymorphi environment fragment A maps eah name u

i

to a type

sheme

i

. Thefat thatthese typeshemesare independent ofoneanotheris

reetedinourinterpretationofAastheCartesianprodutoftheirinterpreta-

tions. Onthe other hand,8[C ℄:B is just a type sheme whose body happens

to beatuple, soweinterpretitas(theupperone generatedby)theset ofits

instanes,asinDenition 5.5.

Interpreting thenotations 8[C ℄B and 8[C℄:B within the samemathe-

matialspaeallowsustogivealogialriterionunderwhihtheyoinide.

Denition5.7. Bydenition, C 8[C℄:B 8[C℄B holds if andonly if,

under everyassignment suhthat`C,L8[C ℄:BM

L8[C℄B M

holds.

ThestrengthofthisriterionistobeindependentoftheonstraintlogiX.

ThisallowsustoproveJOIN(X)orretinapleasantgeneriway(seeSet.5.3).

Asanal remark,letuspointoutthat, independentlyofhowto dene the

generalizationriterion,there isalsoaquestionof howto apply it.It would be

orret for ruleDef to requireC 8[C℄:B 8[C℄B, asin [4℄. However,

(11)

redued,soitissuienttoseparatelyensurethatthemessageswhihappearin

eahlausehaveonsistenttypes.Asaresult,wesuessivelyapplytheriterion

to eah lauseJ

i .P

i

, byrestritingB to thesetof itsdened names,yielding

Bj

dn(J

i )

.Inthisrespet,weloselyfollowtheJoCamlimplementation[1℄aswell

asOderskyetal.[7℄.

5.3 TypeSoundness, Semi-Syntatially

ThissetiongivesatypesoundnessproofforJOIN(X)byshowingthatitissafe

withrespettoB(T).Thatis,weshowthateveryjudgementC ; `J desribes

the set of all B(T) judgementsof the form ( ` J), where ` C. Thus, we

give logial(rather than syntati) meaning to JOIN(X) judgements, yielding

a onise and natural proof. As a whole, the approah is still semi-syntati,

beauseB(T)itself hasbeenprovenorretinasyntatiway.

Denition5.8. When dened (f. Denition 5.5), JK

is a polytype, i.e. an

elementofS.ThedenotationfuntionJK

isextendedpoint-wisetotypingenvi-

ronments.Asaresult,if isanS-environment,thenJ K

isanS-environment.

Theorem5.9 (Soundness).Let(u:),(D::B), (P)stand for u:(),

D::(B), P,respetively.Then, `C andC ; `J imply J K

`(J).

Proof. Bystruturalindutiononthederivationoftheinputjudgement.Weuse

exatlythe notationsof Fig.3.In eah ase,weassumegiven somesolution

oftheonstraintwhihappearsin thejudgement'sonlusion.

CaseInst.WehaveJ K

(u)=J8[C ℄:K

3()beause`C.Theresult

followsbyb-Inst.

Case Sub-Name. The indution hypothesis yields J K

` u : ( 0

). The

seondpremiseimplies( 0

)().Applyb-Sub-Nametoonlude.

CaseEmpty.Immediate.

CaseJoin. LetB =(x

i :

i )

i2I

.Applying theindution hypothesis to the

rstpremiseyieldsJ K

+(u~

i :J~

i K

)

i2I

`P.SineJK

is"f()g,thismaybe

written J K

+(u~

i :(~

i ))

i2I

`P.(Reallthe abuseofnotationintroduedin

Denition4.3.)Theseondpremiseimplies8i2I (

i

)=h(~

i

)i .Asaresult,

byb-Join,J K

`D:(B)holds.

Case Or.Then, D is D

1

^D

2

and B is B

1 B

2

. Applying the indution

hypothesistothepremisesyieldsJ K

`D

i :(B

i

).Applyb-Ortoonlude.

Case Sub-Def. The indution hypothesis yields J K

` D : (B 0

). The

seondpremiseimplies(B 0

)(B).Applyb-Sub-Def toonlude.

CasesNull,Par.Immediate.

CaseMsg.Applyingtheindutionhypothesistothersttwopremisesyields

J K

` u: () and J K

`~v : (~ ).The last premise entails ()= h(~ )i.

Applyb-Msgto onlude.

Case Def. By hypothesis, ` C 0

; aording to the last premise, ` C

also holds. Let A = 8[C℄B. Take B 2 LAM

. Take i 2 I and dene B

i

=

Bj

dn(Ji)

. Then, B

i

is a memberof L8[C ℄Bj

dn(Ji) M

, whih, aordingto the

(12)

thirdpremise,isasubsetofL8[C℄:Bj

dn(J

i )

M

.Thus, thereexistsanassignment

0

suh that ( 0

n = n) ^ 0

` C and 0

(Bj

dn(J

i )

) B

i

. The indution

hypothesis,appliedtotherstpremiseandto 0

,yieldsJ +BK

0

`D::

0

(B).

ByLemma4.5,thisimpliesJ +BK

0 `J

i .P

i ::B

i .

Now,beause\fv( )=?,J K

0 isJ K

.Furthermore,giventheproperties

of 0

, we have JBK

0 J8[C ℄BK

= JAK

. As a result, by Lemma 4.4, the

judgementaboveimpliesJ K

+JAK

`J

i .P

i ::B

i .

Beausethisholds foranyi2I,repeateduseofb-Oryieldsaderivationof

J K

+JAK

`D::B.Lastly,beausethisholdsforanyB2LAM

,b-Genyields

J K

+JAK

`D::JAK

.

ApplyingtheindutionhypothesistothefourthpremiseyieldsJ K

+JAK

`

P.Applyb-Deftoonlude.

Case Weaken. The seond premise gives ` C 0

. Thus, the indution hy-

pothesismaybeappliedtotherstpremise,yieldingthedesiredjudgement.

Case 9 Intro. We have ` 9 :C . Then, there exists an assignment 0

suh that ( 0

n = n) ^ 0

` C. Consideringthe seond premise, wehave

J K

0

=J K

and

0

(J)=(J).Thus,applyingtheindutionhypothesistothe

rstpremiseandto 0

yieldsthedesiredjudgement.

This proof is, in our opinion, fairly readable. Infat, all asesexept Def

arenexttotrivial.

IntheDefase,wemustshowthat thedenition D hastypeJAK

, where

A=8[C℄B .BeauseB(T)hasextensionalpolymorphism(i.e.ruleb-Gen),

itsues toshowthatit haseverytypeB2JAK

. Notiehowwemustut

B into piees B

i

,orrespondingto eah lauseJ

i

,in order to makeuse ofthe

per-lausegeneralizationriterion.Weusetheindution hypothesisatthelevel

ofeahlause,thenreombinetheresultingtypederivationsusingb-Or.Notie

how we use Lemma 4.4; proving an environment strengthening lemma at the

levelofJOIN(X)wouldbemuhmoreumbersome.

Theeight non-syntax-diretedrulesare easily provenorret. Indeed,their

onlusiondenotesfewer(Sub-Name,Sub-Def,Weaken)orexatlythesame

(9Intro)judgementsinB(T)astheirpremise.Inasyntatiproof,thepresene

oftheseruleswouldrequireseveralnormalizationlemmas.

Corollary 5.10. Nowell-typedproess getsfaulty throughredution.

Proof. Assume C ; ` P. Beause C mustbesatisable, it must haveat least

onesolution.ByTheorem5.9, J K

`P holdsin B(T).Theresultfollowsby

Theorems4.6and4.8.

6 Type Inferene

6.1 Troublewith Generalization

Twosevere problems quikly arise when attempting to dene aomplete type

infereneproedureforJOIN(X).Bothareausedbythefragility ofthelogial

(13)

Def

C ; +B`(Ji.Pi) i2I

::B \fv( )=?

(9i2I jdn(Ji)j>1))=?

C 0

; +8[C℄B`P C 0

C

C 0

; `def(Ji.Pi) i2I

inP

Fig.4.DenitiveDefrule

Non-determinism.Tobeginwith,theriterionisnon-deterministi.Itstates

asuientonditionforagivenhoieoftobeorret.However,thereseems

tobe,ingeneral,nobest hoie.

Non-monotoniity.Moresubtly,strengthening theonstraintCmay,insome

ases,auseapparentorrelationstodisappear. Considertheenvironmentfrag-

ment B = (a: ;b : ) under the onstraint? = (assuming thelogi X

oerssuhaonstraint,tobereadifisnon-?,thenmustequal).Thereis

aorrelationbetweenaandb,beause,inertainases(thatis,when6=?),

and mustoinide.However,letus nowaddtheonstraint=?.Weobtain

?=^=?,whihis logiallyequivalentto =?.Itislearthat,under

thenewonstraint,aandbarenolongerorrelated.So,thesetofgeneralizable

typevariablesmayinreaseastheonstraintCismademorerestritive.

GivenadenitionD,anaturaltypeinferenealgorithmwillinfertheweakest

onstraintC under whih it is well-typed, then will useC to determinewhih

typevariables maybegeneralized.Beauseof non-monotoniity, thealgorithm

may nd apparent orrelations whih would disappear if the onstraint were

deliberatelystrengthened. However,there isno wayfor thealgorithm to guess

ifandhowitshoulddoso.

These remarks showthat it is diult to dene a omplete type inferene

algorithm,i.e.onewhih provablyyieldsasingle,mostgeneraltyping.

Previousworks[4,7℄useasimilartype-basedriterion,yetreportnodiulty

withtypeinferene.Thisleadsustoonjeturethattheseproblemsdonotarise

when subtyping is interpreted asequality and no ustom onstraint forms are

available. This may be truefor other onstraintlogis aswell. Thus, a partial

solution would be to dene a type inferene proedure only for those logis,

takingadvantageoftheirpartiularstruture toproveitsompleteness.

Inthegeneralase,i.e.underanarbitraryhoieofX,weknowofnosolution

otherthantoabandonthelogialriterion.Wesuggestreplaingitwithamuh

morenaïveone, basedon thestruture of the denition itself, ratherthan on

typeinformation.OnepossiblesuhriterionisgiveninFig.4.Itsimplyonsists

inrefusinggeneralizationentirelyifthedenitioninvolvesany synhronization,

i.e.ifanyjoin-patterndenesmorethanonename.(Itispossibletodoslightly

better,e.g.bygeneralizingallnamesnotinvolvedinasynhronizationbetween

twomessages of non-zeroarity.) It is learly safewith respet to theprevious

(14)

The new riterion is deterministi, and impervious to hanges in C, sine

it depends solely on the struture of the denition D. It is the analogue of

theso-alledvaluerestrition,suggestedbyWright[10℄,nowinuseinmostML

implementations.ExperienewithMLsuggeststhatsuharestritionistolerable

in pratie;aquikexperimentshowsthat allofthesampleodebundled with

JoCaml[1℄iswell-typedunder it.

Inthefollowing,weadopttherestritedDefruleofFig.4.

6.2 A Type Inferene Algorithm

Fig.5givesaset ofsyntax-diretedtypeinferenerules.Again,ineveryjudge-

mentC ; `

I

J,itisunderstoodthatCmustbesatisable.Therulesimpliitly

desribeanalgorithm,whoseinputsareanenvironment andasub-termu,D

or P, andwhoseoutput, inaseofsuess, isajudgement.Rulei-Orusesthe

followingnotation:

Denition6.1. The least upperbound of B

1 and B

2

, written B

1 tB

2 , is a

pair ofamonomorphi environmentandaonstraint.Itisdenedby:

B

1 tB

2

=(u:

u )

u2U

;

^

i2f1;2g;u2dom (Bi) B

i

(u)

u

whereU =dom(B

1

)[dom(B

2

)andthe typevariables (

u )

u2U

arefresh.

Following[9℄, wehavesaturatedeverytypeinferenejudgementbyexisten-

tialquantiation.Althoughslightlyverbose,thisstylenielyshowswhihtype

variablesareloalto asub-derivation,yieldingthefollowinginvariant:

Lemma6.2. IfC ; `

I

J holds,thenfv (C)fv( ;J)andfv (J)\fv( )=?.

We now prove the type inferene rules orret and omplete with respet

to JOIN(X). For the sake of simpliity, welimit the statement to the ase of

proesses(omittingthat ofnamesanddenitions).

Theorem 6.3. C ; `

I

P impliesC ; `P.Conversely,ifC ; `P holds,then

thereexistsaonstraintC 0

suhthat C 0

; `

I

P andCC 0

.

7 Disussion

JOIN(X) is losely related to HM(X) [6, 8℄, a similar type system aimed at

purelyfuntionallanguages.Italsodrawsinspirationfromprevioustypesystems

forthejoin-alulus [4,7℄, whihwerepurely uniation-based.JOIN(X)isan

attemptto bringtogetherthesetwoorthogonallinesofresearh.

Ourresultsarepartlynegative:under anaturalgeneralizationriterion,the

existeneofprinipaltypingsisproblemati.Thisleadsus,in thegeneralase,

tosuggestamoredrastirestrition.Nevertheless,thelogialriterionmaystill

(15)

Names

i-Inst

(u)=8[C℄: fresh

9:(C ^); `

I u:

Denitions

i-Empty

true; `I::

~

0

i-Join

C ; +(u~

i :~

i )

i2I

`

I

P (~

i )

i2I

;(

i )

i2I

fresh

9(

i )

i2I

:(C^

^

i2I

i

=h~

i i); `

I (x

i h~u

i i)

i2I

.P ::(x

i :

i )

i2I

i-Or

C

1

; `

I D

1 :B

1 C

2

; `

I D

2 :B

2

B;C=B1tB2

=fv(B1;B2)

9

:(C

1

^C

2

^C); `

I D

1

;D

2 ::B

Proesses

i-Null

true ; `

I 0

i-Par

C

1

; `

I

P C

2

; `

I Q

C

1

^C

2

; `

I PjQ

i-Msg

C ; `

I u:

~

C; `

I

~v:~

9:(C ^

~

C^=h~i); `Iuh~vi

i-Def

B fresh

=fv(B)

C

1

; +B`

I (J

i .P

i )

i2I

::B 0

0

=fv(B 0

) C2=9

0

:(C1^B 0

B)

if9i2I jdn(J

i

)j>1then=?else =

C3; +8[C2℄B`IP

9

:(C

2

^C

3 ); `

I def(J

i .P

i )

i2I

inP

Fig.5.Typeinferene

still beahieved, orin situations where their existene isnot essential(e.g. in

programanalysis).

Toestablishtypesafety, weinterpret typing judgements as(sets of) judge-

mentsinanunderlyingsystem,whih isgivenasyntatisoundnessproof.The

formerstep,bygivingalogialviewofpolymorphismandonstraints,aptlyex-

pressesourintuitionsaboutthesenotions,yieldingaoniseproof.Thelatteris

amatterofroutine,beausethelow-leveltypesystemissimple.Thus,bothlogi

andsyntaxareputtobestuse.Wehavebaptizedthisapproahsemi-syntati;

wefeelitisperhapsnotpubliizedenough.

Aknowledgements

AlexandreFreysuggestedtheuseofextensionalpolymorphismintheintermedi-

(16)

ofonstraint-basedtypeinfereneinHM (X),whihwashelpfulinourownom-

pleteness proof.Wewould alsoliketoaknowledgeMartin OderskyandDidier

Rém yforstimulatingdisussions.

Referenes

[1℄ Sylvain Conhon and FabrieLeFessant. Joaml: Mobile agentsfor Objetive-

Caml. InFirstInternationalSymposiumonAgentSystemsandAppliationsand

Third International Symposium on Mobile Agents (ASA/MA'99), pages 2229,

PalmSprings,California,Otober1999.URL:http://para.inria.fr/~onhon /

publis/asa99.ps.gz.

[2℄ Sylvain Conhon and François Pottier. JOIN(X): Constraint-based type infer-

ene for the join-alulus. Long version. URL: http://pauilla.inria.fr/

~fpottier/publis/onhon-fpotti er-e sop01 -lo ng.ps .gz, April2001.

[3℄ CédriFournet andGeorgesGonthier. Thereexive hemialabstratmahine

andthejoin-alulus. InProeedingsofthe23rdACMSymposiumonPriniples

ofProgrammingLanguages,pages372385,1996.URL:http://pauilla.inria.

fr/~fournet/papers/popl-96.ps.g z.

[4℄ CédriFournet,LuMaranget,CosimoLaneve,andDidierRémy.Impliittyping

àla ML for the join-alulus. In8th InternationalConferene onConurreny

Theory(CONCUR'97),volume1243ofLetureNotesinComputerSiene,pages

196212, Warsaw, Poland, 1997. Springer. URL: ftp://ftp.inria.fr/INRIA/

Projets/ristal/Didier.Remy/typ ing-join .ps.g z.

[5℄ RobinMilner. Atheoryoftypepolymorphisminprogramming.JournalofCom-

puterandSystemSienes,17(3):348375,Deember1978.

[6℄ MartinOdersky,MartinSulzmann,andMartinWehr. Typeinferene withon-

strained types. Theory andPratie of ObjetSystems, 5(1):3555, 1999. URL:

http://www.s.mu.oz.au/~sulzmann /pub liat ions/ tapo s.ps.

[7℄ MartinOdersky, ChristophZenger, Matthias Zenger, and Gang Chen. Afun-

tionalviewofjoin.TehnialReportACRC-99-016,UniversityofSouthAustralia,

1999. URL: http://lampwww.epfl.h/~zenge r/pap ers/ tr-a r-99-0 16.ps .

gz.

[8℄ Martin Sulzmann. A general framework for Hindley/Milner type systems with

onstraints. PhDthesis,YaleUniversity,DepartmentofComputerSiene,May

2000. URL:http://www.s.mu.oz.au/~sulzmann /publ iat ions/ diss. ps.g z.

[9℄ MartinSulzmann, Martin Müller, and Christoph Zenger. Hindley/Milner style

type systemsinonstraint form. ResearhReportACRC99009, University of

SouthAustralia, ShoolofComputerandInformationSiene,July1999. URL:

http://www.ps.uni-sb.de/~mmuell er/pa pers /hm-onst rain ts.ps .gz.

[10℄ AndrewK.Wright. Simpleimperative polymorphism. Lispand Symboli Com-

putation,8(4):343356,Deember1995.

[11℄ AndrewK.WrightandMatthiasFelleisen. Asyntatiapproahtotypesound-

ness. InformationandComputation,115(1):3894,November1994. URL:http:

//www.s.rie.edu/CS/PLT/Publia tion s/i9 4-wf .ps. gz.

Références

Documents relatifs

In this paper we consider the implementation of the Partition Based Spatial Merge Join [13] provided by SpatialHadoop, de- noted as Sjmr, which is the only spatial join algorithm

In this paper we introduce a binary graph join opera- tor and a corresponding algorithm outperforming the solu- tion proposed by query languages for either graphs (Cypher, SPARQL)

Today it is… Tomorrow it will be…!. Yesterday it was…

This could lead to huge orders for electronics firms, 71___ is why, in his recent jobs speech, President Barack Obama called for $1 billion of extra _72__ to speed up

In particular, this class includes in dimension N = 2 the nonlinear potentials w 2 with w being an harmonic function or a solution to the wave equation, while in dimension N >

For each database instance I and for each goal join predicate θ, we have considered two measures: the number of user interactions (i.e., the number of tuples that need to be

For each database instance I and for each goal join predicate θ, we have considered two measures: the number of user interactions (i.e., the number of tuples that need to be

As already explained for the interactive inference process, we repeatedly show the most informative pair of pictures to the attendee that she labels as positive or negative un- til