ebook img

Functional Programming, Glasgow 1995: Proceedings of the 1995 Glasgow Workshop on Functional Programming, Ullapool, Scotland, 10-12 July 1995 PDF

193 Pages·1996·0.957 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Functional Programming, Glasgow 1995: Proceedings of the 1995 Glasgow Workshop on Functional Programming, Ullapool, Scotland, 10-12 July 1995

ELECTRONIC WORKSHOPS IN COMPUTING Series edited by Professor C.J. van Rijsbergen David N. Turner (Ed) Functional Programming, Glasgow 1995 Proceedings of the 1995 Glasgow Workshop on Functional Programming, Ullapool, Scotland, 10-12 July 1995 Paper: Uniqueness Typing in Natural Deduction Style Erik Barendsen and Sjaak Smetse Published in collaboration with the British Computer Society BCS (cid:211) Copyright in this paper belongs to the author(s) Uniqueness Typing in Natural Deduction Style ErikBarendsen SjaakSmetsers UniversityofNijmegen,ComputingScienceInstitute Toernooiveld1,6525ED Nijmegen,TheNetherlands [email protected],[email protected] Abstract Wepresenttwotypesystemsforgraphrewriting: conventionaltypingand(polymorphic)uniquenesstyping. The latterisintroducedasanaturalextensionofsimplealgebraicandhigher-orderuniquenesstyping. Thesystemsare giveninnaturaldeductionstyleusinganinductivesyntaxofgraphdenotationswithfamiliarconstructssuchaslet andcase. TheconventionalsystemresemblestraditionalCurry-styletypingsystemsinfunctionalprogramminglanguages. Uniquenesstypingextendsthiswithreferencecountinformation. Inbothtypesystems,typingispreservedduring evaluation,andtypescanbedeterminedeffectively. Duetothepresentformalization,thesystemcaneasilybecomparedwithotherproposalsbasedonlinearandaffine logic. 1 Introduction Inrecentyears,variousproposalshavebeenbroughtupassolutionstothe—atfirstsightparadoxical—desiretoallow destructiveoperationsinafunctionalcontext. Indeed,byadmittingtheseoperations(suchasfilemanipulations)onelosesreferentialtransparency. Theessence ofcommonsolutions(e.g., Wadler(1990), Guzma´nandHudak(1990))istherestrictionofdestructiveoperationsto argumentswithreferencecount . Theuniquenesstypesystemf1orgraphrewritesystems(presentedinBarendsenandSmetsers(1993a)and (1993b)) offersthepossibilitytoindicatesuchreferencecountrequirementsoffunctionsinthetypesofthecorrespondingargu- ments. Thesespecialso-calleduniquenesstypesareannotatedversionsoftraditionalCurry-liketypes. E.g.theoper- ation whichwritesacharactertoafileistypedwith . Here, (cid:2) (cid:15) (cid:15) standWforr‘iuteniCquhea’rand‘non-unique’respectively. WriteChar:(Char ;File ) File (cid:15);(cid:2) Uniquenesstypingcanberegardedasacombinationoflineartyping(dealingwithuniqueobjects)andtraditional typing(fornon-uniqueobjects,withoutrestrictionsontheirreferencecounts),connectedbyasubtypingmechanism. Infact,theparthandlinguniquenessallowsdiscardingofobjects, soitcorrespondsmorecloselytoaffinelogic, see Blass(1992). Alogical/categoricalproposalforarelatedcombinationappearsinBenton(1994). Thepresentpaperdescribesasimplifiedversionofthesysteminnaturaldeductionstyle,usinganinductivesyntax forgraphexpressions. Theemphasisongraphdenotationscontraststheoriginalpresentation,whichreferreddirectly tothenode/referencestructureof(non-inductive)graphobjects. Thegraphsyntaxissimilartotheobjectlanguagein theequationalapproachtowardsTermGraphRewritingofAriolaandKlop(1995). WestartwithaspecificationoftheformallanguageanddefineaCurry-like(conventional)typesystem. Aftera verybriefintroductiontouniquenesstyping,adescriptionoftheuniquenesstypeassignmentsystemisgiven. Forboth systemsweprovepreservationoftypingduringreductionandtheexistenceofprincipaltypes. Theoriginaluniquenesstypesystemisrathercomplex. Toavoidthatthereadergetsentangledintechnicaldetails, thereferenceanalysisiskeptassimpleaspossible: itdoesnottaketheevaluationorderintoaccount. Fordetails,see BarendsenandSmetsers(1993a). Independently, Turneretal. (1995) havedevelopedastronglyrelated systembased on -calculus. Theresearch reportedtherehasbeenguidedbydifferentobjectives. (cid:21) FunctionalProgramming,Glasgow1995 1 UniquenessTypinginNaturalDeductionStyle Uniqueness typing is now part of the functional programming languageClean, see Plasmeijer and van Eekelen (1995). 2 Syntax Wepresentasyntaxofaformallanguagewhichincorporatessomeessentialaspectsofgraphrewriting:sharing,cycles andpatternmatching. Theobjectsareexpressionsgeneratedbythefollowingsyntax. let in letrec in case of 0 0 E ::= xjS(E1;:::;Ek)j x=E E j ~x=E~ E j E P~jE~; P ::= C(x1;:::;xk): Here rangeover(sequencesof)termvariables,and oversomesetofsymbolsoffixedarity(wewillsometimes suggexst;i~xvelyuse forfunctionsand fordataconstrucStors). Patterns(indicatedby intheabovesyntax)aresup- posedtobelinearF: novariableisoccuCrringmorethanonceinthesamepattern. P Theexpressionsareinterpretedasgraphs. Sharingmanifestsitselfbymultipleoccurrencesofthesamevariables. Sharingofcompoundstructuresisexpressedbyaletbinding,whereas introducescyclicdependencies. E.g.,the expression letrec let inletrec in x=0 z =F(Cons(x;G(x;z))) z denotesthegraph Fjj (cid:15)(cid:15) Cons ~~~~~~~ BBBBB 0‘‘ G Operationsonobjectsaredefinedusingfunctiondefinitions. Thegeneralformoftheseis F(x1;:::;xk)=E: Forexample, case of Append(‘1;‘2)= ‘1 Cons(h;t) j Cons(h;Append(t;‘2)) Nil j ‘2: The operational semantics of our language is given by the concept of Term Graph Rewriting, see Barendregt et al. (1987). Each expression is translated to agraph denoted by . Function definitionsaretranslated into rewrite rules, inducing a (multisteEp) rewrite relation on graphs (cf.[[BEa]]rendsen and Smetsers (1993a)). In contrast with AriolaandKlop(1995),werefrainfromdefin!i!ngareductionrelationontheexpressionsthemselves. 3 Conventional Typing Typesarebuiltupfromtypevariablesandtypeconstructors. (cid:27) ::= (cid:11)jT~(cid:27) j(cid:27)1!(cid:27)2: Here, rangesoveralgebraictypeconstructorswhichareassumedtobeintroducedbyanalgebraictypesystem containTingspecificationslike A List((cid:11))=Cons((cid:11);List((cid:11)))jNil: Thefunctionspacetypeconstructor isusedwhendealingwithhigher-orderfunctions. Wewilltreattheseonlyin theuniquenesscase. ! FunctionalProgramming,Glasgow1995 2 UniquenessTypinginNaturalDeductionStyle Thealgebraictypesystem givesthetypesofthealgebraicconstructors. Let A T(cid:11)~ =C1(cid:27)~1j(cid:1)(cid:1)(cid:1) beadeclarationin . Then A A‘Ci :(cid:27)~i T(cid:11)~ Forexample,forlistsonehas A‘Nil:List((cid:11)); A‘Cons:((cid:11);List((cid:11))) List((cid:11)): Thefunctionsymbolsaresupplied with atype by afunction typeenvironment , containingdeclarations of the form F F:((cid:27)1;:::;(cid:27)k) (cid:28); where isthearityof . Inthiscasewewrite k F F ‘F:~(cid:27) (cid:28): Thesymboltypesobtainedsofararereferredtoasthestandardtypes(in )ofthesymbols. Theseareregarded astypeschemes: othertypesareobtainedbyinstantiation,usingthefollowinFg;rAule( denotessubstitution). [(cid:11):=(cid:26)] F;A‘S:~(cid:27) (cid:28) F;A‘S:~(cid:27)[(cid:11):=(cid:26)] (cid:28)[(cid:11):=(cid:26)] Oursystemdealswithtypingstatementsoftheform B ‘E :(cid:27); where issomefinitesetofvariabledeclarationsoftheform calledabasis. Suchastatementisvalidifitcanbe producBedusingthefollowingderivationrules. x:(cid:28) B;x:(cid:27)‘x:(cid:27) (variable) F;A‘S:~(cid:27) (cid:28) B‘E~ :~(cid:27) (application) B‘SE~ :(cid:28) 0 B‘E:(cid:27) B;x:(cid:27)‘E :(cid:28) let in 0 (sharing) B‘ x=E E :(cid:28) 0 B;~x:~(cid:27)‘Ei :(cid:27)i B;~x:~(cid:27)‘E :(cid:28) letrec in 0 (cycle) B‘ ~x=E~ E :(cid:28) 0 B‘E :(cid:28) A‘Ci :(cid:27)~i (cid:28) B;x~i:(cid:27)~i ‘Ei:(cid:28) (patternmatching) case of 0 (if ) B ‘ E P~jE~ :(cid:28) Pi=Cix~i Thisconcludesthetreatmentofexpressions. Astofunctiondefinitions,theenvironment shouldbeconsistent withthese. Wesaythatthefunction F F~x=E; saywithstandardtype ,istypecorrectif F:~(cid:27) (cid:28) ~x:~(cid:27) ‘E :(cid:28): Typingispreservedduringreduction(theso-calledsubjectreductionproperty). FunctionalProgramming,Glasgow1995 3 UniquenessTypinginNaturalDeductionStyle SUBJECTREDUCTIONTHEOREM. Supposethefunctiondefinitionsaretypecorrect. Then 0 0 0 B ‘E :(cid:27); [[E]]!!g ) 9E [[E ]]=g & B ‘E :(cid:27): Thesystemhastheprincipaltypeproperty: eachtypableexpression hasatypefromwhichallothertypesfor canbeobtainedbyinstantiation. E E PRINCIPALTYPE THEOREM. Let betypable. Thenthereexist (computablefrom )suchthat andforany and E B0;(cid:27)0 E B0 ‘E :(cid:27)0 B (cid:27) forsomesubstitution . (cid:3) (cid:3) B ‘E :(cid:27) ) B (cid:19)B0;(cid:27) =(cid:27)0 (cid:3) 4 Simple Uniqueness Typing Uniquenesstypingcombinesconventionaltypingandlineartyping,throughareferencecountadministration. Anen- vironmenttype meansthat ’sargumentshould beuniquefor , i.e., shouldhavereferencecount1. InthesamewayF,un:i(cid:27)qu(cid:15)e nes(cid:1)s(cid:1)o(cid:1)fresultsissFpecified: if ,thenaweFll-typedexpression remains type-correct,evenif issubjecttocomputation. SGom:e(cid:1)ti(cid:1)m(cid:1) es,(cid:27)u(cid:15)niquenessisnotrequired. If F(G(E))thenstill istypecorGre(cEt.)Thisisexpressedinasubtyperelation,suchthatroughly . OFff:e(cid:27)ri(cid:2)ng a(cid:1)n(cid:1)o(cid:1)n-unique (cid:15) (cid:2) Far(gGum(Een)t)ifafunctionrequiresauniqueonefails: . Thesubtyperelationis(cid:27)de(cid:20)fin(cid:27)edintermsoftheordering (cid:2) (cid:15) onattributes. (cid:27) (cid:2) (cid:27) (cid:15) (cid:20)T(cid:2)henon-unique(‘conventional’)andunique(‘linear’)typesarealsoconnectedbyacorrectionmechanism:aunique resultmaybeusedmorethanonce,aslongasonlynon-uniquesupertypesarerequired. Pattern matching(expressed by the caseconstruction) is an essentialaspect of term graph rewriting, causing a functiontohaveaccesstoargumentsviadatapathsinsteadofasinglereference. Thisgivesriseto‘hiddensharing’of objectsbyaccessviaintermediatedatanodes. Forexample,ifafunction hasaccesstoalistwithnon-uniquespine, thelistelementsshouldalsobeconsideredasnon-uniquefor : otherfunFctionsmayaccessthemviathespine. This effectistakenintoaccountbyarestrictionontheuniquenessFtypesofdataconstructors: theresultofaconstructoris uniquewheneveroneofitsargumentsis. Thisuniquenesspropagationcanbeexpressedusingthe relation. Inthe caseoflists,forexample, (cid:20) u v u v u Cons:((cid:11) ;List ((cid:11) )) List ((cid:11) ) iswell-attributedif (thisindeedexcludesaconstructorfor ). Notethattheattributeofanon-variable (cid:2) (cid:15) typeisattachedtoitvs(cid:20)topumosttypeconstructor. List (Int ) InBarendsenandSmetsers(1993a),thetypingsystemisshowntobesoundwithrespecttotermgraphrewriting, withtheabove-mentionedinterpretationofuniqueness. AlgebraicUniqueness Types Wewillfirstdescribethesystemwithoutthetypeconstructor . Below, rangeoveruniquenesstypes. The outermostattributeof isdenotedby . ! S;T;::: ThesubtyperelatioSnisverysimplep:Stqhevalidityof dependssubtypewiseonthevalidityof with 0 0 attributesin . Onehas,forexample, S (cid:20) S u (cid:20) u 0 0 u;u S;S u v w u0 v0 w0 iff 0 0 0 List (List (Int ))(cid:20)List (List (Int )) u(cid:20)u;v (cid:20)v ;w(cid:20)w : Inordertoaccountformultiplereferencestothesameobjectweintroduceauniquenesscorrection: iftheobjectin questionhastype ,thenonlynon-uniqueversionsof maybeused. Given ,weconstructthesmallestnon-unique supertypeof : S S S S u (cid:2) [(cid:11) ] = (cid:11) ; u (cid:2) [T S~] = T S~: FunctionalProgramming,Glasgow1995 4 UniquenessTypinginNaturalDeductionStyle Thelastclausepossiblyintroducestypeslike . ContrastingTurneretal.(1995),weallowthesetypesinour (cid:2) (cid:15) system. Thisisharmlesssincethese‘inconsisLtiesntt’(tIynpte)shavenoinhabitants(forexample,thereisno yielding type ). Cons (cid:2) (cid:15) CLyicsltic(oInbtje)cts(withtheirinherentsharing)aretreatedbycorrectingbothinternalandexternalreferencestotheir roots. Thenotionofstandardtypeisadaptedinthefollowingway. Asbefore,standardtypesoffunctionsymbols( )arecollectedinanenvironment . F : S~ ATscanbeseenfromthe exampleF,thereareseveralstandardtypesforeachdataconstructor. Saythealgebraic environment contains List A T(cid:11)~ =C1(cid:27)~1j(cid:1)(cid:1)(cid:1) Asetofstandardtypesfor consistsofattributedversionsoftheconventionaltype ,suchthat (1) multipleoccurrenceCsoifthesamevariableandoftheconstructor havethesam(cid:27)~eiu niqTu(cid:11)~enessattributethrough- outeachversion; T (2) eachversionisuniquenesspropagating; (3) thesetcontainsatmostoneversionforeachattributedvariantof . ThisleavessomefreedomastothechoiceofattributesonpositionsnotcorTre(cid:11)~spondingto . BarendsenandSmetsers (1993a)offerageneralmethodforconstructingareasonablesetofstandardtypesforeaTc;h(cid:11)~constructor. Inmostcases (like , see above), however, the choice of attributes of fixes those for the . From now on we assume that standaLridsttypeshavebeendetermined. ForthesestandardtypTe(cid:11)~s weset (cid:27)~i asbefore. Symboltypesareinstantiatedviatherule S~ T A‘C:S~ T F;A‘S:S~ T p(cid:11)q=pRq (instantiation) F;A‘S:S~[(cid:11):=R] T[(cid:11):=R] Auniquenesstypingstatement(in )hastheform F;A B ‘E :S: Inourlanguage,sharingappearsasmultipleoccurrencesofthesamevariable. Likeinlinearlogic,wehavetobeprecise whendealingwithbasesusedfortypingsubterms: thedenotation standsforadisjointunionofbases. Therulesfortypeassignmentarethefollowing. B1;B2 x:S‘x:S (variable) F;A‘S:S~ T Bi ‘Ei :Si (application) B~ ‘SE~ :T 0 0 B‘E :S B ;x:S‘E :T 0 let in 0 (sharing) B;B ‘ x=E E :T 0 0 Bi;~x:[S~]‘Ei :Si B ;~x:[S~]‘E :T 0 letrec in 0 (cycle) B~;B ‘ ~x=E~ E :T 0 0 B‘E :T F;A‘Ci:S~ T B ;x~i :S~i ‘Ei:T (patternmatching) 0 case of 0 (if ) B;B ‘ E P~jE~ :T Pi =Cix~i 0 B‘E:S S(cid:20)S 0 (subsumption) B‘E:S FunctionalProgramming,Glasgow1995 5 UniquenessTypinginNaturalDeductionStyle Additionally,wehavethefollowing‘structuralrules’. Weakeningexpressesthatonecandiscard(uniqueornon- unique)input. Thecontractionruledealswithcorrectionoftypesofsharedobjects: multipleuseofthesameobjectis allowedaslongasonlynon-uniquevariantsofthetypesareused. B‘E :T (weakening) B;x:S‘E:T B;y:[S];z:[S]‘E:T (contraction) B;x:S ‘E[y:=x;z:=x]:T Likeintheconventionalcase, shouldbeconsistentwiththefunctiondefinitions. Afunction F F~x=E; saywithstandardtype ,istypecorrectif F:S~ T ~x:S~ ‘E :T: Higher-OrderUniqueness Types Wewillnowdescribetheincorporation ofhigher-orderfunctions. Higher-order functions giveriseto partial(often calledCurried)symbolapplications. Infunctionalprogramminglanguages,theseapplicationsareusuallywrittenas (with )),denotingthefunction FE1(cid:1)(cid:1)(cid:1)Ek k <arity(F (cid:21)~x:F(E1;:::;Ek;xk+1;:::;xarity(F)): Ifthesepartialapplicationscontainuniquesubexpressionsonehastobecareful. Consider,forexample,afunction FIfowniethatlylopwesFth:a(t(cid:27)th(cid:15);is(cid:28)a(cid:2)p)p lic(cid:27)a(cid:15)tioinntihseuaspepdlmicaotrieonthFanEo.nCcele,aornlye,cthanenroestuglutatyrapneteoeftthhiesaarpgpulmiceantitoni(swoifththteypfoerm)(cid:28)r(cid:2)em!ua(cid:27)in(cid:15)s. (cid:15) uniqueduringevaluation. E.g.if ispassedtoafunction ,theoccurrencEesof willr(cid:27)esultintwo applicationsof sharingthesamFeEexpression . ApparentlGy,(tfh)e=(fe0x;pfre1s)sionisnecessarilyunfique: itsreference countshouldneFverbecomegreaterthan1. TheEreareseveralwaysFtEopreventsuchanexpressionfrombeingcopied. For instance, one might introduce a new uniqueness attribute, say , for any unique object that does not coerce to 4 a non-unique variants. This has been described in Barendsen and Smetsers (1993a). An alternative solution is the administrationofso-calledregionsintroducedbyReynolds(1995). Insteadof introducinganewattribute, thepresentpaperconsidersthe constructorincombinationwiththe (cid:15) attributeasspecial: itisnotpermittedtodiscarditsuniqueness. Theleadst!oanadjustmentofthesubtypingrelations aswellasofthetypecorrectionoperator . Astothesubtypingrelation,theattribu[(cid:1)t]esofcorrespondingoccurrencesofthe constructors(intheleft-handand theright-handsideofaninequality)shouldbeidentical. Thesameisrequired(toe!nsuresubstitutivityofthesubtyping relation)forvariables. Thesubtypingrelationbecomesinherentlymorecomplexthaninthealgebraiccasebecauseoftheso-calledcon- travarianceof initsfirstargument: ! u 0 u 0 0 0 S!S (cid:20)T !T , T (cid:20)S; S (cid:20)T : Since may appear inthedefinitionsofalgebraictypeconstructors, theseconstructorsmayinherittheco-orcon- travari!antsubtyping behaviour with respectto their arguments. Wecanclassify the‘sign’ of thearguments of each typeconstructoras (positive,covariant), (negative,contravariant)or (bothpositiveandnegative). Ingeneral thisisdonebyanaly(cid:8)zingthe(possiblymutua(cid:9)llyrecursive)algebraictypede>finitionsbyafixedpointconstruction,with basis . Thesubtypingrelation isdefinedbyinduction. sign(!)=((cid:9);(cid:8)) (cid:20) FunctionalProgramming,Glasgow1995 6 UniquenessTypinginNaturalDeductionStyle Notation. (cid:8) (cid:9) S (cid:20) T , S (cid:20)T; anSd(cid:20) T , T (cid:20)S; > (cid:8) (cid:9) S (cid:20) T , S (cid:20) T forSeac(cid:20)h T; Nowset S~ (cid:20)~s T~ , Si (cid:20)si Ti i: u v (cid:11) (cid:20)(cid:11) , u=v; and TuS~ (cid:20)TvT~ , u(cid:20)v S~ (cid:20)sign(T) T~; u 0 v 0 and (cid:9) and 0 (cid:8) 0 S!S (cid:20)T !T , u=v S (cid:20) T S (cid:20) T : E.g. u v w u0 v0 w0 iff 0 0 0 Int !(cid:12) (cid:20)Int !(cid:12) u (cid:20)u;v =v ;w =w : Adjustingthetypecorrectionoperatoriseasy: correctionof (cid:15) typessimplyfails. Thustheoperator becomesa partialfunction: ! [(cid:1)] if , u (cid:2) [(cid:11) ] = (cid:11) u=(cid:2) u (cid:2) [T S~] = T S~; u (cid:2) if , [S!T] = S!T u=(cid:2) (undefined) inallothercases. [S] = " Partialapplicationscanbeincorporatedinourformalsystemasfollows. Anapplication iswrittenas (so ). Moreoverweaddtheapplicationoperator tooursynFtaEx1w(cid:1)it(cid:1)h(cid:1)Eefkfect(roughly) Fk(E1;:::;Ek) Farity(F) =F Ap Ap(Fk(E~);E0)=Fk+1(E~;E0): Thetypeof isdefinedintermsthetypeof bythefollowingrule. Fk Fk+1 0 F;A‘Fk+1 :(S~;T) T u(cid:20)(cid:5)pS~q u 0 (Curry) F;A‘Fk :S~ (T !T ) Here, stands for the so-called cumulativeuniqueness attributeof : itequals whenever some is , and otherw(cid:5)is~ue. ~u (cid:15) ui (cid:15) (cid:2) Thetypingrulefor isdefinedstraightforwardly. Ap u 0 0 B‘E:S!T B ‘E :S (curriedapplication) 0 0 B;B ‘Ap(E;E ):T 5 Polymorphic Uniqueness Typing Inordertodenoteuniquenessschemes,weextendtheattributesetwithattributevariables( ). Thisincreases the expressivity of the type system. Moreover, attribute polymorphism is needed for thead;ebt;ear1m;i:n:a:tion of principal types. Uniquenessconstraintsareindicatedby(finite)setsofattributeinequalitiescalledcoercionenvironments. For example,thestandardtypeofthesymbol isnowexpressedby Cons a b a b a Cons:((cid:11) ;List ((cid:11) )) List ((cid:11) ) j b(cid:20)a: Allnotionsoftheprevioussection(typeenvironment,subtyping,typederivation)arere-definedrelativetocoercion environments. FunctionalProgramming,Glasgow1995 7 UniquenessTypinginNaturalDeductionStyle Astotheattributerelation ,wesaythat isderivablefromthecoercionenvironment (notation ) if canbeproduced(cid:20)bytheaxiomsu(cid:20)v (cid:0) (cid:0)‘u(cid:20)v (cid:0)‘u(cid:20)v if (cid:0)‘u(cid:20)v (u(cid:20)v)2(cid:0); (cid:15) (cid:0)‘u(cid:20)u; (cid:0)‘u(cid:20)(cid:2); (cid:0)‘ (cid:20)u andrule (cid:0)‘u(cid:20)v (cid:0)‘v (cid:20)w : (cid:0)‘u(cid:20)w Thisdenotationisextendedtofinitesetsofinequalities: if foreach . Wesaythat is 0 0 consistentif . (cid:0)‘(cid:0) (cid:0)‘u(cid:20)v (u(cid:20)v)2(cid:0) (cid:0) (cid:15) Therelati(cid:0)on6‘(cid:2)is(cid:20)extendedtotypes. Onehas,forexample, (cid:20) u v w x u0 v0 w0 x0 iff 0 0 0 0 (cid:0)‘List (Int !(cid:11) )(cid:20)List (Int !(cid:11) ) (cid:0)‘u(cid:20)u;v (cid:20)v;w=w ;x=x: Thecontextrulesbecome 0 F;A‘S:S~ T j(cid:0) (cid:0) ‘(cid:0)(attributeinstantiation) 0 F;A‘S:S~ T j(cid:0) F;A‘S:S~ T j(cid:0) (cid:0)‘p(cid:11)q=pRq(instantiation) F;A‘S:S~[(cid:11):=R] T[(cid:11):=R]j(cid:0) 0 F;A‘Fi+1 :(S~;T) T j(cid:0) (cid:0)‘u(cid:20)pS~q u 0 (Curry) F;A‘Fi :S~ (T !T )j(cid:0) Thecorrectionoperationisalsorelativized: forexample, u (cid:2) if . Therulesforproducingtypingstatements ar[eSo!btaTin]e(cid:0)d=froSm!thTepre(cid:0)vi‘ouuso=ne(cid:2)s,roughlybyreplacing by . Theapplicationrulebecomes B ‘(cid:0) E :S ‘ ‘(cid:0) F;A‘S:S~ T j(cid:0) Bi ‘(cid:0) Ei:Si (application) B~ ‘(cid:0) SE~ :T andthesubsumptionrule 0 B ‘(cid:0) E:S (cid:0)‘S(cid:20)S 0 (subsumption) B ‘(cid:0) E:S The environments in the deduction system are global in the sense that they may contain auxiliary uniqueness constraints(attributein(cid:0)equalitiesappearinginsomederivationstep,butnotoccurringinthefinalbasisandtype). In ordertoeliminatethesesuperfluousconstraintsintheconclusionofadeduction,werefinethenotionofderivability. By wedenotethat isderivableforsome‘conservative’extension of (withrespectto attriBbu‘tesEo:ccSujrr(cid:0)ingin ,theenvBiron‘m(cid:0)e0nEt :Sprovesthesamestatementsastheoriginal ). A(cid:0)lt0erna(cid:0)tively,onecould 0 extendthedeductionsy(cid:0)stemwithrulesfor(cid:0)explicitsimplificationofenvironments. (cid:0) Typecorrectnessoffunctiondefinitionscannowbeexpressedasfollows. Thefunction F~x=E; FunctionalProgramming,Glasgow1995 8 UniquenessTypinginNaturalDeductionStyle saywith -standardtype ,istype-correctif F S~ T j(cid:0) ~x:S~ ‘E :T j(cid:0): Thesubjectreductionpropertyalsoholdsfortheuniquenesstypesystem,cf.BarendsenandSmetsers(1993a). Weareinterestedinattributedversionsofconventionaltypederivations:given and andaderivationshowing ,wewishtoconstructauniquenessvariant(intheobvioussense:assigniBng;tEhesam(cid:27)eunderlyingconventional Btyp‘esEto:th(cid:27)esubexpressionsof )ofthisderivation,yielding with and . E B0;S0;(cid:0)0 jB0j=B;jS0j=(cid:27) B0 ‘E :S0j(cid:0)0 PRINCIPALATTRIBUTIONTHEOREM. Supposeagivenderivationof isattributable. Thenthereexistsan attribution, (computablefromtheconventionalderivation, B ‘aEnd:(cid:27))suchthatforanyotherattribution, ,B0;S0;(cid:0)0 B;E (cid:27) B1;S1;(cid:0)1 (cid:5) (cid:5) (cid:5) B1 =B0; S1 =S0; (cid:0)1 ‘(cid:0)0 forsomeattributesubstitution . (cid:5) Thisdecidabilityresult(intheoriginalgraphframework)hasbeenaddressedinBarendsenandSmetsers(1995). Example The(higher-order)function isdefinedasusual: Map case of Map(f;‘) = ‘ Cons(h;t) j Cons(Ap(f;h);Map(f;t)) Nil j Nil: say = E(f;‘); : Then a a d b c a e b h:(cid:11) ;f:(cid:11) !(cid:12) ;t:List ((cid:11) )‘Cons(Ap(f;h);Map(f;t)):List ((cid:12) )j(cid:2)(cid:20)d: ((cid:3)) Moreover a d b c a e b f:(cid:11) !(cid:12) ;‘:List ((cid:11) )‘E(f;‘):List ((cid:12) )j(cid:2)(cid:20)d: Thisalsovalidates((cid:11)a!(cid:2) (cid:12)b;Listc((cid:11)a)) Liste((cid:12)b)asstandardtypeforMapusedin((cid:3)). 6 Concluding Remarks WehavepresentedClean’suniquenesstypingsysteminnaturaldeductionstyle. Theoriginalsystemshavebeenshown to bedecidable in thesensethatprincipaltypes can bedetermined effectively, seeBarendsen and Smetsers(1993a) and (1995). Thepresentframeworknotonlyprovidesmoredirectproofsoftheseresults,butalsofitscloselytomore commonmethodsbasedonsubstructurallogics. TherelationwiththeapproachofBenton(1994)issubjecttofurther research. References Ariola, Z.M. and J.W. Klop (1995). Equational term graph rewriting, Technical Report CS-R9552, Centrum voor WiskundeenInformatica(CWI),ComputerScience/DepartmentofSoftwareTechnology. Barendregt,H.P.,M.C.J.D.vanEekelen,J.R.W.Glauert,J.R.Kennaway,M.J.PlasmeijerandM.R.Sleep(1987).Term graphreduction,in:J.W.deBakker,A.J.NijmanandP.C.Treleaven(eds.),ProceedingsoftheConferenceonPar- allelArchitecturesandLanguagesEurope(PARLE)II,Eindhoven,TheNetherlands,LectureNotesinComputer Science259,Springer-Verlag,Berlin,pp.141–158. Barendsen,E.(1995). TypesandComputationsinLambdaCalculiandGraphRewriteSystems,Dissertation,Univer- sityofNijmegen. FunctionalProgramming,Glasgow1995 9

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.