116K - views

The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride Abstract olymorphic gular types ar tr eelik datatypes en er ated by polynomial type xpr essions ver set of

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

Tags : The equal ity types
Embed :
Pdf Download 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.

The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride Abstract olymorphic gular types ar tr eelik datatypes en er ated by polynomial type xpr essions ver set of






Presentation on theme: "The Deri ati of Re gular ype is its ype of OneHole Conte xts Extended Abstract Conor McBride Abstract olymorphic gular types ar tr eelik datatypes en er ated by polynomial type xpr essions ver set of "— 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].1IntroductionGerardHuet'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\n bool btreeWecandenethe`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@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'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\rRegD1RegDORegDO RegDPRegD=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\rst uvgcf*econinlXZYvWwmxWcyconinrXHYkVkzq{rrQ.1\rs] t |`gcfeconinlX Y`wmxWc}~coninrXHX}HYY4 Wemayuseweakeningtodeneanoperationwhichcom-puteslisttypes:_ CkQ.1\r pwWgconinlXZY''{!coninrXH!YThenitelybranchingtreesmaythusbegivenbykVq*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!(5con !Thepremisecanonlybefurthersimpliedbythedeni-tionrules:thedirectrulendsonlytheheadofthelistin;theindirectrule'ssecondpremisendsonlythetailinJ,andtherstdemandsthatwesearchforanwithinthattail.Wethusderive(andshowcomplete)thetworuleswemighthavehopedfor:5Itwouldbeinterestingtoinvestigateanotionofsubtermwithasinglerulefordenitionscapturing`-subtermswithin-term:,re-memberingthatreallymeans':however,wewouldpaywithextracomplexityintheruleforvariables,andwiththeneedtocarryextraenvironmentalinformationexplicitly.5 (25')'!t25!(25''!Wemayexploitthis`containment'relationtodenetheusualsubtermrelationforrecursivetypes,namely.forR%%Q.P&&,asfollows:T.T.T.conThatis,tondasubtermofconR%%QJ.P&&,eitherstopwhereyouare,ormovedownoneleveltoancontainedbyPandrepeat.cannotgofurtherthanonelevel,becauseisfreeinP!Withalittlework,wecanspecializetheserulesfor[kzq{rrto,"t5t,5vWwmxWc9*t5,"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\rO\r10O O \rO QJ.PQ^.P J=QJ.P\rP J=QJ.P P J=OP J=O\rP J=O O0zFigure4: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 Kinthespecialcasewhereis.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,forisnotfreeforP.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&&0Writingfortheo-foldproductof'sandoforthesumofo1's,wecancheck(byinductionono),thatforoÉR%%9&&o p^Viewedasaone-holecontextfor,theotellsuswhichtheholeisat,whiletheƏrecordstheremaining's.Amoreinvolvedexamplendsanwithinalistof's_ CkQJ.1\rst JQ^.1\rst JV 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\rSVSzS9,for p andconventionalcalculustellsusthat@,t,3.3PluggingInGivenaone-holecontextinandan,weshouldbeabletoconstructabypluggingtheinthehole.Thatis,weneedanoperationwhichbehavesthus:^҇R%%&&R%%&&R%%&&҇7 R%%&&R%%&&^ R%%&&X Y^ inlO\r^ inlO^ inrO\r^ inr^ NinlXHYO ^ XO^ HYinrXHYO ^ XH^ѰYconinlQJ.P^ conP+;coninrXH{!YQJ.P^ conPJ!QJ.P^ѰN7inlP J=O^ P+ѰinrXғHYP J=O^ ғPJO+;ҌVu-+Ѱ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.Pgivenby77AbuseofnotationisreallyanoperationonQ.PRegDd[Q.PRegDzd[Q.P_C k9P =Q.PInformally,aninhabitantof+[Q.Plookslike')'')'|Vz''wWgAfewbriefcalculationsreassureusthatR%%d[_ Ck&&R%%_C k&&henceR%%+[zd[Q.P&&R%%zd[Q.P&&R%%zd[[kVq*rr&&R%%_C k [kzq{rr&&R%%+[kzkVq*rr&&RG2_ CkC kzkVq*rr5R%%d[kVq*rr&&R2_ Ck_C kkzq{rrThecorrespondingnotionof`addition'hasthesignature!#R%%d[Q.P&&R%%Q.P&&!\r.R%%Q.P&&8 Forthe`!'depictedaboveandanappropriate`',weexpect!\r.tobeconconconVV‡Ofcourse,\r.isdenedbyiteratingP^overthelist8:wWg\r.ҝ''!\r.conP^z\r.Observe,forexample,that\r{reallybehaveslike`plus',whilst\r5iseffectively`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)ForR%%Q.P&&:.!#R%%zd[Q.P&&!\r.Theproofsofthesetheoremsareeasyinductions,onderivationsforthedirection,andonthestructureof8Again,Huetwouldwrite.)^121U368z.,�7/8V..con.0((Bu6C6or!forthedirection.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,Nmakesaholeforasecondinaone-holecontextfrom.Moregenerally,givesalltheo-holecontextsfor'sin'sineachoftheouorderswithwhichtheycanbefound.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,andJoseN.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-Lof'stypetheory.InG.HuetandG.Plotkin,editors,LogicalFrameworks.CUP,1991.10 [Hue97]GerardHuet.TheZipper.JournalofFunc-tionalProgramming,7(5):549554,1997.[JJ97]PatrikJanssonandJohanJeuring.PolyPapolytypicprogramminglanguageextension.InProceedingsofPOPL'97,pages470482.ACM,January1997.[Joy87]AndreJoyal.Foncteursanalytiquesetespecesdestructures.InCombinatoireenumerative,volume1234ofLNM,pages126159.Springer-Verlag,1987.[McB70]FredMcBride.ComputerAidedManipulationofSymbols.PhDthesis,Queen'sUniversityofBelfast,1970.[McB99]ConorMcBride.DependentlyTypedFunc-tionalProgramsandtheirProofs.PhDthesis,UniversityofEdinburgh,1999.11