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
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.
TheDerivativeofaRegularTypeisitsTypeofOne-HoleContextsExtendedAbstractConorMcBride AbstractPolymorphicregulartypesaretree-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-likedatastructuresthe`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,weareeitherattheholeorwemuststepfurtherinourjourneyisalistofsteps,listbtree\nforsomeappropriatesteptypebtree\n,butwhat?Ateachstep,wemustrecordourbinarychoiceofleftorright,togetherwiththebtreewepassedby.Wemaytakebtree\nboolbtreeWecandenethe`pluggingin'operation\rasfollows1btree\nbtreebtreetruenodefalse node!"!#listbtree\nbtree!"!\r$btree%&\r$(')'*!"!+\r$,!"!\r-Wemightdenebtreemorealgebraicallyasthesum(i.e.`choice')oftheuniqueleafwithnodespairingtwosubtreespowersdenoterepeatedproduct:btree1\rbtree2Correspondingly,wemightwrite1Huetwouldwrite.0/+12143537698;:=?353@8A.0/+B:C6btree\n@2btreeNowimaginesimilarjourneyslistttree\nforternarytrees:ttree1\rttree3Eachstepchoosesoneofthreedirections,andrememberstwobypassedtrees,sottree\n3ttree2Itlooksremarkablylikethetypeofstepsiscalculatedbydifferentiatingtheoriginaldatatype.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'namesintuitively,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\rRegD1RegDORegDORegDPRegD=HQ.PRegDPRegD=HORegDP =ORegDRegDRegD=HFigure2:descriptionsofregulartypesThelasttwoconstructorsmayseemmysterious.How-ever,theredundancytheyintroducewillsaveusworkwhenwecometointerpretthesedescriptionsoftypes.WecouldchoosetointerpretonlyRegE,theclosedde-scriptions,keepingtheopentypesunderwaterlikethedangerousbitsofaniceberg.Thiswouldrequireustosubstituteforfreenameswhenevertheybecomeexposed,forexample,whenexpandingaxedpoint.Wewouldinturnbeforcedtotakeaccountoftheequationalpropertiesofsubstitutionsandproveclosurepropertieswithrespecttothem.Idispensewithsubstitution.ThealternativeIhaveadoptedistointerpretopendescrip-tionsinenvironmentswhichexplaintheirfreenames.Thetwounusualconstructorsaboveperformtherolesofde-nitionandweakening,respectivelygrowingandshrinkingtheenvironmentwithintheirscope.Denitionreplacessubstitutionandweakeningaddsmorefreenameswithoutmodifying`old'descriptions.Thisavoidsthepropagationofsubstitutionsthroughthesyntacticstructureandhenceconcernsaboutcaptureweshallonlyeverinterpretthe`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,relativetoanenvironmentexplainingitsfreenameswemustgiveasemanticstothesyntax.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\rstuvgcf*econinlXZYvWwmxWcyconinrXHYkVkzq{rrQ.1\rs]t|`gcfeconinlX Y`wmxWc}~coninrXHX}HYY4 Wemayuseweakeningtodeneanoperationwhichcom-puteslisttypes:_ CkQ.1\rpwWgconinlXZY''{!coninrXH!YThenitelybranchingtreesmaythusbegivenby kVq*rrQ._C kewmxWc,!con!2.6SubtermOrderingsforRegularTypesLetusnowdeneaninductiverelation,(forR%%&&andR%%&&,characterizingthesubtermsofaterminaccountedforby'sin.Thisrelationcharacterizes'sroleasacontainerof's.Iomittheobvious`well-formedness'premises.R%%&&TT9^inlT(T9^inrTXHY(TXHY(|=..conT]=T|=(Observethatsubtermsaccountedforbyaninacompos-itetypearecharacterizedbyaruleforeachcomponentofthattype.Inparticular,therulesforadenitionP J=Ondsubtermsdueto'sinPand'sinOrespectively,thelatteroccurringwithinsubtermsduetoJ'sinP.NotethatthelatterruleexploitsthefactthatwemayseeasinhabitingbothR%%O&&andRHJ=O%%J9&&.Theeffectoflocaltypevariablesisthusreectedattheirplaceofbinding,ratherthanattheirplacesofuse.5Thesignicanceofthephrase`accountedforbythe'sin'isshownbythissimpleexample:IfwetakeREH=vmmgHJ=wecanderive`a7bWcX`a7bWcHeCfg)hcYbutnoteCfg)hcX`7abWcHeCfg0hcYThepointisthateCfg0hchastypeonaccountoftheinthisparticularR'sdenitionofJ,whereas,irrespectiveofR,wecanalwaysderiveXHYHowever,dischargingthedenitionofJinourexample:TakingREH=vmmgwecanderive`a7bWc=X`7abWcHeCfg0hcYandeCfg)hc=X`7abWcHeCfg0hcYBoth'sareaccountedforbytheindicatedtype,andthederivationsfollowrespectivelybythetwodenitionrules.Asimilarphenomenonoccursifwetrytospecializethisorderingtothe'scontainedbya_C k,thatis,todeter-minewhent.1!Onlytheruleforxedpointsapplies,showingthisderivedruletobecomplete:1U=.1Z!( ¡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©««,¨¢ª©¬«"«vWwmxc93One-HoleContextsLetusnowturntothegenericrepresentationofone-holecontextsforrecursiveregulartypes.Weshallrstneedtoseewhat`onestep'is.TheimmediaterecursivesubtermsinsomeconoftypeR%%Q.P&&arethosesubtermsofwhichcorrespondtotheoccurrencesofinPrecallthathastypeRH=Q.P%%P&&.Wethereforeneedtodescribetheone-holecontextsfor'sinP's.SincePmayitselfcontainxedpoints,theprimitiveoperationweneedtodenewillcomputeforPthetypeofone-holecontextsforanyofitsfreenames.Thisoperationisexactlypartialdifferentia-tion.3.1PartialDifferentiationThepartialderivativeofaregulartypedescriptionwithrespecttoafreenameiscomputedbystructuralrecur-sionoverthesyntaxof.6Itisdenedingure4.DRegDRegD1CJML000O\r®O\r¯10O®O\rO°QJ.PQ^±.P J=QJ.P²\rP J=QJ.P²±P J=OP J=O\r¯P J=OO0z³Figure4:partialdifferentiationTherstsixlinesarefamiliarfromcalculus.Forone-holecontexts,theytellusthatancontainsoneintrivialsurroundingsaJotherthancontainsnoconstantscontainnowendaninanO\rineitheranOorawendaninanOeither(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.PP J=QJ.PP J=QJ.P\rP J=QJ.P°QJ.PItistemptingtosolvethisrecursiveequationwithaleastxedpoint,butdoesthisgivethecorrecttypeofone-holecontexts?Yes:everyinsideaQJ.Pmustbeapieceof`payloaddata'attachedtosomeJ-nodeburiedatanitedepth.HenceourjourneytakesuseithertoanattheoutermostnodeandstopshencethePinthe`basecase'ortoasubnodeandonwardshencethePinthe`stepcase':itmuststopeventually.Wemustweakenat±,for±isnotfreeforP.Ourjourneyisclearlylinear:thebodyofthexedpointissyntacticallylinearin±.In-deed,thefollowingsetisomorphismholds,showingthatourjourneyisalistof`steps'witha`tip':R%%Q^±.²\rO²±&&^ÁR%%)_ CkO*&&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Â&&ÁopÂÆ^ÇViewedasaone-holecontextforÂ,theotellsuswhichtheholeisat,whiletheÂÆÇrecordstheremaining's.Amoreinvolvedexamplendsanwithinalistof's_ CkÁQJ.1\rstJÁQ^±.1\rstJV J=_ Ck²\r1\rs]J7V J=_C k²±ÁQ^±.J J=_C k²\r-p J=_C kt±²Á_C k_ CkWewouldindeedhopethataone-holecontextforalistelementisapairofliststheprexandthesufx!Amusingly,thefollowingpowerseriesresembles_ Ck,È\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.PRegDzÙd[Q.P_C k9P =Q.PInformally,aninhabitantof¹Ù+[Q.PlookslikeÒÇ')'ÒÉ')'|ÝVÝzÝÒÂ''wWgAfewbriefcalculationsreassureusthatR%%¹Ùd[_ Ck&&Á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á_ CkCâkzkVq*rrÉ5ã§ãR%%¹Ùd[ä kVq*rr&&ÁRá2á_ Ck_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:wWg\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)ForR%%&&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,thisworkopensupahostoffascinatingtheoreticalpossibilitiesoneonlyhastoopenone'soldschooltext-booksalmostatrandomandask`whatdoesthismeanfordatatypes?'.TheremustsurelyalsobearelationshipbetweenthisworkandJoyal'sgeneralcharacterizationof`speciesofstructure'intermsoftheirTaylorseries[Joy87].Forreg-ulartypes,NÉmakesaholeforasecondinaone-holecontextfrom.Moregenerally,Âgivesalltheo-holecontextsfor'sin'sineachoftheouöorderswithwhichtheycanbefound.ThisstrongresonancewithTay-lorseriesseemsworthyofpursuitandisanactivetopicofresearch.Insummary,theestablishmentoftheconnectionbetweencontextsandcalculusisbuttherststeponalongroadwhoknowswhereitwillend?AcknowledgementsIfeelveryluckytohavestumbledonthisinterpretationofdifferentiationfordatatypeswithsuchpotentialforbothutilityandfascination,andhasbeenintriguingmesincethedayImadetheconnection(whilstchangingtrainsatShrewsbury).Thisworkhasbenetedgreatlyfromhoursspentontrains,andenthusiasticdiscussionswithmanypeople,mostnotablyKonstantinosTourlas,JamesMcKinna,AlexSimpson,DanieleTuri,MartinHofmann,ThorstenAltenkirchand,especially,PeterHancock.References[BJJM98]RolandBackhouse,PatrikJansson,JohanJeuring,andLambertMeertens.Genericprogramminganintroduction.InS.DoaitseSweierstra,PedroR.Henriques,andJos´eN.Oliveira,editors,AdvancedFunctionalProgramming,ThirdInternationalSummerSchool(AFP'98);Braga,Portugal,volume1608ofLNCS,pages28115.Springer-Verlag,1998.[BM98]RichardBirdandLambertMeertens.Nesteddatatypes.InMathematicsofProgramCon-struction,volume1422ofLNCS,pages5267.Springer-Verlag,1998.[BP99]RichardBirdandRossPaterson.deBruijnno-tationasanesteddatatype.JournalofFunc-tionalProgramming,9(1):7792,1999.[Dyb91]PeterDybjer.InductivesetsandfamiliesinMartin-L¨of'stypetheory.InG.HuetandG.Plotkin,editors,LogicalFrameworks.CUP,1991.10 [Hue97]G´erardHuet.TheZipper.JournalofFunc-tionalProgramming,7(5):549554,1997.[JJ97]PatrikJanssonandJohanJeuring.PolyPapolytypicprogramminglanguageextension.InProceedingsofPOPL'97,pages470482.ACM,January1997.[Joy87]Andr´eJoyal.Foncteursanalytiquesetespecesdestructures.InCombinatoire´enumerative,volume1234ofLNM,pages126159.Springer-Verlag,1987.[McB70]FredMcBride.ComputerAidedManipulationofSymbols.PhDthesis,Queen'sUniversityofBelfast,1970.[McB99]ConorMcBride.DependentlyTypedFunc-tionalProgramsandtheirProofs.PhDthesis,UniversityofEdinburgh,1999.11