/
The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride

The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride - PDF document

test
test . @test
Follow
459 views
Uploaded On 2014-11-12

The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride - PPT Presentation

The equal ity types of Cor ML can be xpr essed in this form Given suc type xpr ession with fr ee this paper shows way to epr esent the onehole conte xts for elements of within elements of to ether with an oper ation whic will plug an element of into ID: 10760

The equal ity types

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "The Deri ati of Re gular ype is its ype ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

TheDerivativeofaRegularTypeisitsTypeofOne-HoleContextsExtendedAbstractConorMcBrideAbstractPolymorphicregulartypesaretree-likedatatypesgen-eratedbypolynomialtypeexpressionsoverasetoffreevariablesandclosedunderleastxedpoint.The`equal-itytypes'ofCoreMLcanbeexpressedinthisform.Givensuchatypeexpressionwithfree,thispapershowsawaytorepresenttheone-holecontextsforelementsofwithinelementsof,togetherwithanoperationwhichwillpluganelementofintotheholeofsuchacontext.One-holecontextsaregivenasinhabitantsofaregulartype,computedgenericallyfromthesyntacticstruc-tureofbyamechanismbetterknownaspartialdiffer-entiation.Therelevantnotionofcontainmentisshowntobeappropriatelycharacterizedintermsofderivativesandpluggingin.Thetechnologyisthenexploitedtogivetheone-holecontextsforsub-elementsofrecursivetypesinamannersimilartoHuet's`zippers'[Hue97].1IntroductionG´erardHuet'sdelightfulpaper`TheZipper'[Hue97]de-nesarepresentationoftree-likedatadecomposedintoasubtreeofinterestanditssurroundings.Heshowsusin-formallyhowtoequipadatatypewithanassociatedtypeof`zippers'—one-holecontextsrepresentingatreewithonesubtreedeleted.Zipperscollectthesubtreesforkingoffstepbystepfromthepathwhichstartsattheholeandreturnstotheroot.Thistypeofcontextsisthusindepen-dentoftheparticulartreebeingdecomposedorthesub-treeinthehole.DecompositionisseennotasakindofDepartmentofComputerScience,UniversityofDurham,c.t.mcbride@durham.ac.uksubtraction,anoperationinherentlytroubledbytheneedtosubtractonlysmallerthingsfromlarger,butasthein-versionofakindofaddition(seegure1).=+Figure1:atreeasaone-holecontext`plus'asubtreeThispaperexhibitsasimilartechnique,denedmorefor-mally,whichisgenericforalargeclassoftree-likedatastructures—the`regulardatatypes'.Theseareessentiallythe`equalitytypes'ofcoreML,presentedaspolynomialtypeexpressionsclosedunderleastxedpoint.Inpartic-ular,Iwilldeneandcharacterizetwooperations:ontypes,computingforeachregularrecursivedatatypeitstypeofone-holecontexts;onterms,computinga`big'termbyplugginga`small'termintoaone-holecontext.Therstoftheseoperationsisgivenbyrecursiononthestructureofthealgebraicexpressionswhich`name'types.AsIwrotedowntherulescorrespondingtotheemptytype,theunittype,sumsandproducts,IwasastonishedtondthatLeibnizhadbeatenmetothembyseveralcen-turies:theywereexactlytherulesofdifferentiationIhadlearnedasachild.1 1.1MotivatingExamplesHowcanwedescribetheone-holecontextsofarecur-sivetype?Huetsuggeststhatweregardthemasjourneys`backwards'fromholetoroot,recordingwhatwepassbyontheway.Iproposetofollowhissuggestion,exceptthatIwillstartattherootandworkmyway`forwards'tothehole.Bothchoiceshavetheiruses:`backwards'isbetterfor`treeediting'applications,butthe`forwards'approachisconceptuallysimpler.Considersuchjourneyswithinbinarytrees:btreeleaf nodebtreebtreeAteachpoint,weareeitherattheholeorwemuststepfurtherin—ourjourneyisalistofsteps,listbtree\nforsomeappropriatesteptypebtree\n,butwhat?Ateachstep,wemustrecordourbinarychoiceofleftorright,togetherwiththebtreewepassedby.Wemaytakebtree\n bool btreeWecandenethe`pluggingin'operation\rasfollows1btree\nbtreebtreetruenodefalse node!"!#listbtree\nbtree!"!\r$btree%&\r$(')'*!"!+\r$,!"!\r-Wemightdenebtreemorealgebraicallyasthesum(i.e.`choice')oftheuniqueleafwithnodespairingtwosubtrees—powersdenoterepeatedproduct:btree1\rbtree2Correspondingly,wemightwrite1Huetwouldwrite.0/+12143537698;:=�?353@8A.0/+B:C6btree\n@2 btreeNowimaginesimilarjourneyslistttree\nforternarytrees:ttree1\rttree3Eachstepchoosesoneofthreedirections,andrememberstwobypassedtrees,sottree\n3 ttree2Itlooksremarkablylikethetypeofstepsiscalculatedbydifferentiatingtheoriginaldatatype.Infact,thisisexactlywhatishappening,asweshallseewhenweexaminehowtocomputethedescriptionoftheone-holecontextsforregulardatatypes.2PresentingtheRegularTypesInordertogiveaprecisetreatmentof`differentiatingadatatype',wemustbepreciseabouttheexpressionswhichdenethem.Inparticular,theavailabilityofxedpointsrequiresustoconsiderthebindingoffreshtypevariables.Thereismuchactivityinthisareaofresearch,butthisisnottheplacetorehearseitsmanyissues.TheapproachItakeinthispaperrelativizesregulartypeexpressionstonitesequencesofavailablefreenames.Ithenexplainhowtointerpretsuchexpressionsrelativetoanenviron-mentwhichinterpretsthosenames.Ichoosetogiveinductivedenitionsinnaturaldeduc-tionstyle.Althoughthisrequiresmorespacethanthedatatypedeclarationsofconventionalprogramminglan-guages,theyallowdependentfamiliestobepresentedmuchmoreclearly:even`nested'types[BM98,BP99]mustbedeneduniformlyovertheirindices,whilstthefullnotionoffamilyallowsconstructorstoapplyonlyatparticularindices.Ialsogivetypesignaturestode-nedfunctionsinthisway,preferringtopresenttheuni-versalquanticationinherentintheirtypedependencyviaschematicuseofvariables,ratherthanbycomplexandin-scrutableformulae.2 2.1SequencesofDistinctNamesLetuspresumetheexistenceofaninnite2setNameofnames,equippedwithadecidableequality.WemaythinkofNameasbeing`string'.ThesetNmSeqmaythenbedenedtocontainthenitesequencesofdistinctnames.Eachsuchsequencecanbeviewed`forgetfully'asaset.NameSetDNmSeqDSetENmSeqDNmSeqNameGFDD=HNmSeqIshallalwaysusenamesinawell-foundedmanner.The`explanation'ofsomenamefromsomesequenceDwillinvolveonly`prior'names—intuitively,thosewhichhavealreadybeenexplained.Itisthereforeimportanttodeneforanysuchpair,therestrictionDGI,beingthesequenceofnamesfromDpriorto.DNmSeqDDGINmSeqD=HIDD=HKJMLNIDGIAsequalityonnamesisdecidable,Ishallfreelyallownamestooccurnonlinearlyinpatterns.Inordertore-coverthedisjointnessofpatternswithoutrecoursetopri-oritizingthem,IintroducethenotationJMLtomean`anyJexcept'.Correspondingly,eachclauseofsuchade-nitionholds(schematically)asanequation.Inonethelesswritetoindicateadirectedcomputationrule,reservingforequationalpropositions.2.2DescribingtheRegularTypesTheregulartypesovergivenfreenames,orrather,theex-pressionswhichdescribethemaregivenbytheinductive2By`innite',ImeanthatIcanalwayschooseafreshnameifIneedtocreateanewbinding.familyRegDingure2.Firstly,weembed3typevari-ablesDinRegD,thenwegivethebuildingblocksforpolynomialsandleastxedpoint.DNmSeqRegDSetDRegD0RegDORegDO\rRegD1RegDORegDO RegDPRegD=HQ.PRegDPRegD=HORegDP =ORegDRegDRegD=HFigure2:descriptionsofregulartypesThelasttwoconstructorsmayseemmysterious.How-ever,theredundancytheyintroducewillsaveusworkwhenwecometointerpretthesedescriptionsoftypes.WecouldchoosetointerpretonlyRegE,theclosedde-scriptions,keepingtheopentypesunderwaterlikethedangerousbitsofaniceberg.Thiswouldrequireustosubstituteforfreenameswhenevertheybecomeexposed,forexample,whenexpandingaxedpoint.Wewouldinturnbeforcedtotakeaccountoftheequationalpropertiesofsubstitutionsandproveclosurepropertieswithrespecttothem.Idispensewithsubstitution.ThealternativeIhaveadoptedistointerpretopendescrip-tionsinenvironmentswhichexplaintheirfreenames.Thetwounusualconstructorsaboveperformtherˆolesofde-nitionandweakening,respectivelygrowingandshrinkingtheenvironmentwithintheirscope.Denitionreplacessubstitutionandweakeningaddsmorefreenameswithoutmodifying`old'descriptions.Thisavoidsthepropagationofsubstitutionsthroughthesyntacticstructureandhenceconcernsaboutcapture—weshallonlyeverinterpretthe`value'ofavariableinitsbinding-timeenvironment.3InfactIamabusingnotationbysuppressingaconstructorsymbol.3 2.3TypeEnvironmentsAtypeenvironmentforagivennamesequenceDasso-ciateseachinDwithatypedescriptionoverthepriornames,DGI.DNmSeqEnvDSetEEnvED=HNmSeqREnvDORegDRH=OEnvD=HWemayequipenvironmentswithoperatorsforrestriction(extractingtheprexpriortoagivenname)andprojection(lookingupaname'sassociatedtypedescription).RIistheenvironmentwhichexplainsthefreenamesinRTSU.REnvDDRIEnvDGIREnvDDRTSVRegDGIRH=OIRRHCJWL=OIRIRH=OSVORHKJMLN=OSVRTSV2.4InterpretingtheDescriptionsNowthatwehavethemeanstodescriberegulartypes,wemustsaywhichdataarecontainedbythetypewithagivendescription,relativetoanenvironmentexplainingitsfreenames—wemustgiveasemanticstothesyntax.Figure3denestheinterpretationR%%&&inductively.4NotethatIhavenotsuppliedconstructorsymbolsfortheembeddingrulescorrespondingtovariable-lookup,def-initionandweakening.Theseapparentconationsoftypes,e.g.RH=O%%&&withR%%O&&,areharmless,asthetypestelluswhichembeddingsareoperative.4The`semanticbrackets'donotrepresentameta-leveloperation;theyareintendedtobeasuggestiveobject-levelsyntaxforadependentfamilyoftypes.REnvDRegDR%%&&SetRI%%RTSU&&R%%&&R%%O&&inlR%%O\r&&R%%&&inrR%%O\r&&XZYR%%1&&#R%%O&&R%%&&XHYR%%O &&R%%P =Q.P&&conR%%Q.P&&RH=O%%P&&R%%P =O&&R%%&&RH=O%%&&Figure3:thedatainregulartypes2.5ExamplesofRegularTypesLetusbrieyexaminesomefamiliartypesinthissetting.Wehavetheunittype1,sowecanuse\rtobuildthebooleans:[]\^\_1\r1RegDanyD`a7bMcinlX YR%%[]\+\@_&&anyRdeCfg0hcinrX YR%%[]\+\@_&&anyRdWemayuseQtobuildrecursivedatatypeslikethenaturalnumbersandourtreeexamples,againforanyDandR,asafreshboundvariable(below)canalwaysbechosen:idjWkQ.1\r-lcVamconinlX YhbMnpoconinro[kVq*rrQ.1\rst uvgcf*econinlXZYvWwmxWcyconinrXHYkVkzq{rrQ.1\rs] t |`gcfeconinlX Y`wmxWc}~coninrXHX}HYY4 Wemayuseweakeningtodeneanoperationwhichcom-puteslisttypes:_ C€kQ.1\r pwWgconinlXZY'‚'{ƒ„!coninrXHƒ!YThenitelybranchingtreesmaythusbegivenby…kVq*rrQ._C €kewmxWc,†!con†!2.6SubtermOrderingsforRegularTypesLetusnowdeneaninductiverelation,‡‰ˆ(Šfor‡R%%&&andR%%&&,characterizingthesubtermsofaterminaccountedforby'sin.Thisrelationcharacterizes'srˆoleasacontainerof's.Iomittheobvious`well-formedness'premises.‡R%%&&‡Tˆ‡‡Tˆ‹‡Œˆ‹9^Šinl‡Tˆ(Š‡Tˆ‹9^Šinr‡Œˆ‹‡Tˆ‹ŽŠXHY‡Œˆ(Š‡Tˆ‹ŽŠXHY‡Œˆ(‘|’“=”“.‘‡Œˆ”“.‘con‡Œˆ‘‡Tˆ‘]’“=‹‡Tˆ‹ˆ‘“‡Œˆ‘|’“=‹‡Œˆ(Š‡•ˆŠ–Observethatsubtermsaccountedforbyaninacompos-itetypearecharacterizedbyaruleforeachcomponentofthattype.Inparticular,therulesforadenitionP J=Ondsubtermsdueto'sinPand'sinOrespectively,thelatteroccurringwithinsubtermsduetoJ'sinP.NotethatthelatterruleexploitsthefactthatwemayseeasinhabitingbothR%%O&&andRHJ=O%%J9&&.Theeffectoflocaltypevariablesisthusreectedattheirplaceofbinding,ratherthanattheirplacesofuse.5Thesignicanceofthephrase`accountedforbythe'sin'isshownbythissimpleexample:IfwetakeR—EH=vmmgHJ=wecanderive`a7bWcˆŽ“X`a7bWcHeCf„g)hcYbutnoteCf„g)hcˆŽ“X`7abWcHeCfg0hcYThepointisthateCfg0hchastypeonaccountoftheinthisparticularR'sdenitionofJ,whereas,irrespectiveofR,wecanalwaysderiveˆŽ“XHYHowever,dischargingthedenitionofJinourexample:TakingR—EH=vmmgwecanderive`a7bWcˆŽ“’“=X`7abWcHeCfg0hcYandeCf„g)hcˆŽ“„’“=X`7abWcHeCfg0hcYBoth'sareaccountedforbytheindicatedtype,andthederivationsfollowrespectivelybythetwodenitionrules.Asimilarphenomenonoccursifwetrytospecializethisorderingtothe'scontainedbya_C €k,thatis,todeter-minewhentˆ”“.1–˜Ž“†!Onlytheruleforxedpointsapplies,showingthisderivedruletobecomplete:™ˆ›š1–Ž“Uœ’“=”“.1–Ž“†Z†!ˆ(ž Ÿ ¡5¢con† †!Thepremisecanonlybefurthersimpliedbythedeni-tionrules:thedirectrulendsonlytheheadofthelistin;theindirectrule'ssecondpremisendsonlythetailinJ,andtherstdemandsthatwesearchforanwithinthattail.Wethusderive(andshowcomplete)thetworuleswemighthavehopedfor:5Itwouldbeinterestingtoinvestigateanotionofsubtermwithasinglerulefordenitionscapturing`£-subtermswithin¤-term:,re-memberingthat¥reallymeans¦':however,wewouldpaywithextracomplexityintheruleforvariables,andwiththeneedtocarryextraenvironmentalinformationexplicitly.5 ™ˆ(ž Ÿ2¡5¢')'†!tˆž§Ÿ2¡5¢†!™ˆ(ž Ÿ2¡5¢'‚'†!Wemayexploitthis`containment'relationtodenetheusualsubtermrelationforrecursivetypes,namelyˆ”.‘forR%%Q.P&&,asfollows:‡Tˆ”.‘‡‡Tˆ”.‘ˆ‘‡Tˆ”.‘conThatis,tondasubtermofconR%%QJ.P&&,eitherstopwhereyouare,ormovedownoneleveltoancontainedbyPandrepeat.ˆ‘cannotgofurtherthanonelevel,becauseisfreeinP!Withalittlework,wecanspecializetheserulesfor[kzq{rrto™ˆ,¨¢ª©¬«"«tˆ¨¢5©««tˆ,¨¢5©««vWwmxWc9*tˆ¨¢5©««™ˆ,¨¢ª©¬«"«vWwmxc93One-HoleContextsLetusnowturntothegenericrepresentationofone-holecontextsforrecursiveregulartypes.Weshallrstneedtoseewhat`onestep'is.TheimmediaterecursivesubtermsinsomeconoftypeR%%Q.P&&arethosesubtermsofwhichcorrespondtotheoccurrencesofinP—recallthathastypeRH=Q.P%%P&&.Wethereforeneedtodescribetheone-holecontextsfor'sinP's.SincePmayitselfcontainxedpoints,theprimitiveoperationweneedtodenewillcomputeforPthetypeofone-holecontextsforanyofitsfreenames.Thisoperationisexactlypartialdifferentia-tion.3.1PartialDifferentiationThepartialderivativeofaregulartypedescriptionwithrespecttoafreenameiscomputedbystructuralrecur-sionoverthesyntaxof.6Itisdenedingure4.DRegDRegD1CJML­000O\r®O\r¯10O ®O \rO °QJ.P­Q^±.P J=QJ.P²\r“P J=QJ.P² ±P J=O­P J=O\r¯“P J=O O0“z³“Figure4:partialdifferentiationTherstsixlinesarefamiliarfromcalculus.Forone-holecontexts,theytellusthatancontainsoneintrivialsurroundingsaJotherthancontainsnoconstantscontainnowendaninanO\rineitheranOorawendaninanO either(left)intheO,passingthe,or(right)inthepassingtheONotethatpartialdifferentiationisindependentofenviron-ments:itisdenedonthesyntaxoftypesalone.Justlikethesubtermordering,ittakesnoaccountofthepossibil-itythatsomeJmight,forsomeR,expandintermsof.However,partialdifferentiationisthebasictoolbywhichtotaldifferentiationisconstructed,andthisisexactlywhatweneedwhenwegounderabinderandbecomeliabletoencounterlocalnameswhichpotentiallydoconceal's.Therulefordenitionsagainhandleslocalvariablesattheirplaceofbinding,summingthetypesofcontextsfor6Itisdepressinghowfewmathematicsteachersdeigntoimpartthisvitalcluetocalculusstudents,givingthemrulesbutnomethod.Ilearneddifferentiationfromthepatternmatchingalgorithmgivenin[McB70].6 'soccurringdirectlyinP,andindirectlyinanOburiedwithinaJ.Inconventionalcalculus,thisiseffectivelythe`chainrule'extendedtofunctionsoftwoarguments´´µ ¶·U|´´¹¸µ‡º»´{¼´\r´´¹½µ‡º»´{¾´z š¸˜¿½œKÀš¼¹¿¾œinthespecialcasewhere¶is.Onceweknowhowtodifferentiatedenitions,wecanmaketheleaptoxedpoints.Ifweexpandthexedpointandapplythe`chainrule',weobtain:QJ.P­P J=QJ.PP J=QJ.P\r“P J=QJ.P °QJ.PItistemptingtosolvethisrecursiveequationwithaleastxedpoint,butdoesthisgivethecorrecttypeofone-holecontexts?Yes:everyinsideaQJ.Pmustbeapieceof`payloaddata'attachedtosomeJ-nodeburiedatanitedepth.Henceourjourneytakesuseithertoanattheoutermostnodeandstops—hencethePinthe`basecase'—ortoasubnodeandonwards—hencethe“Pinthe`stepcase':itmuststopeventually.Wemustweakenat±,for±isnotfreeforP.Ourjourneyisclearlylinear:thebodyofthexedpointissyntacticallylinearin±.In-deed,thefollowingsetisomorphismholds,showingthatourjourneyisalistof`steps'witha`tip':R%%Q^±.²\rO² ±&&^ÁR%%)_ C€kO* &&Therulesfordifferentiatinganexplicitweakeningsimplyshort-circuittheprocessifthenameweseekisthatbeingexcluded.3.2ExamplesofDerivativesBeforewedevelopanymoretechnology,letuscheckthatpartialdifferentiationisgivingusthekindofanswersweexpect.Ofcourse,thetypeswegetbackwillcontainlotsof`0\r'and`1 ',buttheusualalgebraiclawswhichsim-plifysuchexpressionsholdassetisomorphisms.Itisalsonothardtoshowthatarecursivetypewithnobasecasesisempty:IfR%%P =0&&Á0thenR%%Q.P&&Á0WritingÂfortheo-foldproductof'sandoforthesumofo1's,wecancheck(byinductionono),thatforoÄÉÅR%%9„Â&&Áo pÂÆ^ÇViewedasaone-holecontextforÂ,theotellsuswhichtheholeisat,whiletheƏÇrecordstheremaining's.Amoreinvolvedexamplendsanwithinalistof's_ C€kÁQJ.1\rst JÁQ^±.1\rst JV J=_ C€k²\r“1\rs] J7V J=_C €k² ±ÁQ^±.J J=_C €k²\r-p J=_C €kt ±²Á_C €k _ C€kWewouldindeedhopethataone-holecontextforalistelementisapairoflists—theprexandthesufx!Amusingly,thefollowingpowerseriesresembles_ C€k,È\r$;\r-Ét\r$@Êt\rËSVSzS9ÈÈ,Ìfor p ÍÈandconventionalcalculustellsusthat@ÎÈÈ,ÌtÏÎÈÈ,̝ÏÉ3.3PluggingInGivenaone-holecontextinandan,weshouldbeabletoconstructabypluggingtheinthehole.Thatis,weneedanoperationwhichbehavesthus:Ð^Ñ҇R%%&&R%%&&R%%&&҇7 ÒÓR%%&&‡R%%&&ÒÐ^Ñ ‡R%%&&X YÔÐ^Ñ ‡‡inlÒÐO\r^Ñ ‡inlÒÐO^Ñ ‡inrÒÐO\r^Ñ ‡inrÒÐ^Ñ ‡NinlXÒHYÔÐO ^Ñ ‡XÒÐO^Ñ ‡HYinrXHÒYÔÐO ^Ñ ‡XHÒÐ^Ñ°‡YconinlÒÐQJ.P^Ñ ‡conÒÐP+Ñ;‡coninrXÒH{Õ!YÐQJ.P^Ñ ‡conÒÐPJÑÕ!ÐQJ.P^Ñ°‡N7inlÒÐP J=O^Ñ ‡ÒÐP+Ñ°‡inrXғHÒYÖÐP J=O^Ñ ‡ғÐPJÑÒÐO+Ñ;‡ҌדV³uØ-‡ÒÐ+Ñ°‡Figure5:plugginginHowarewetodenethisoperation?shouldtellustheshapeofthetermwearetryingtobuild;Òshouldtelluswhichpathtotakeandalsosupplythesubtermscorre-spondingtothe`off-path'componentsofpairs.Ineffect,theoperationproceedsbystructuralrecursiononÒ,butitsowofcontrolinvolvesaprimarycaseanalysison.Ofcourse,weneedonlyconsidercaseswhereisnot0.Thedenitionisingure5.3.4SubtreesinRecursiveRegularTypesTheoperationpicksout'sfromcontainersfor's.Assuggestedabove,thisgivesusthetoolweneedtopickoutsubtreesfromourtree-likerecursivedatatypes,interpret-ingasacontainerfortheimmediatesubtreesofcon.Henceourintuitionthatcontextsforrecursivetypein-habitlist\ncanbemaderigorous.The`steptype'fortreesinQ.PisP =Q.PTheone-holecontextsforQ.Pthusinhabit€¹Ù+[Q.Pgivenby77Abuseofnotation—ÚÛÜisreallyanoperationon¤Q.PRegD€¹Ùd[Q.PRegD€zÙd[Q.P_C €k9P =Q.PInformally,aninhabitantof€¹Ù+[Q.PlookslikeÒÇ')'ÒÉ')'|ÝVÝzÝÒÂ'‚'wWgAfewbriefcalculationsreassureusthatR%%€¹Ùd[_ C€k&&ÁR%%_C €k&&henceR%%€¹Ù+[€zÙd[Q.P&&ÁR%%€zÙd[Q.P&&R%%€zÙd[Þ[kVq*rr&&ßÁR%%_C €k à [kzq{rr&&R%%€¹Ù+[kzkVq*rr&&ÁRGá2á_ C€kCâ kzkVq*rrÉ5ã§ãR%%€¹Ùd[ä…kVq*rr&&ÁRá2á_ C€k_C €k…kzq{rr¬Éã ãThecorrespondingnotionof`addition'hasthesignatureÕ!#R%%€¹Ùd[Q.P&&‡R%%Q.P&&Õ!\r”.‘‡R%%Q.P&&8 Forthe`Õ!'depictedaboveandanappropriate`‡',weexpectÕ!\r”.‘‡tobeconÒÇconÒÉconÝVÝVÝÒ‡Ofcourse,\r”.‘isdenedbyiteratingÐP^Ñoverthelist8:wWg\r”.‘‡‡ҝ'‚'Õ!\r”.‘‡conÒÐP^ÑÒz\r”.‘‡Observe,forexample,that\r{å„æ¢reallybehaveslike`plus',whilst\rž Ÿ ¡5¢iseffectively`append'.Itisnothardtoshowingeneralthat€¹Ù+[Q.Pisamonoidunder`append'andthat\r”.‘isanactionofthatmonoidonQ.P.3.5SubtermsandDerivativesTherelationshipbetweenthecontainmentorderingsandderivativesisanintimateone,andsotooisthatbetweenthesubtreeorderingsandthetypescomputedby€¹Ù+[.Ineffect,thecontainmentorderingisexactlythatinducedbypluggingin,whilethesubtreeorderingonQ.Pisin-ducedby\r”.‘.Whatwehavedoneistogiveaconcreterepresentationforthewitnessestotheserelationalprop-erties.Wemayprovethefollowingtheorems:Theorem(containment)For‡R%%&&andR%%&&:‡Œˆ(ŠäçèÒÓR%%&&ݹÒÐ+Ñ;‡éêTheorem(subtree)For‡ºR%%Q.P&&:‡Œˆ”.‘çèÕ!#R%%€zÙd[Q.P&&ÝÕ!\r”.‘‡äêTheproofsofthesetheoremsareeasyinductions,onderivationsfortheëdirection,andonthestructureof8Again,Huetwouldwrite.)ì^121Uí368ªîzï.ð,ñ�òì7/8¬îVï.ð.con.0ì(ó¤(Bu£˜ôñ6C6ÒorÕ!fortheõdirection.ItismoreoverthecasethatdistinctÒ'sorÕ!'sontherightgiverisetodistinctderiva-tionsontheleft,andviceversa.Iomitthedetailsforreasonsofspace.4TowardsanImplementationRecentextensionstotheHASKELLtypesystem,suchasJanssonandJeuring'sPOLYPhavebeguntorealisethepotentialofgenericprogrammingforthedevelopmentofhighlyreusablecode,instantiableforawideclassofdatatypesandcharacterisedbyequallygenerictheorems[JJ97,BJJM98].However,thesesystemsshownosignofallowingoperationslikewhichcomputetypesgener-icallybyrecursionoveraclosedsyntaxoftypeexpres-sions,cruciallyregardingtypevariablesasconcreteob-jects.Inadependenttypetheorysupportinginductivefamiliesofdatatypes[Dyb91],syntaxessuchasRegDcanberep-resentedasordinarydatawhichcanthenbeusedtoindexthefamilieslikeR%%&&whichreectthem.becomesmerelyanoperationondata,requiringnoextensiontothecomputationalpowerofthetheory.Aprogramminglanguagebasedonsuchatypetheory,asenvisagedin[McB99],wouldseemtobeapromisingsettinginwhichtoimplementthetechnologydescribedinthispaper.ThisworkiswellunderwayintheComputer-AssistedReason-ingGroupatDurham.Thepayoffsfromsuchanimplementationseemlikelytobesubstantial,extendingfarbeyondapplicationstoedit-ingtrees.Alibraryofgenerictoolsforworkingwithcon-textswouldallowustodenefunctionsintermsofthesehigher-levelstructures,manipulatingdatainlargechunks,ratherthanoneconstructoratatime.Furthermore,inadependentlytypedsetting,aricherstructureondataisipsofactoaricherstructureontheindicesofdatatypes.Italsoseemshighlydesirabletoextendtheclassofdatatypesforwhichone-holecontextscanbemanipulatedgenericallybeyondtheregulartypes,perhapstoincludeindexedfamiliesthemselves.Aconcreterepresentationofone-holecontextsforasyntaxwithbindinghasmuchtoofferbothmetaprogrammingandmetatheory.9 5ConclusionsandFutureWorkThispaperhasshownthattheone-holecontextsforele-mentscontainedinapolymorphicregulartypecanberep-resentedastheinhabitantsoftheregulartypecomputedfromtheoriginalbypartialdifferentiation.Thistechnol-ogyhasbeenusedtocharacterizedatastructuresequiv-alenttoHuet's`zippers'—one-holecontextsforthesub-treesoftreesinhabitingarbitraryrecursivetypesinthatclass.Theoperationswhichplugappropriatedataintotheholesofsuchcontextshavealsobeenexhibited.Whilethisconnectionseemsunlikelytobeamerecoinci-dence,itisperhapssurprisingtondauseforthelawsoftheinnitesimalcalculusinsuchadiscretesetting.Thereisnoobviousnotionof`tangent'orof`limit'fordatatypeswhichmightconnectwithourintuitionsfromschoolmathematics.NeithercanIofferatpresentanysenseinwhich`integration'mightmeanmorethanjust`differentiationbackwards'.Oneobservationdoes,however,seemrelevant:thesyn-tacticoperationofdifferentiatinganexpressionwithre-specttogeneratesanapproximationtothechangeinvalueofthatexpressionbysummingthecontributionsgeneratedbyvaryingeachofthe'sintheexpressioninturn.Thederivativeisthusthesumoftermscorrespond-ingtoeachone-holecontextforanintheexpression.Perhapsthekeytotheconnectioncanbefoundbyfo-cusingnotonwhatisbeinginnitesimallyvaried,butonwhat,forthesakeofalinearapproximationtothecurve,isbeingkeptthesame.Apartfromtheimplementationofthistechnology,andthedevelopmentofalibraryofrelatedgenericutili-ties,thisworkopensupahostoffascinatingtheoreticalpossibilities—oneonlyhastoopenone'soldschooltext-booksalmostatrandomandask`whatdoesthismeanfordatatypes?'.TheremustsurelyalsobearelationshipbetweenthisworkandJoyal'sgeneralcharacterizationof`speciesofstructure'intermsoftheirTaylorseries[Joy87].Forreg-ulartypes,NÉmakesaholeforasecondinaone-holecontextfrom.Moregenerally,Âgivesalltheo-holecontextsfor'sin'sineachoftheouöorderswithwhichtheycanbefound.ThisstrongresonancewithTay-lorseriesseemsworthyofpursuitandisanactivetopicofresearch.Insummary,theestablishmentoftheconnectionbetweencontextsandcalculusisbuttherststeponalongroad—whoknowswhereitwillend?AcknowledgementsIfeelveryluckytohavestumbledonthisinterpretationofdifferentiationfordatatypeswithsuchpotentialforbothutilityandfascination,andhasbeenintriguingmesincethedayImadetheconnection(whilstchangingtrainsatShrewsbury).Thisworkhasbenetedgreatlyfromhoursspentontrains,andenthusiasticdiscussionswithmanypeople,mostnotablyKonstantinosTourlas,JamesMcKinna,AlexSimpson,DanieleTuri,MartinHofmann,ThorstenAltenkirchand,especially,PeterHancock.References[BJJM98]RolandBackhouse,PatrikJansson,JohanJeuring,andLambertMeertens.Genericprogramming—anintroduction.InS.DoaitseSweierstra,PedroR.Henriques,andJos´eN.Oliveira,editors,AdvancedFunctionalProgramming,ThirdInternationalSummerSchool(AFP'98);Braga,Portugal,volume1608ofLNCS,pages28–115.Springer-Verlag,1998.[BM98]RichardBirdandLambertMeertens.Nesteddatatypes.InMathematicsofProgramCon-struction,volume1422ofLNCS,pages52–67.Springer-Verlag,1998.[BP99]RichardBirdandRossPaterson.deBruijnno-tationasanesteddatatype.JournalofFunc-tionalProgramming,9(1):77–92,1999.[Dyb91]PeterDybjer.InductivesetsandfamiliesinMartin-L¨of'stypetheory.InG.HuetandG.Plotkin,editors,LogicalFrameworks.CUP,1991.10 [Hue97]G´erardHuet.TheZipper.JournalofFunc-tionalProgramming,7(5):549–554,1997.[JJ97]PatrikJanssonandJohanJeuring.PolyP—apolytypicprogramminglanguageextension.InProceedingsofPOPL'97,pages470–482.ACM,January1997.[Joy87]Andr´eJoyal.Foncteursanalytiquesetespecesdestructures.InCombinatoire´enumerative,volume1234ofLNM,pages126–159.Springer-Verlag,1987.[McB70]FredMcBride.ComputerAidedManipulationofSymbols.PhDthesis,Queen'sUniversityofBelfast,1970.[McB99]ConorMcBride.DependentlyTypedFunc-tionalProgramsandtheirProofs.PhDthesis,UniversityofEdinburgh,1999.11