您好,欢迎访问三七文档
ReferentialTransparenyinImperativeLanguagesANTHONYC.DANIELSUniversityofKentatCanterburyWeformalisereferentialtransparenyofexpressionsinimperativelanguages.Weestablishtherelationshipbetweenreferentialtransparenyandside-e ets,andexplaintherelatedpropertyofextensionalityoffuntions.Thenwepresentanewlanguagebasedontheseideas.Althoughsomeofitsfeaturesarepresentinotherlanguages,wegofurtherbyprovidingaproofthatourlanguageformallysatis espropertiessuhasreferentialtransparenyandextensionalitywithrespettoitsdenotationalsemantis.CategoriesandSubjetDesriptors:D.3.1[ProgrammingLanguages℄:FormalDe nitionsandTheory|Semantis;D.3.3[ProgrammingLanguages℄:LanguageConstrutsandFeatures|Proedures,funtions,andsubroutines;F.3.2[LogisandMeaningsofPrograms℄:SemantisofProgrammingLanguages|Denotationalsemantis;F.3.3[LogisandMeaningsofPro-grams℄:StudiesofProgramConstruts|FuntionalonstrutsGeneralTerms:Languages,ReliabilityAdditionalKeyWordsandPhrases:ReferentialTranspareny,Eulid,oam,ImperativeLan-guages,Aliasing,Interferene1.INTRODUCTIONExpressionswerearuialinnovationintheearlyevolutionofhigh-levelprogram-minglanguages,providingaompatandreadablenotationforomputingvalues.Oneissuewhihisstillthesubjetofintenseinvestigationiswhethertheyshouldallowside-e ets,bywhihwemeantheabilitytoupdatevariablesorperformIOduringexpressionevaluation.Intheirfavour,side-e etsanbeveryusefulandgivetheprogrammergreaterfreedomandontrol.Onthedownside,expressionswithside-e etsarelesstransparentandonsequentlyhardertounderstandandreasonabout,partiularlywhenside-e etsupdatevariablesintheexpression.Intheory,tounderstandanexpressionwithside-e etswemustfollowthelanguageimplementation’sdesriptionofexpressionevaluation(ifoneexists)andworkouttheside-e etsinallfuntionallsandsoon.Inpratie,thisisnotalwaysnees-sarybeausetheside-e etsanbeorthogonaltotheexpression,inthesensethattheydonota etthevalueoftheexpression,andsoweanignorethemwhenweonsiderthevaluepartoftheexpression.However,theside-e etsanstillbedif- ulttounderstandbeausetheysometimesinterferewitheahotherresultinginverysubtleerrors.Expressionnotationhidestheseside-e etsandobsurestheor-Author’saddress:A.C.Daniels,ComputingLaboratory,UniversityofKentatCanterbury,Can-terbury,Kent,CT27NF,UK.Permissiontomakedigital/hardopyofallorpartofthismaterialwithoutfeeforpersonalorlassroomuseprovidedthattheopiesarenotmadeordistributedforpro torommerialadvantage,theACMopyright/servernotie,thetitleofthepubliation,anditsdateappear,andnotieisgiventhatopyingisbypermissionoftheACM,In.Toopyotherwise,torepublish,topostonservers,ortoredistributetolistsrequirespriorspei permissionand/orafee.ACMTransationsonProgrammingLanguagesandSystems,Vol.TBD,No.TDB,MonthYear,Pages1{??.2 AnthonyC.Danielsdertheyourin,whihisusuallytheorderofexpressionevaluation.Re-arranginganexpressionmayormaynotalteritsvalue,butitwillhangetheorderofanyside-e ets.Mostimperativelanguagesoptfor exibilityandallowunrestritedside-e ets.Inontrast,Eulid[Lampsonetal.1977;Popeketal.1977℄andoam[INMOSLimited1988℄imposerestritionsonside-e ets,butfordi erentreasons:Eulidwasdesignedforverifyingprogramorretness,andtherestritionsonside-e etsmaketheproofrulesmuhsimpler;oamisaonurrentlanguage,andstritontroloverside-e etsisneessaryforpreventingunwantedinterferenebetweenproesses.(InSetion5wedisussapproahestakenbyotherlanguagestoombin-ingside-e etsandexpressions.)Althoughitiseasytounderstandtherationaleforthedesignoftheselanguages,itismorediÆulttostatepreiselythepropertiesthatEulidandoamhave(intheiroreimperativesubset)whihlessrestritivelanguagesdonot.Inthispaperweaddressthisbyde ningandprovingpropertiesofvariousminiexpressionlanguages,designedtoaptureertainkeyfeatures.Considerpropertiesusedinequationalreasoninginvolvingarithmetiexpres-sions,forinstane,inthefollowingsteps,(x+1)*f(x)*(x-1)+f(x)=hommutativityandassoiativityof*if(x)*(x+1)*(x-1)+f(x)=hdistributivityof*over+if(x)*(x*(x-1)+1*(x-1))+f(x)=h:::manymoresmallsteps:::if(x)*x*xPropertiessuhasommutativityofadditionanbeprovenbyusingthesemantistoshowthatE1+E2=E2+E1holdsforanyE1andE2.Whensuhapropertyholdsthisisgenerallyquiteeasy.However,notiethateverysteprequiresthefollowingproperty:foranysubexpressionE1andequivalentexpressionE2,wemayreplaeE1withE2intheoverallexpressionwithouthangingitsmeaning.Thispropertymustholdforthelanguageifwearetouseequationalreasoningasitisrequiredineverystep.Weshallrefertothispropertyas\referentialtranspareny,butitisalsoknownas\substitutivityofidentityor\Leibnitz’slaw.InSetion2weinvestigatereferentialtransparenyforvariousexpressionlan-guages.We ndthatitsde nitionneedstailoringtotakeaountoffeaturessuhasvariables,funtionsandtypes,soitisnotanabsolutenotion.Foromparisonweanalysealanguagewithside-e etsandexplainformallytheonsequenesthattheinlusionofside-e etshasforreferentialtransparenyandforotherproperties.Wethenonsideruser-de nedfuntionsandextensionality,whihisthepropertythatfuntionsalwaysyieldthesameresultgiventhesameinputvalue,regardlessofthestate.Finallyweprovereferentialtransparenyfortypedexpressions.So,inSetion2welarifytheintuit
本文标题:Referential Transparency in Imperative Languages
链接地址:https://www.777doc.com/doc-6041170 .html