÷ƒ’À;è TeX output 1995.10.19:1430‹ÿÿÿÿ •ºâ ý? £ þŸŒ÷‘dßdóÂÖN ffcmbx12¼Strictness–ffAnalysis‘I™‘ø4a“Grande“Vitesse:Ž¤‘¼¦Rewriting–ffthe“rules“of“the“Ev‘ÿ™aluation“T‘þ¦fransformers“gameŽ¡‘5†ÈóX«Qffcmr12»Second–³/draft:›D>OctobdCer“19,“1995.˜Commenš›¼ts“are“w˜elcomed.ŸúÆ=ó
!",š

cmsy10¸ŽŽŽŸy”’È@ó(Kñ`y
ó3
cmr10ÓJulian‘¦fSew²!ardŽŽ¤
™™‘5)JDepartmenš²!t–¦fof“Computer“Science,“Univ˜ersit˜y“of“Manc˜hester,“M13“9PL,“UKŽŽ¡’°>?ó7ßê<x
ó3
cmtt10âsewardj@cs.man.ac.ukŽŽŽŽŽŽŽ ú þ"‘íºâóñkAH	
cmssbx10¹AbstractŽ©†´‘íºâóo´‹Ç		cmr9ºThis–l¾papAÇer“presen¾9ts“the“design“of“a“strictness“analyser“pri-Ž¤
‘íºâmarily–u‰inš¾9tended“to“assist“in“the“parallelisation“of“Hask˜ellŽ¡‘íºâprograms.‘åôThe–qàanalyser“generates“detailed“ev‘ÿ|raluation“trans-Ž¡‘íºâformer–â'information“suitable“for“use“in“a“parallel“graph“re-Ž¡‘íºâduction–ssmac¾9hine.‘6ÍBy“tuning“the“design“to“handle“commonŽ¡‘íºâcases–H'rapidly‘ÿ:«,‘TÛwš¾9e“ac˜hiev˜e“go•AÇo“d›H'p“erformance˜o•¾9v“er˜a˜range˜ofŽ¡‘íºârealistic–ö~test“inputs,‘.Èof“sizes“up“to“a“thousand“lines.‘¿îP¾9er-Ž¡‘íºâformance–ó/gures“are“presen¾9ted.‘¶F‘ÿ:«rom“measuring“the“timeŽ¡‘íºâit–!Stakš¾9es“Glasgo˜w“Hask˜ell“0.10“to“compile“those“same“pro-Ž¡‘íºâgrams,‘ªit–w3is“apparenš¾9t“that“the“analyser“is“sucien˜tly“quic˜kŽ¡‘íºâto–ߥbšAÇe“approac¾9hing“the“p˜oin¾9t“where“incorp˜orating“it“in¾9to“aŽ¡‘íºâHask¾9ell–Tcompiler“is“a“viable“propAÇosition.ŽŸ
‘íºâOur–ƒ€strictness“analyser“conš¾9tains“three“ma‘ƒŽjor“inno˜v‘ÿ|rations.Ž¡‘íºâFirstly‘ÿ:«,‘î“w•¾9e›à emplo“y˜a˜mixed˜forw“ard˜and˜bac“kw“ards˜analy-Ž¡‘íºâsis,‘l
whic•¾9h›'‚allo“ws˜us˜to˜do˜pro‘ƒŽjection˜analysis˜ev“en˜in˜theŽ¡‘íºâpresence–¼Fof“higher“order“functions.‘ESecondly‘ÿ:«,‘æwš¾9e“solv˜e“theŽ¡‘íºâresulting–Õ¹recursiv¾9e“domain“equations“using“a“sophisticatedŽ¡‘íºâterm–±rewriting“system,–Nlwhicš¾9h,“as–±far“as“w˜e“kno˜w,‘Nlhas“abilitiesŽ¡‘íºâfar–9~bAÇeyš¾9ond“previous“rewrite“based“solv˜ers“in“abstract“in˜ter-Ž¡‘íºâpretation–Èsystems.‘ªFinally‘ÿ:«,‘×xwš¾9e“a˜v˜oid“man˜y“of“the“dicultiesŽ¡‘íºâof–|ôhigher“order“analysis“b¾9y“automatically“transforming“outŽ¡‘íºâmost–Thigher“order“functions“bšAÇefore“analysis“b˜egins.ŽŸ-‘íºâ¹1Ž‘ü”IntroFfductionŽ¦‘íºâºHigher-order,‘Zûnon-
at–,dstrictness“analysis“tecš¾9hniques“ha˜v˜e“ac-Ž¡‘íºâquired–¡a“reputation“for“bšAÇeing“to˜o“exp˜ensiv¾9e“for“use“in“pro-Ž¡‘íºâduction–Âscompilers.‘ÐThis“is“a“pitš¾9y‘ÿ:«,‘Ósince“man˜y“suc˜h“functionsŽ¡‘íºâbAÇeha•¾9v“e–ãin“relativš¾9ely“simple“w˜a˜ys,‘~whic˜h“suggests“their“ab-Ž¡‘íºâstract–TbšAÇeha¾9viour“could“b˜e“divined“without“m•¾9uc“h‘Tdicult“y‘ÿ:«.ŽŸ
‘íºâOne–ãof“the“main“themes“whicš¾9h“c˜haracterised“the“pastŽ¡‘íºâdecade's–Ÿadv‘ÿ|rances“in“hardwš¾9are“and“soft˜w˜are“pAÇerformanceŽ¡‘íºâis–5£that“of“measuremenš¾9t-lead“design.‘}\This“sc˜hoAÇol“of“though˜tŽ¡‘íºâbases–Ødesign“on“measuring“what“programs“do“most“often,Ž¡‘íºâand–WQmaking“these“common“activities“as“fast“as“pAÇossible,‘}Rev¾9enŽ¡‘íºâat––ïthe“expAÇense“of“sloš¾9wing“do˜wn“less“common“opAÇerations.Ž¡‘íºâThese–,Ôideas,‘r´elabAÇorated“in“Hennessy“&“P¾9atterson“[HP90Ž‘zú],Ž‘íºâŸÀ‰ff_ÿ Ÿ34‘
+bŸüûró°Ü0ncmsy5¶ŽŽ‘YóÙ“ Rcmr7±My–}^apš7ologies“for“the“dog-rough“tÈãyp˜esetting.‘|ÂThis“will“b˜e“xed“inŽŸlater–±ÈvÈãersions“of“the“pap7er.ŽŸfhŽŽ þ"’õºâºpla•¾9y“ed–î…a“cenš¾9tral“role“in“the“RISC‘î{rev˜olution,‘öHand“ha˜v˜e“bAÇeenŽ¤
’õºâtakš¾9en–Ï
up“recen˜tly“b˜y“the“functional“programming“comm˜u-Ž¡’õºânitš¾9y–T[PHHP93Ž‘#µø]“[P˜ar92Ž‘‡Ç].Ž©
’õºâW‘ÿ:«e–©Ûpresen¾9t,›¿Zin“detail,˜the“design“of“a“fast“strictness“analyserŽ¡’õºâfor–”ßHask¾9ell,‘ôÁdealing“with“higher-order“functions“and“gen-Ž¡’õºâerating–vøev‘ÿ|raluation“transformer“information“suitable“for“useŽ¡’õºâin–Uparallel“graph“reduction“systems“[Bur87Ž›Žã]“[Bur91Ž˜].‘ãsPre-Ž¡’õºâliminary–5ŠexpAÇerimenš¾9ts“ha˜v˜e“bAÇeen“encouraging.‘}F‘ÿ:«or“example,Ž¡’õºârunning–in“compiled“Hask¾9ell“on“a“Sun“Sparc-10,‘«	a“618“lineŽ¡’õºâprogram–}Xw¾9as“analysed“in“44“seconds.‘T|Of“this,‘—Yroughly“halfŽ¡’õºâw•¾9as›’dev“oted˜to˜parsing,‘U¢desugaring˜and˜t“ypAÇec“hec“king,‘U¢ex-Ž¡’õºâpAÇenses–Rwhicš¾9h“an˜y“compiler“w˜ould“incur.‘Ò¨As“a“naiv˜e“rstŽ¡’õºâimplemen¾9tation,‘jthere–Þÿis“ample“scopšAÇe“for“p˜erformance“im-Ž¡’õºâpro•¾9v“emen“t.Ž¦’õºâThis–XpapAÇer“argues“in“fa•¾9v“our–Xof“a“measuremenš¾9t-lead“approac˜hŽ¡’õºâfor–¢qthe“implemenš¾9tation“of“seman˜tic“analysis“tec˜hniques“forŽ¡’õºâfunctional–ßlanguages.‘
UA‘Þôma‘ƒŽjor“emphasis“is“to“feed“the“anal-Ž¡’õºâyser–LÈthe“kinds“of“programs“pAÇeople“really“write,‘Z¥rather“thanŽ¡’õºâbasing–Øïdesign“decisions“on“the“usual“Mic•¾9k“ey–ØïMouse“exam-Ž¡’õºâples–ý¬ošAÇccurring“so“frequen¾9tly“in“pap˜ers“on“the“sub‘ƒŽject.‘ÕxT‘ÿ:«oŽ¡’õºâthis–Ëend,‘¿ètest“inputs“ha•¾9v“e–ËbšAÇeen“tak¾9en“from“the“b˜enc¾9hmarkŽ¡’õºâsuites–Tof“Hartel“[HL92Ž‘÷l]“and“Pš¾9artain“[P˜ar92Ž‘‡Ç].Ž¦’õºâSucš¾9h–?®an“approac˜h“rev˜eals“some“in˜teresting“facts.‘›~F‘ÿ:«or“ex-Ž¡’õºâample,‘Õçw•¾9e›¯cdisco“v“ered˜the˜main˜limitation˜on˜analyser˜pAÇer-Ž¡’õºâformance–#¼wš¾9as“not“the“necessit˜y“to“iterate“to“and“detect“x-Ž¡’õºâpšAÇoin¾9ts,‘¨as–ŒÐhad“b˜een“assumed“bš¾9y“so“man˜y“theoretics.‘îïRather,Ž¡’õºâit–aàw¾9as“the“sheer“size“of“the“terms“generated“during“the“ab-Ž¡’õºâstract–cBinš¾9terpretation“phase.‘;By“in˜troAÇducing“a“little“moreŽ¡’õºâin•¾9telligence›þGin“to˜that˜phase,‘8ƒterm˜size˜is˜cut˜dramatically‘ÿ:«,Ž¡’õºâgiving–Ta“correspšAÇonding“p˜erformance“increase.Ž¦’õºâSimilarly‘ÿ:«,‘h­pAÇolymorphism–Xis“dealt“with“bš¾9y“the“crude“mec˜ha-Ž¡’õºânism–Áof“a“monomorphisation“pass“bAÇefore“analysis.‘/·PreviousŽ¡’õºâw•¾9ork“ers,›™pincluding‘m“yself,˜assumed–this“w¾9as“a“\bad“thing"Ž¡’õºâ(see–¿Š[HH91Ž‘>]“and“[Sew93Ž‘/]),‘гand“put“m•¾9uc“h–¿Šeort“in¾9to“devisingŽ¡’õºâpšAÇolymorphic–¢analysis“metho˜ds“[Bar91Ž‘U].‘5Y‘ÿ:«et“the“feared“co˜deŽ¡’õºâexplosion,–Ò›it›Áíseems,“simply˜do•AÇes˜not˜happ“en.‘£Measuremen¾9tsŽ¡’õºâbš¾9y–›<Mark“Jones“on“a“13000“line“Hask˜ell“program“{“the“sourceŽ¡’õºâcoAÇde–TDof“this“analyser“{“revš¾9eal“that“only“a“v˜ery“few“pAÇoly-Ž¡’õºâmorphic–G‡functions,›Tfor“example“óMߤN		cmtt9ëMmap“ºand“ëMfoldrº,˜are“used“atŽ¡’õºâa–†large“n•¾9um“bAÇer–†of“instances.‘µCertainly‘ÿ:«,‘¿’monomorphisationŽ¡’õºâdošAÇes–wÎnot“cause“an¾9y“noticeable“p˜erformance“problems“for“thisŽ¡’õºâanalyser.‘#¸A‘mm•¾9uc“h–mbAÇetter“reason“for“disliking“monomorphicŽ¡’õºâanalyses–‹#is“that“they“signican¾9tly“complicate“life“when“moAÇd-Ž¡’õºâules–TappAÇear“on“the“scene.ŽŽŽŽŽŽŽŒ‹* •ºâ ý? £ ý€‘íºâ¹1.1Ž‘G·Overview–LÎof“papFferŽŸm‘íºâºThe–†Iremainder“of“the“inš¾9troAÇduction“is“dev˜oted“to“an“o˜v˜erviewŽ¤
‘íºâof–Tthe“analyser,“henceforth“referred“to“as“óNt‰:		cmbx9ëNAnnaº.Ž©
‘íºâSection–“”2“deals“with“tec¾9hnical“preliminaries.‘—/In“particular,Ž¡‘íºâwš¾9e– nexamine“ho˜w“t˜ypšAÇes“in“the“source“program“are“mapp˜ed“toŽ¡‘íºâabstract–
Èdomains“suitable“for“the“con¾9trol“of“parallel“ev‘ÿ|ralua-Ž¡‘íºâtion.Ž¦‘íºâThe–Ï~abstract“in¾9terpretation“used“forms“the“sub‘ƒŽject“of“sec-Ž¡‘íºâtion–e<3.‘'A‘dåv‘ÿ|rarian¾9t“of“the“pro‘ƒŽjection“analysis“describAÇed“inŽ¡‘íºâsection–,ê6“of“[Hug87Ž‘ó'],‘rÐthe“tecš¾9hnique“is“a“mixed“bac˜kw˜ardsŽ¡‘íºâand–œàforwš¾9ards“analysis,‘þÂwith“the“aim“of“pAÇerforming“bac˜k-Ž¡‘íºâwš¾9ards–4analysis.‘By“supplying“just“enough“\forw˜ards"“infor-Ž¡‘íºâmation–lîto“turn“functions“in¾9to“rst“class“citizens,‘Žthe“analysisŽ¡‘íºâdeals–Çsensibly“with“higher-order“functions,‘ókpartial“applica-Ž¡‘íºâtions–Tand“functions“inside“data“structures.Ž¦‘íºâSection–öÇ4“presen¾9ts,›/$in“detail,˜the“elabAÇorate“term“rewritingŽ¡‘íºâsystem–lused“to“detect“xed“pAÇoinš¾9ts“in“the“recursiv˜e“domainŽ¡‘íºâequations–Tgenerated“bš¾9y“the“abstract“in˜terpreter.Ž¦‘íºâF‘ÿ:«unctional–f¢programmers“ha•¾9v“e–f¢long“observ¾9ed“that“large“partsŽ¡‘íºâof–zŠthe“programs“they“write“can“bAÇe“mec¾9hanically“transformedŽ¡‘íºâto›eçha•¾9v“e˜no˜higher-order˜functions.‘(Anna˜exploits˜this˜toŽ¡‘íºâgo•AÇo“d–„eect,‘Ÿ³transforming“a•¾9w“a“y–„as“man¾9y“higher-order“func-Ž¡‘íºâtions–ias“pšAÇossible“b˜efore“analysis.‘Ç"Common“higher“order“func-Ž¡‘íºâtions–c|whicš¾9h“encapsulate“particular“forms“of“recursion,‘wsuc˜hŽ¡‘íºâas–gëMfoldrº,‘{are“trivially“remo•¾9v“ed.‘ÌEv“en–gmore“dicult“forms,Ž¡‘íºâlikš¾9e–P$the“monads“so“bAÇelo˜v˜ed“in“certain“quarters“[W‘ÿ:«ad92Ž‘¿˜]“areŽ¡‘íºâtransformable.›)ªNev¾9ertheless,‘…some–odiculties“remain.˜Sec-Ž¡‘íºâtion–Âo5“discusses“all“this“in“detail.‘ÎW‘ÿ:«e“also“loAÇok“brie
y“at“theŽ¡‘íºâmonomorphiser.Ž¦‘íºâFinally‘ÿ:«,›/²in–÷9section“6,˜all“these“go•AÇo“dies–÷9are“dra¾9wn“togetherŽ¡‘íºâwith–@’a“discussion“of“the“system's“pAÇerformance,‘kand“of“relatedŽ¡‘íºâand–Tfurther“w¾9ork.ŽŸÚ‘íºâ¹1.2Ž‘G·Overview–LÎof“the“analyser's“front“endŽŸm‘íºâºAnna–pis“a“large“Hask¾9ell“program,‘B·consisting“of“more“thanŽ¡‘íºâ13000–7lines.›¿OpAÇeration“is“simple.˜Anna“reads“a“source“pro-Ž¡‘íºâgram–Cyon“the“standard“input,‘Oand“pAÇerforms“extensiv¾9e“trans-Ž¡‘íºâformations–»ñon“the“program,‘ÍÒprinš¾9ting“it“out“at“v‘ÿ|rarious“pAÇoin˜tsŽ¡‘íºâon–1Ðthe“w•¾9a“y–ÿ:«.‘qåFinally“,‘8ïthe–1Ðstrictness“information“is“generatedŽ¡‘íºâand‘Tprin¾9ted.Ž¦‘íºâThe–y¦language“accepted“is“a“subset“of“Hask¾9ell.‘IfMissing“fea-Ž¡‘íºâtures–are“anš¾9ything“to“do“with“o˜v˜erloading,‘CmoAÇdules“or“arra˜ys.Ž¡‘íºâBecause–Òàof“these,‘à+oering“up“arbitrary“Hask¾9ell“programs“forŽ¡‘íºâanalysis–«is“a“dicult“task:‘çGall“o•¾9v“erloading–«has“to“bAÇe“resolv¾9edŽ¡‘íºâbš¾9y–óhand,‘*‚a“tedious“business.‘µ«The“lac˜k“of“mošAÇdule“supp˜ortŽ¡‘íºâdoAÇes–rœnot“pro•¾9v“e›rœm“uc“h˜of˜a˜problem,‘“(since˜m“ultimoAÇdule˜inputsŽ¡‘íºâare–nsimply“concatenated“inš¾9to“one“massiv˜e“program,‘moAÇduloŽ¡‘íºâsolving–|Íthe“oAÇdd“renaming“problem“along“the“w•¾9a“y‘ÿ:«.‘RÚAnnaŽ¡‘íºâknoš¾9ws–`Ynothing“abAÇout“the“Hask˜ell“prelude,‘sand“the“relev‘ÿ|ran˜tŽ¡‘íºâparts–Õof“this“tošAÇo“need“to“b˜e“inserted“inš¾9to“the“inputs.‘A‘Õv˜eryŽ¡‘íºâfew–(opAÇerations“are“takš¾9en“as“primitiv˜e:‘AÏëM(+)º,–l¯ëM(-)º,“ëM(*)‘(ºandŽ¡‘íºâëM(/)º,›š~all–{Çof“t¾9ypAÇe“ëMInt–¹–->“Int“->“Intº,˜comparisons‘{ÇëM(<)º,˜ëM(<=)º,Ž¡‘íºâëM(==)º,–n¾ëM(/=)º,“ëM(>)–Eºand“ëM(>=)º,›n¾of“t¾9ypAÇe“ëMInt–¹–->“Int“->“Boolº,˜andŽ¡‘íºâcon•¾9v“ersion–=ífunctions“ëMchr“ºand“ëMord“ºof“t¾9ypAÇe“ëMInt–¹–->“Char‘=íºandŽ¡‘íºâëMChar–¹–->“Int–¦ÍºrespAÇectivš¾9ely‘ÿ:«.‘ÐÚA‘¦§v‘ÿ|ralid“program“m˜ust“supply“aŽ¡‘íºâbinding–»for“ëMmainº,‘Íbut“unlikš¾9e“a“Hask˜ell“program,‘Íthis“ma˜y“bAÇeŽ¡‘íºâof–Tanš¾9y“t˜ypAÇe.Ž¦‘íºâDespite–iÉthis“meagre“collection“of“primitivš¾9es,‘¾æAnna“kno˜wsŽ¡‘íºâabAÇout–fmost“of“the“built-in“Haskš¾9ell“t˜ypšAÇes,‘‰including“b˜o˜oleans,Ž¡‘íºâc¾9haracters,–T„strings,“lists–Gáand“tuples.‘´Although“some“impAÇor-ŽŽŽ ý€’õºâtanš¾9t–Ü»features“of“Hask˜ell“are“missing,‘è
the“subset“allo˜ws“AnnaŽ¤
’õºâto–:CbAÇe“fed“real-wš¾9orld“programs“of“considerable“complexit˜y‘ÿ:«,Ž¡’õºâalbAÇeit–Tafter“some“considerable“massaging.Ž©
’õºâProbably–g)the“bAÇest“w•¾9a“y–g)to“think“of“Anna“is“as“a“framew¾9orkŽ¡’õºâfor–¡Itrying“out“new“analysis“tec¾9hniques.‘ÀNHence,‘ÄFthe“systemŽ¡’õºâlogically–%Ýconsists“of“t•¾9w“o–%Ýparts:‘=‚the“analysis“propAÇer,‘)ÿand“theŽ¡’õºâsuppAÇorting–uÏframewš¾9ork.‘=àThe“in˜terface“bAÇet˜w˜een“the“t˜w˜o“isŽ¡’õºâreasonably–ÃVclean,‘Ó¼so“c¾9hanging“the“nature“of“the“analysis“canŽ¡’õºâbAÇe–Íudone“without“m•¾9uc“h›Íuuphea“v‘ÿ|ral.‘DÓThis˜section˜foAÇcusses˜onŽ¡’õºâthe–TsuppAÇorting“framew¾9ork.Ž¦’õºâBecause–×'wš¾9e“w˜an˜t“to“exercise“the“analyses“on“functional“pro-Ž¡’õºâgrams–T'of“realistic“size,‘zÊthe“suppAÇorting“framew¾9ork“is“necessar-Ž¡’õºâily–¼Ûlarge“and“complex.‘þòIndeed,‘Îthe“analysis“part“is“curren¾9tlyŽ¡’õºâthe–è¶smaller“of“the“t•¾9w“o.‘–•The›è¶framew“ork˜con“tains˜a˜go•AÇo“dlyŽ¡’õºâpart–Áof“what“one“migh¾9t“expAÇect“to“nd“in“a“full-scale“com-Ž¡’õºâpiler–Tfor“the“same“language:ŽŸÐO’äóP©±Ê		cmsy9ëPŽŽŽ’:âºF‘ÿ:«ollo¾9wing–=
the“parsing“stage,‘†÷desugaring“and“patternŽ¡’:âmatc¾9hing–0ãtransformations“are“carried“out.‘oThese“pro-Ž¡’:âduce–ÝyëNCoreº,‘O‚a“minimal“functional“language“used“asŽ¡’:âan–
-inš¾9termediate“form“in“the“Glasgo˜w“Hask˜ell“com-Ž¡’:âpiler–îž[PHHP93Ž‘#µø],‘ö\and“tš¾9ypical“of“the“in˜termediate“formsŽ¡’:âof–|Ïv‘ÿ|rarious“other“compilers,‘–®for“example“the“ChalmersŽ¡’:âHask¾9ell-B‘¶}Compiler–¶§[Aug87Ž‘ó'].‘hAll“further“transforma-Ž¡’:âtions–òprior“to“strictness“analysis“propAÇer“are“Core-to-Ž¡’:âCore‘Ttransformations.Ž©34’äëPŽŽŽ’:âºA‘MÌdepAÇendancy–Nanalysis“phase“splits“the“program“upŽ¡’:âinš¾9to–µyminimal“m˜utually“recursiv˜e“groups,‘and“marksŽ¡’:ânon-recursivš¾9e–M>bindings“as“suc˜h.‘Ä.All“subsequen˜t“trans-Ž¡’:âformations–Bare“required“to“main¾9tain“depAÇendancy“order.Ž¦’äëPŽŽŽ’:âºA‘Ízcrude–ÍŒbut“eectivš¾9e“Core“simplication“pass“remo˜v˜esŽ¡’:âunš¾9used–
ºbindings,‘Øand“substitutes“in“constan˜t“bindingsŽ¡’:âonly–:used“once.‘ÆThis“helps“to“clean“up“the“rather“messyŽ¡’:âoutput–`-of“the“desugarer.‘üûThe“former“feature“is“usefulŽ¡’:âfor–;ždebugging“the“analyser.‘ÓÞBecause“a“binding“for“ëMmainŽ¡’:âºmš¾9ust–“ìbAÇe“supplied,‘­Îthe“simplier“will“ev˜en˜tually“remo˜v˜eŽ¡’:âall–´bindings“not“reac¾9hable“from“ëMmainº.‘êIf“the“analyser“isŽ¡’:âseen–‘¹to“malfunction,‘¬arbitrary“subsections“of“the“inputŽ¡’:âprogram–can“bAÇe“discarded“simply“bš¾9y“c˜hanging“the“b•AÇo“dyŽ¡’:âof–¥ëMmainº,‘Éunš¾9til“what“remains“is“small“enough“to“mak˜eŽ¡’:âdebugging‘Tviable.Ž¦’äëPŽŽŽ’:âºRemoš¾9ving–.“nested“en˜vironmen˜ts“mak˜es“subsequen˜tŽ¡’:âtransformations–i®and“analyses“simpler.‘ã9T‘ÿ:«o“this“end,‘ŒtheŽ¡’:âprogram–Vis“
attened“out“bš¾9y“a“moAÇdied“Johnsson-st˜yleŽ¡’:âlam•¾9bAÇda-lifter›‰[Joh85Ž‘Ä9],‘¥!follo“w“ed˜b“y˜another˜depAÇendancyŽ¡’:âanalysis‘Tpass.Ž¦’äëPŽŽŽ’:âºThe– Ûprogram“is“noš¾9w“t˜ypAÇec˜hec˜k˜ed,‘¼using“a“standardŽ¡’:âMilner-Hindley–ƒinferencer“deriv¾9ed“from“Chapter“9“ofŽ¡’:âPš¾9eyton–…uJones'“b•AÇo“ok–…u[P˜ey87Ž‘Hª].‘lÒEv˜ery“noAÇde“in“the“CoreŽ¡’:âtree–;has“a“tš¾9ypAÇe“expression“attac˜hed.‘hAlthough“a“com-Ž¡’:âplete–mannotation“is“rather“expAÇensivš¾9e,‘ ³it“is“essen˜tial“forŽ¡’:âsubsequen¾9t‘Tpasses.Ž¦’äëPŽŽŽ’:âºThe–þNsingle“most“complicated“transformation,‘8Œhigher-Ž¡’:âorder–ôfunction“remoš¾9v‘ÿ|ral“(also“kno˜wn“as“spAÇecialisationŽ¡’:âor–zrstication)“noš¾9w“follo˜ws.‘(âThe“presen˜t“naiv˜e“im-Ž¡’:âplemen¾9tation,›|xdescribAÇed–g×in“Section“5,˜is“slo¾9w“but“cor-Ž¡’:ârect.‘™cMost–é¥if“not“all“of“the“higher-orderness“of“t¾9ypi-Ž¡’:âcal–Q™programs“can“bAÇe“remo•¾9v“ed.‘Ñ>This–Q™transformation“isŽ¡’:âcomplicated–¹ybš¾9y“the“need“to“main˜tain“t˜ypAÇe“annotationsŽ¡’:âcorrectly‘ÿ:«.ŽŽŽŽŽŸ’çjã2ŽŽŒ‹ •ºâ ý? £ ý€‘ûäëPŽŽŽ‘:âºFinally‘ÿ:«,‘ŸSthe–ƒºprogram“is“monomorphised.‘g¡This“pass“isŽ¤
‘:âquicš¾9k–Ÿand“relativ˜ely“painless,‘\ev˜en“though“a“third“tripŽ¡‘:âthrough–Ó•the“depAÇendancy“analyser“is“subsequen¾9tly“re-Ž¡‘:âquired.Ž©Ù‘íºâMost–†£compilers“wš¾9ould“w˜an˜t“to“mangle“the“output“of“theŽ¡‘íºâdesugarer–5rin“quite“dierenš¾9t“w˜a˜ys“to“generate“go•AÇo“d‘5rco“de.‘ÑÏF‘ÿ:«or-Ž¡‘íºâtunately‘ÿ:«,‘Ñit–«is“easy“to“see“ho¾9w“the“output“of“the“strictnessŽ¡‘íºâanalyser–ççpropšAÇer“p˜ertains“to“the“desugared“program.‘”)OnlyŽ¡‘íºât•¾9w“o–Ttransformations“givš¾9e“m˜uc˜h“trouble:ŽŸØ‘ûäëPŽŽŽ‘:âºLamš¾9bAÇda-lifting–psimply“mo˜v˜es“bindings“from“inner“lev-Ž¡‘:âels–Véto“the“top“lev¾9el,‘|ÿand“adds“extra“parameters.‘Ü÷With“aŽ¡‘:âlittle›¢bb•AÇo“okk¾9eeping,‘¹_it˜is˜p“ossible˜to˜k•¾9eep˜trac“k˜of˜whereŽ¡‘:ânested–pŸbindings“ended“up,‘‡rso“that“strictness“informa-Ž¡‘:âtion–Tcan“bAÇe“related“bac¾9k“to“them.ŽŸ×x‘ûäëPŽŽŽ‘:âºHigher-order–1tfunction“remoš¾9v‘ÿ|ral“will“only“ev˜er“remo˜v˜eŽ¡‘:âhigher-order–NTfunctions“whicš¾9h“ha˜v˜e“bAÇecome“irrelev‘ÿ|ran˜tŽ¡‘:âbšAÇecause–Gˆof“sp˜ecialisation.‘³All“rst-order“functions“areŽ¡‘:âpreservš¾9ed.‘
gwW‘ÿ:«e–.Vare“really“only“in˜terested“in“deriv-Ž¡‘:âing–†Xev‘ÿ|raluation“transformers“for“the“rst“order“func-Ž¡‘:âtions.‘$ëThis–m}is“bAÇecause“the“demand“propagated“acrossŽ¡‘:âa–ÿ/higher-order“function“largely“depAÇends“on“what“theŽ¡‘:âhigher-order–@Eparameter“is.‘ÕkSo“exploiting“demand“prop-Ž¡‘:âagation–Xacross“higher-order“functions“means“run¾9timeŽ¡‘:âmanipulation–×of“ev‘ÿ|raluation“transformers,‘‡|a“seriousŽ¡‘:âcomplication–Tfor“parallel“graph“reduction“systems.Ž¦‘íºâBuilding–¿Áand“mainš¾9taining“the“framew˜ork“is“a“tiresome,‘ÐÞtimeŽ¡‘íºâconsuming–z°task.‘èäOne“could“also“argue“all“that“eort“w¾9as“un-Ž¡‘íºânecessarily‘ÿ:«,‘%_bAÇecause–"*the“Glasgoš¾9w“Hask˜ell“team“ha˜v˜e“spAÇeci-Ž¡‘íºâcally–þdesigned“their“compiler“as“a“basis“for“expAÇerimenš¾9ts“lik˜eŽ¡‘íºâthis,‘º5and–f	v‘ÿ|ralianš¾9tly“suppAÇorted“those“bra˜v˜e“enough“to“tak˜eŽ¡‘íºâthem–¡´up“[PHHP93Ž‘#µø].‘ÁIn“retrospAÇect,‘ÄÌthere“are“three“reasonsŽ¡‘íºâwhš¾9y–TAnna“w˜as“not“built“in˜to“Glasgo˜w“Hask˜ell:ŽŸØ‘ø‰1.ŽŽŽ‘:âAš¾9t–Ïçthe“time“w˜ork“on“Anna“bAÇegun,‘þ‹in“the“summer“ofŽ¡‘:â1991,‘ÖGlasgoš¾9w's–¼compiler“(v˜ersion“0.02)“w˜as“in“still“inŽ¡‘:âthe–TproAÇcess“of“dev•¾9elopmen“t.Ž©×x‘ø‰2.ŽŽŽ‘:âUn•¾9til›gFrecen“tly‘ÿ:«,‘»Ãthe˜analyser˜w“as˜relativ“ely˜feeble,‘»ÃsoŽ¡‘:âthe–ú¹need“to“feed“it“realistic“Hask¾9ell“programs“has“onlyŽ¡‘:ârecen¾9tly‘Tarisen.Ž¦‘ø‰3.ŽŽŽ‘:âThe–…Ïmost“impAÇortan¾9t“reason,–¢ƒthough,“is–…Ïthis:‘Ô­Anna“hadŽ¡‘:âb•AÇeen›êdev¾9elop“ed˜using˜Mark˜Jones'˜marv•¾9ellous˜in“terac-Ž¡‘:âtiv•¾9e›¯?en“vironmen“t,‘êGofer.‘úiMerging˜Anna˜in“to˜the˜Glas-Ž¡‘:âgo•¾9w›À Hask“ell˜w“orld˜w“ould˜ha“v“e˜mean“t˜compiling˜withŽ¡‘:âa–yêHaskš¾9ell“compiler“and“this“w˜ould“easily“ha˜v˜e“put“anŽ¡‘:âorder–m£of“magnitude“on“the“edit-compile-run“cycle“time.ŽŸÙ‘íºâAs–Å€Anna“bšAÇecomes“more“and“more“p˜o•¾9w“erful,‘Õwthe›Å€incen“tiv“e˜toŽ¡‘íºâbuild–'it“inš¾9to“a“real“compiler“gro˜ws.‘êThis“is“denitely“a“longŽ¡‘íºâterm‘Tob‘ƒŽjectiv¾9e.ŽŸ	‘íºâ¹2Ž‘ü”T‘ÿ,Ìechnical‘LÎp•¹™relimina“riesŽŸ†´‘íºâ2.1Ž‘G·Some‘LÎterminologyŽŸm‘íºâºThe–ÿanalyser's“fron¾9t“end“proAÇduces“a“ëNCore––Åsyn´Ctax“treeº,‘ *inŽ¡‘íºâwhic•¾9h›Rev“ery˜noAÇde˜is˜decorated˜with˜its˜t“ypAÇe.‘Ò¥This˜is˜fed˜toŽ¡‘íºâthe–oëNabstract‘¢bin´Cterpreter“ºpropAÇer,‘Bµwhic¾9h“translates“to“anŽ¡‘íºâabstract›9=form:‘dBëNrecursiv´Ce–Üádomain“equationsº.‘ˆ,The˜ëNx-Ž¡‘íºâpK¼oin´Cter–›€ºsolvš¾9es“these“equations“b˜y“iterating“to“their“greatestŽŽŽ ý€’õºâxed–népAÇoinš¾9ts,‘…Ndetecting“equalit˜y“of“adjacen˜t“appro˜ximationsŽ¤
’õºâb¾9y–š³reducing“them“to“ëNnormal›ÿšform“ºusing“the“ëNterm˜rewrit-Ž¡’õºâing‘ŒÊsystemº,–Tand“comparing“those“normal“forms.ŽŸ
’õºâThere–Tare“t•¾9w“o–Tkinds“of“abstract“en•¾9tit“y‘ÿ:«.Ž©ÐO’äëPŽŽŽ’:âëNCon´Ctexts–eºdenote“an“amoun¾9t“of“ev‘ÿ|raluation“that“shouldŽ¡’:âbAÇe–àUapplied“to“a“data“structure“or“function.‘	}sTheseŽ¡’:âare– Dsometimes“referred“to“as“ëNdemands“ºor“ëNbac•´Ckw“ardsŽ¡’:âv‘ÿh‰aluesº,‘á¦but–…–wš¾9e“will“stic˜k“with“ëNcon´Ctext“ºwhere“pAÇos-Ž¡’:âsible.‘ÑÊW‘ÿ:«e–ürlater“inš¾9troAÇduce“a“Hask˜ell“t˜ypAÇe“ëMContext“ºtoŽ¡’:âmoAÇdel‘Tcon¾9texts.ŽŸ34’äëPŽŽŽ’:âëNAbstract‘CFv‘ÿh‰alues–Õzºamounš¾9t“to“some“tric˜k˜ery“w˜e“will“in-Ž¡’:âtroAÇduce–øÙto“deal“with“higher“order“functions.‘òAn“alter-Ž¡’:ânativ•¾9e›ýname,‘['whic“h˜is˜again˜a“v“oided˜where˜pAÇossible,Ž¡’:âis–"’ëNforw´Card‘œ	v‘ÿh‰alueº.‘D*The“correspAÇonding“Haskš¾9ell“t˜ypAÇe“isŽ¡’:âëMAbsValº.Ž¦’õºâThis–?¿papAÇer“is“primarily“concerned“with“disco•¾9v“ering‘?¿ho“wŽ¡’õºâsource–Ý(language“functions“bAÇeha•¾9v“e–Ý(viz-a-viz“con¾9texts.‘síNev-Ž¡’õºâertheless,‘ßgthe–¶ýoutput“of“the“abstract“in¾9terpreter“is“one“ab-Ž¡’õºâstract–EÙv›ÿ|ralue“pAÇer“Core“function.‘×GCon¾9texts“and“abstract“v˜aluesŽ¡’õºâin•¾9tert“wine,‘Öfso–¯Éthe“ëMContext“ºand“ëMAbsVal“ºtš¾9ypAÇes“are“m˜utuallyŽ¡’õºârecursivš¾9e.‘ÄThe–÷Üabstract“in˜terpreter“itself“is“dened“as“theŽ¡’õºâfunction–TëMZ“ºin“section“3.6.1.Ž©
’õºâCon¾9texts–ˆand“abstract“v‘ÿ|ralues“are,›¤Zin“a“sense,˜strongly“t¾9ypAÇed.Ž¡’õºâEac•¾9h›£Bcon“text˜is˜a˜mem“bAÇer˜of˜a˜particular˜ëNcon´Ctext‘	udomainº,Ž¡’õºâand–nSmost“opAÇerations“on“con¾9texts“are“only“meaningful“if“theirŽ¡’õºâopAÇerands–ÿ8are“dra¾9wn“from“particular“domains.‘Abstract“v‘ÿ|ral-Ž¡’õºâues–zÌare“also“strongly“t¾9ypAÇed.‘L×Although“the“domains“for“ab-Ž¡’õºâstract–uv‘ÿ|ralues“are,›[¼strictly“spAÇeaking,˜dierenš¾9t“from“con˜textŽ¡’õºâdomains,›£Âw¾9e–‡]will“ignore“abstract“v‘ÿ|ralue“domains.‘íInstead,˜w¾9eŽ¡’õºâonly–“ýconsider“con¾9text“domains,‘³§henceforth“referred“to“sim-Ž¡’õºâply–Tas“ëNdomainsº,‘Tand“pretend“that“for“eac¾9h“domain“there“isŽ¡’õºâa–Tfamily“of“con¾9texts,“and“a“family“of“abstract“v‘ÿ|ralues.Ž¦’õºâF‘ÿ:«or–Z}eacš¾9h“Milner-Hindley“t˜ypšAÇe,‘kÇthere“is“a“corresp˜onding“do-Ž¡’õºâmain.‘}+In–5’general,‘=¢there“maš¾9y“bAÇe“man˜y“dieren˜t“t˜ypAÇes“whic˜hŽ¡’õºâmap–´Üto“the“same“domain.‘ûThe“next“section“denes,‘ܾinfor-Ž¡’õºâmally–ÿ:«,‘Ä‘this›°`mapping.‘úÉW“e˜then˜rene˜the˜mapping˜sligh¾9tly˜inŽ¡’õºâsection–T2.2.4,“and“formalise“it“in“section“2.2.5.Ž©5’õºâ¹2.2Ž’G·Domains–LÎfoš¹™r“p˜rojection“analysisŽŸm’õºâºA‘@primary–@*aim“of“these“analyses“is“to“generate“informationŽ¡’õºâuseful–Õúfor“exploiting“a“parallel“macš¾9hine.‘RT‘ÿ:«o“this“end,‘â¦w˜e“useŽ¡’õºâdomains–9³whicš¾9h“are“bAÇest“view˜ed“as“a“generalisation“of“theŽ¡’õºâev‘ÿ|raluation–âétransformers“inš¾9troAÇduced“b˜y“Burn“[Bur87Ž‘Žã].‘¢TheseŽ¡’õºâare–Tinš¾9troAÇduced“b˜y“example.Ž¦’õºâ¹2.2.1Ž’úíBase‘LÎt¹™ypFfesŽŸm’õºâºBase–¥ˆt¾9ypšAÇes“ëMInt“ºand“ëMChar“ºare“mapp˜ed“to“a“t•¾9w“o‘¥ˆp˜oin“t‘¥ˆdomainŽ¡’õºâëM2–¹–=“{0,“1}º,‘Ú8with–²ØëM0“ºmeaning“\do“not“ev‘ÿ|raluate“this"“and“ëM1Ž¡’õºâºmeaning–n·\ev›ÿ|raluate“fully".‘äæIn“this“case“only‘ÿ:«,‘
full“ev˜aluation“isŽ¡’õºâthe–§Usame“as“ev‘ÿ|raluation“to“w¾9eak“head“normal“form“(WHNF).Ž¦’õºâ¹2.2.2Ž’úíNon-recursive–LÎstructured“t¹™ypFfesŽŸm’õºâºConsider–DÕthe“inš¾9terpretation“of“a“familiar“non-recursiv˜e“struc-Ž¡’õºâtured–mBt¾9ypšAÇe:‘ÌMëM(Int,‘¹–Int)º.‘$;W‘ÿ:«e“need“to“mo˜del“the“ev‘ÿ|raluatorsŽ¡’õºâfor–¤the“compAÇonenš¾9ts“of“the“pair“separately‘ÿ:«,‘øso“there“m˜ust“bAÇeŽ¡’õºâa–ÃprošAÇduct“in•¾9v“olv“ed:‘wÿëM(2–¹–x“2)º.‘%ÆAn–Ãev‘ÿ|raluator“corresp˜ondingŽŽŽŽŽŸ’çjã3ŽŽŒ‹<à•ºâ ý? £ ý€‘íºâºto–AØanš¾9y“suc˜h“pAÇoin˜t“w˜ould“rst“ha˜v˜e“to“ev‘ÿ|raluate“the“pair“clo-Ž¤
‘íºâsure–~ëto“WHNF,“so“it“could“get“its“hands“on“the“individualŽ¡‘íºâcompAÇonen•¾9ts.‘
ÕSo›à„w“e˜really˜need˜a˜fth˜pAÇoin“t˜represen“ting˜anŽ¡‘íºâev‘ÿ|raluator–õˆwhicš¾9h“doAÇes“nothing“at“all.‘×The“o˜v˜erall“in˜terpreta-Ž¡‘íºâtion–Tis“ëMLift–¹–(2“x“2)º.ŽŸ
‘íºâAš¾9t–Fóthis“pAÇoin˜t“it“is“con˜v˜enien˜t“to“in˜troAÇduce“a“notation“forŽ¡‘íºâpšAÇoin¾9ts–çåto“b˜e“used“throughout“this“pap˜er.‘
KThe“b˜ottom“p˜oin¾9tŽ¡‘íºâof–¶the“abAÇo•¾9v“e–¶domain“is“written“as“an“underscore,‘UÎëM_º.‘•TheŽ¡‘íºâother–¼·four“are“written“in“the“form“ëMU[x,‘¹–y]“ºwhere“the“ëMUŽ¡‘íºâºstands–\Vfor“\go“up“the“ëMLiftº",‘Vand“the“ëMx“ºand“ëMy“ºare“the“relev‘ÿ|ran¾9tŽ¡‘íºâpro•AÇduct›»comp“onen•¾9ts.‘5¥The˜o“v“erall˜collection˜of˜ev‘ÿ|raluators˜isŽ¡‘íºâth¾9us–ZVwritten“ëM{_,–¹–U[0,0],“U[0,1],“U[1,0],“U[1,1]}‘ZVºwithŽ¡‘íºâthe–Tfollo¾9wing“ordering:Ž©ÐO‘_ òëMU[1,1]Ž¡‘Zg\/‘Y„\Ž¡‘>
ØU[0,1]‘%Ì°U[1,0]Ž¡‘Zg\\‘Y„/Ž¡‘_ òU[0,0]Ž¡‘mM´|Ž¡‘mM´_Ž¦‘íºâºHoš¾9w– \doAÇes“this“generalise“to“arbitrary“non-recursiv˜e“struc-Ž¡‘íºâtured›%t•¾9ypAÇes?‘K¢W‘ÿ:«ell,‘(þv“ery˜simply‘ÿ:«.‘K¢A‘%non-recursiv“e˜structuredŽ¡‘íºât¾9ypšAÇe–ŽÆis“mo˜delled“b¾9y“the“single“lifting“of“the“pro˜duct“of“what-Ž¡‘íºâevš¾9er–=Fits“t˜ypšAÇe“v‘ÿ|rariables“are“b˜ound“to.‘”GF‘ÿ:«urther“details“are“ir-Ž¡‘íºârelev‘ÿ|ranš¾9t.‘3That's–ÇŽbAÇecause“w˜e“observ˜e“the“guiding“rule“thatŽ¡‘íºâall–ãÂob‘ƒŽjects“correspšAÇonding“to“a“particular“t¾9yp˜e“v‘ÿ|rariable“areŽ¡‘íºâtreated–6ïas“a“single“en•¾9tit“y‘ÿ:«.‘AThis–6ïrule“is“impAÇosed“for“the“pur-Ž¡‘íºâpAÇose–…of“kš¾9eeping“things“reasonably“straigh˜tforw˜ard.‘k°F‘ÿ:«or“ex-Ž¡‘íºâample,‘Tgiv¾9en:Ž¦‘ûç¤ëMdata–¹–Foo“a“b“=“MkFoo“a“bŽ¡‘9TB|–¹–MkA“aŽ¡‘9TB|–¹–MkB“bŽ¡¡‘ûç¤data–¹–Grok“a“b“c“=“MkGrok“a“b“cŽ¡‘G|–¹–GrokodileDundee“a“a“a“b“b“cŽ¦‘íºâºa–±~v‘ÿ|ralue“of“ëM(Foo–¹–Int“Int)–±~ºis“mappAÇed“to“ëMLift–¹–(2“x“2)º,Ž¡‘íºâand›S­ëM(Grok–¹–Int“Int“Int)˜ºto˜ëMLift“(2“x“2“x“2)º.‘
×|MoreŽ¡‘íºâcomplicated–{parameterisations“giv¾9e“rise“to“more“com-Ž¡‘íºâplicated–щdomains.‘QThe“t¾9ypAÇe“ëM(Grok–¹–Int“(Foo“Int“Int)Ž¡‘íºâ(Grok–¹–Int“Int“Int))–i®ºhas“a“91“pAÇoin¾9t“domainŽ¡‘íºâëMLift–¹–(2“x“Lift“(2“x“2)“x“Lift“(2“x“2“x“2))º.ŽŸ
‘íºâIt–úKis“wš¾9orth“understanding“that“the“n˜um˜bšAÇer“of“pro˜duct“com-Ž¡‘íºâpAÇonenš¾9ts–ãýis“equal“to“the“n˜um˜bAÇer“of“t˜ypAÇe“v‘ÿ|rariables,‘§and“en-Ž¡‘íºâtirely–®unrelated“to“the“n•¾9um“bAÇer–®of“parameters“of“an¾9y“partic-Ž¡‘íºâular–g[constructor.‘…A‘gFcon¾9text“ëMU[1,0,0]“ºapplied“to“an“ob‘ƒŽjectŽ¡‘íºâof–µt¾9ypAÇe“ëM(Grok–¹–Int“Int“Int)–µºmeans:‘)1ev‘ÿ|raluate“the“ob‘ƒŽject“toŽ¡‘íºâthe–·|rst“constructor.‘çThen,›àif“it“is“a“ëMMkGrokº,˜ev‘ÿ|raluate“theŽ¡‘íºârst–{5argumenš¾9t.‘NOtherwise,‘”­it“m˜ust“bAÇe“a“ëMGrokodileDundeeº,Ž¡‘íºâso–&Eev‘ÿ|raluate“the“rst“three“parameters.‘ODW‘ÿ:«e“treat“the“rstŽ¡‘íºâargumen¾9t–Îto“ëMMkGrok“ºand“the“rst“three“of“ëMGrokodileDundeeŽ¡‘íºâºas–¸da“single“en•¾9tit“y–¸dbšAÇecause“they“all“corresp˜ond“to“the“sameŽ¡‘íºât¾9ypAÇe–Tv‘ÿ|rariable,“ëMaº,“in“the“declaration.ŽŸ5‘íºâ¹2.2.3Ž‘úíRecursive–LÎstructured“t¹™ypFfesŽŸm‘íºâºSo–QQfar,‘`Qthings“are“reasonably“straigh•¾9tforw“ard.‘ÐhBut‘QQdeningŽ¡‘íºâev‘ÿ|raluators–1œfor“recursivš¾9e“t˜ypšAÇes“is“a“mineeld,‘8®partly“b˜ecauseŽ¡‘íºâthere–exare“so“manš¾9y“alternativ˜e“form˜ulations“[W‘ÿ:«ad87Ž‘¿˜]“[WH87Ž‘±].Ž¡‘íºâAs–v¸it“happAÇens,‘Ïthe“form¾9ulation“used“in“Anna“is“a“trivialŽŽŽ ý€’õºâv‘ÿ|rariation–JÕof“the“rule“for“non-recursivš¾9e“t˜ypAÇes,‘sUbut“justicationŽ¤
’õºâis–Tnot“so“easy‘ÿ:«.ŽŸ
’õºâThe–#§rule“is“idenš¾9tical“to“the“non-recursiv˜e“case,‘g;except“forŽ¡’õºâthe–ïÖfollo¾9wing“mošAÇdication:‘	±the“single“lifting“of“the“pro˜duct,Ž¡’õºâwritten–¥+ëMLiftº,›É is“replaced“b¾9y“a“double“lifting,˜ëMLift2º.‘ËõNo¾9w,Ž¡’õºâgiv¾9en–Tthe“pseudo-declarationŽ©ÐO’ç¤ëMdata–¹–[a]“=“[]Ž¡’.mê|–¹–a“:“[a]Ž¦’õºâºit–Tis“easy“to“see“that“the“domain“for“ëM[Int]“ºis“ëMLift2‘¹–(2)º,‘c¶aŽ¡’õºâfour–‰@pšAÇoin¾9t“domain“corresp˜onding“precisely“to“the“in¾9terpreta-Ž¡’õºâtion–for“that“tš¾9ypAÇe“made“b˜y“W›ÿ:«adler“[W˜ad87Ž‘¿˜]“and“later“justi-Ž¡’õºâed–!b¾9y“Burn“[Bur87Ž‘Žã].‘ËExtending“the“notation“of“the“previousŽ¡’õºâsection,‘Dqwš¾9e–7write“the“pAÇoin˜ts“in“this“domain“as“ëM{_,–¹–U_,“UU[0]Ž¡’õºâºand–Ý®ëMUU[1]}º,‘Äunderstanding“them“to“denote“the“ev‘ÿ|raluatorsŽ¡’õºâwhic¾9h–TBurn“called“ëM{E0,–¹–E1,“E2–Tºand“ëME3}º:Ž¦’äëPŽŽŽ’:âëM_º:‘pDo–Tnot“ev‘ÿ|raluate“at“all“(ëME0º).Ž©34’äëPŽŽŽ’:âëMU_º:‘¹Ev‘ÿ|raluate–æas“far“as“the“rst“constructor,›üthat“is,˜toŽ¡’:âw¾9eak–Thead“normal“form“(ëME1º).Ž¦’äëPŽŽŽ’:âëMUU[0]º:‘pEv‘ÿ|raluate–Tthe“en¾9tire“structure“of“the“list“(ëME2º).Ž¦’äëPŽŽŽ’:âëMUU[1]º:‘˺Ev‘ÿ|raluate–ìùthe“en¾9tire“structure“of“the“list,‘"âandŽ¡’:âall–Tthe“elemen¾9ts“(ëME3º).ŽŸÐO’õºâIn–T“general,‘{!a“recursivš¾9e“t˜ypAÇe“of“ëMn“ºparameters“has“ev‘ÿ|raluators“ofŽ¡’õºâthe–þform“ëM{_,›¹–U_“ºand“ëMUU[x1˜...˜xn]}º.‘­The“ëMUU[x1˜...˜xn]Ž¡’õºâºpAÇoinš¾9ts–O›denote“ev‘ÿ|raluating“the“en˜tire“structure,‘^,and“then“ap-Ž¡’õºâplying–«Hev‘ÿ|raluator“ëMx1“ºto“eac¾9h“ob‘ƒŽject“correspAÇonding“to“the“rstŽ¡’õºâparameter,‘WëMx2–¬ºto“ob‘ƒŽjects“correspAÇonding“to“the“second“pa-Ž¡’õºârameter,›³Cand–`zso“on.‘ýâW‘ÿ:«e“will“see,˜in“Section“4,˜that“thisŽ¡’õºâconceptual–¸partitioning“of“all“recursivš¾9e“domain“pAÇoin˜ts“in˜toŽ¡’õºâthree–ž#sections“is“crucial“to“the“w¾9orking“of“the“term“rewritingŽ¡’õºâsystem–œbused“to“detect“xpAÇoinš¾9ts.‘ôSimilarly‘ÿ:«,‘´“the“non-recursiv˜eŽ¡’õºâpAÇoin•¾9ts›¼ãma“y˜bAÇe˜partitioned˜in“to˜t“w“o:‘ð7ëM{_˜ºand˜ëMU[x1–¹–...“xn]}º.Ž©
’õºâThe–ºguiding“principle,›#>originally“stated“b¾9y“W‘ÿ:«adler,˜is“toŽ¡’õºâmoAÇdel–“tthe“recursivš¾9e“t˜ypAÇes“b˜y“letting“the“sub-ev‘ÿ|raluatorsŽ¡’õºâin–')ëMUU[...]“ºv‘ÿ|ralues“bAÇe“represen•¾9tativ“e–')of“the“least“denedŽ¡’õºâelemenš¾9t–óèof“that“t˜ypAÇe“in“the“structure.‘¸,Imagine“w˜eŽ¡’õºâha•¾9v“e–©Õa“list“of“tš¾9ypAÇe“ëM[(Int,‘¹–Int)]º,‘Žôwhic˜h“induces“do-Ž¡’õºâmain›ªvëMLift2–¹–(Lift“(2“x“2))º,‘Ͼand˜w•¾9e˜kno“w˜that˜ev‘ÿ|raluatorŽ¡’õºâëMUU[U[0,1]]–°Ÿºis“the“strongest“that“can“safely“bAÇe“applied“(thatŽ¡’õºâis,‘mwithout–³danger“of“non-termination)“to“the“list.‘õzNo¾9wŽ¡’õºâsuppAÇose–Âwš¾9e“obtain“another“list“for“whic˜h“ëMUU[U[1,0]]“ºis“theŽ¡’õºâstrongest–ßsafe“ev‘ÿ|raluator,‘MÄand“appAÇend“it“to“the“original.‘ÉIWhatŽ¡’õºâis–ôHthe“bšAÇest“ev‘ÿ|raluator“that“can“b˜e“applied“to“the“new“list?Ž¡’õºâIt–O}cannot“bAÇe“either“of“the“originals,‘žsince“that“risks“non-Ž¡’õºâtermination.‘'HThe–nGmost“wš¾9e“can“ev‘ÿ|raluate“an˜y“particular“ele-Ž¡’õºâmen¾9t–luwhilst“remaining“safe“is“ëMU[0,0]º,‘‚=so“the“bAÇest“that“canŽ¡’õºâbAÇe–applied“to“the“list“as“a“whole“is“ëMUU[U[0,0]]“º{“the“great-Ž¡’õºâest›fÉlo•¾9w“er˜bAÇound˜of˜the˜v‘ÿ|ralues˜for˜the˜original˜lists.‘ÏW‘ÿ:«adlerŽ¡’õºâsummarised–”Sthis“bš¾9y“stating“that“a“list“is“c˜haracterised“\b˜yŽ¡’õºâits–¦Ùleast“dened“elemenš¾9t"“but“w˜e“need“to“bAÇe“more“precise:Ž¡’õºâa–— list“is“cš¾9haracterised“b˜y“the“greatest“ev‘ÿ|raluator“that“canŽ¡’õºâsafely–D•bAÇe“applied“to“anš¾9y“elemen˜t,‘Peev˜en“if“a“stronger“ev‘ÿ|ralua-Ž¡’õºâtor–Icould“bšAÇe“applied“to“sp˜ecic“elemen¾9ts.‘Ø~The“same“principleŽ¡’õºâgeneralises–SÔto“structured“tš¾9ypAÇes“of“an˜y“n˜um˜bAÇer“of“parameters,Ž¡’õºâwith–^the“greatest-lo•¾9w“er-bAÇound›^c“haracterisation˜oAÇccurring˜in-Ž¡’õºâdepAÇendenš¾9tly–Tfor“eac˜h“parameter.Ž¦’õºâThis–(abstraction,›FËwhilst“simple,˜assumes“that“programs“treatŽ¡’õºâall–ð	elemenš¾9ts“of“the“same“t˜ypAÇe“inside“a“structure“in“the“sameŽŽŽŽŽŸ’çjã4ŽŽŒ‹[” •ºâ ý? £ ý€‘íºâºw•¾9a“y–ÿ:«.‘F“or–åÜexample,‘ï[it“assumes“list“proAÇcessing“functions“treatŽ¤
‘íºâall–èÍelemenš¾9ts“in“the“list“the“same“w˜a˜y–ÿ:«.‘
˜F“unctions–èÍnot“pla˜yingŽ¡‘íºâalong–Áwith“this“ma¾9y“induce“bad,›Ñ÷but“safe,˜results.‘^Consider:Ž¤ÐO‘ûç¤ëMtail–¹–(x:xs)“=“xsŽ¡‘íºâºIf–¿^wš¾9e“apply“a“ëMUU[1]“ºev‘ÿ|raluator“to“ëM(tail‘¹–zs)º,‘éàwhat“can“w˜eŽ¤
‘íºâev‘ÿ|raluate–Œ%ëMzs“ºwith?‘€ãUnfortunately‘ÿ:«,›©Ùnot“ëMUU[1]º,˜since“the“ele-Ž¡‘íºâmenš¾9t–"that“ëMtail“ºthro˜ws“a˜w˜a˜y“migh˜t“just“ha˜v˜e“bAÇeen“the“one-Ž¡‘íºâand-only–¥þnon-terminating“ëMInt“ºin“the“list.‘ÎmErring“on“theŽ¡‘íºâside–ààof“safetš¾9y“th˜us“restricts“the“ev‘ÿ|raluator“for“ëMzs“ºto“ëMUU[0]º,Ž¡‘íºâand–%îloses“all“the“pAÇoten¾9tial“parallelism“in“ev‘ÿ|raluating“the“ele-Ž¡‘íºâmen¾9ts–+in“the“rest“of“the“list.‘3ôOne“upshot“of“this,‘ also“notedŽ¡‘íºâbš¾9y–/RW‘ÿ:«adler,‘uÒis“that“dening“functions“directly“b˜y“pattern-Ž¡‘íºâmatcš¾9hing–	×is“essen˜tial“to“get“go•AÇo“d–	×results.‘ùúIn“the“exampleŽ¡‘íºâbAÇeloš¾9w,‘Âthe–­1analyser“giv˜es“a“m˜uc˜h“bAÇetter“result“for“ëMsum1“ºthanŽ¡‘íºâëMsum2º,–Tdespite“them“haš¾9ving“iden˜tical“strictness“propAÇerties.Ž©ÐO‘ûç¤ëMsum1–¹–[]‘Y„=“0Ž¡‘ûç¤sum1–¹–(x:xs)‘	s,=“x“+“sum1“xsŽ¡¡‘ûç¤sum2–¹–xs‘Y„=“if‘æXnull“xsŽ¡‘BÇnthen‘	s,0Ž¡‘BÇnelse‘	s,head–¹–xs“+“sum2“(tail“xs)Ž¦‘íºâºA‘áórelated–âdefect“is“the“inabilit¾9y“of“these“domains“to“captureŽ¡‘íºâthe–K@notion“of“head“strictness.‘¾3A‘K2head“strict“function“is“oneŽ¡‘íºâwhicš¾9h–Æ>ev‘ÿ|raluates“the“rst“item“in“a“list“whenev˜er“it“ev‘ÿ|raluatesŽ¡‘íºâthe–'list“as“far“as“the“rst“constructor,‘IÛand“disco•¾9v“ers–'it“toŽ¡‘íºâbAÇe–‹non-nil.‘}ªHead“strictness“is“useful“in“a“sequen¾9tial“imple-Ž¡‘íºâmen¾9tation,‘so–îan“extension“of“the“domains“to“capture“theseŽ¡‘íºâpropšAÇerties–Tw¾9ould“increase“the“useful“scop˜e“of“this“analyser.Ž©5‘íºâ¹2.2.4Ž‘úíMoFfdifying–LÎthe“notationŽŸm‘íºâºThe›,ÀabAÇo•¾9v“e˜mapping˜assigns˜domain˜ëMLift‘¹–()˜ºto˜allŽ¡‘íºâen•¾9umeration›	¹At“ypAÇes,‘b:for˜example˜the˜familiar˜t“ypAÇeŽ¡‘íºâëMdata–¹–Bool“=“False“|“Trueº.‘<<Observ¾9e–ʘthat“ëMLift‘¹–()“ºis“iso-Ž¡‘íºâmorphic–ôto“the“t•¾9w“o-pšAÇoin“t–ôdomain“used“for“base“t¾9yp˜es,‘®œandŽ¡‘íºârighš¾9tly–Tso.‘pAfter“all,“w˜e“could,“conceptually‘ÿ:«,“deneŽ¤ÐO‘íºâëMdata–¹–Int“=“...“-3“|“-2“|“-1“|“0“|“1“|“2“|“3“...Ž¡‘íºâºand–Twš¾9e'd“certainly“expAÇect“a“t˜w˜o-pAÇoin˜t“domain“for“it!ŽŸ
‘íºâThis–ãisomorphism“can“bAÇe“used“to“simplify“the“domain“struc-Ž¤
‘íºâture,‘¶~and–žÈth¾9us“the“strictness“analysis“itself.‘ôìW‘ÿ:«e“forget“abAÇoutŽ¡‘íºâdomain–žÁëM2º,‘and“instead“map“base“t¾9ypAÇes“ëMInt“ºand“ëMChar“ºtoŽ¡‘íºâëMLift›¹–()º,‘Ówith–8ípAÇoin¾9ts“ëM{_,˜U[]}“ºreplacing“ëM{0,˜1}º.‘‡;Hence-Ž¡‘íºâforth–Tthe“new“notation“is“used.Ž¦‘íºâ¹2.2.5Ž‘úíSumma¹™ryŽŸm‘íºâºLet–ö‹ëMD(t)“ºdenote“the“domain“for“some“t¾9ypAÇe“ëMtº.‘-Let“ëMtypeNameŽ¡‘íºâºbšAÇe–V5the“name“of“some“structured“t¾9yp˜e,‘fmand“ëMte1–¹–...“ten‘V5ºb˜eŽ¡‘íºâsome–Tarbitrary“t¾9ypAÇe“expressions.‘pëMD“ºis“dened“as:ŽŸÐO‘ûç¤ëMD(Int)‘,Â=–¹–Lift“()Ž¡‘ûç¤D(Char)‘	s,=–¹–Lift“()Ž¡¡‘ûç¤D(typeName–¹–te1“...“ten)Ž¡‘
f=–¹–Lift‘	s,(D(te1)“x“...“x“D(ten))Ž¡‘‡’if–¹–typeName“denotes“a“non-recursive“typeŽŽŽ ý€¤
’f=–¹–Lift2“(D(te1)“x“...“x“D(ten))Ž¡’‡’if–¹–typeName“denotes“a“recursive“typeŽŸR³’õºâºThe–mconcept“of“a“function-v‘ÿ|ralued“con¾9text“seems“rather“mean-Ž¡’õºâingless,–Tand“is“left“undened“un¾9til“section“3.2.ŽŸ! ’õºâ¹2.2.6Ž’úíRestrictions–LÎon“structured“t¹™ypFfesŽŸm’õºâºThe–šÂastute“reader“maš¾9y“ha˜v˜e“noticed“the“examples“abAÇo˜v˜eŽ¡’õºâha•¾9v“e–ž6bAÇeen“rather“restricted.‘ô»In“particular,‘¶
none“of“them“hadŽ¡’õºâconstan•¾9t›Ø~t“ypAÇes˜as˜an˜argumen“t˜to˜an“y˜constructor.‘)But˜thisŽ¡’õºâsituation–Â7is“commonplace,‘Ò×for“example“as“the“ëMInt“ºcon•¾9v“eyingŽ¡’õºâbalancing–Tinformation“in“the“follo¾9wing“tree“declaration:Ž©kÒ’ç¤ëMdata–¹–AVLTree“a“bŽ¡’f=‘¹–ALeafŽ¡’f|–¹–ANode“Int“(AVLTree“a“b)“a“b“(AVLTree“a“b)Ž¦’õºâºInstead–ðiof“extending“the“domain-generating“rules“to“co•¾9v“erŽ¡’õºâsuc¾9h–˜¦cases,‘¹zit“is“simpler“to“factorise“out“the“oending“ëMIntº,Ž¡’õºâgenerating–Ta“second“t¾9ypAÇe“ëMAVLTree2º:Ž¦’ç¤ëMdata–¹–AVLTree2“i“a“bŽ¡’f=‘¹–ALeaf2Ž¡’f|–¹–ANode2“i“(AVLTree2“i“a“b)“a“b“(AVLTree2“i“a“b)Ž¦’õºâ(AVLTree2–¹–Int“a“b)–½(ºis“an“isomorphicŽ¡’õºâtš¾9ypAÇe–“]to“ëM(AVLTree–¹–a“b)º,‘²ßat–“]the“same“t˜ypšAÇe“b˜eing“a“t¾9yp˜e“forŽ¡’õºâwhic•¾9h›tŒw“e˜kno“w˜ho“w˜to˜generate˜an˜abstract˜domain.‘æØCon“v“e-Ž¡’õºânien•¾9tly‘ÿ:«,‘Þ±Milner-Hindley›¶lt“ypAÇec“hec“k“ers˜are˜amenable˜to˜suc“hŽ¡’õºâsubstitutions.ŽŸ
’õºâFinally‘ÿ:«,‘yNobservš¾9e–eOthat“there“are“certain“t˜ypAÇes“for“whic˜h“it“isŽ¡’õºâhard–Tto“devise“a“sensible“set“of“ev‘ÿ|raluators,“for“example:Ž¦’ç¤ëMdata–¹–Foo“a“bŽ¡’f=–¹–MkFoo“a“b“(Foo“(Foo“a“b)“(Foo“a“b))Ž¦’õºâºThe–D€solution“adopted“in“Anna“is“simply“to“deem“these“ille-Ž¡’õºâgal.‘ÍW‘ÿ:«e–¸require“that,›àÐin“a“t¾9ypAÇe“declaration,˜argumen¾9ts“onŽ¡’õºâconstructors–e"are“either“simple“v‘ÿ|rariables“(here,›yëMa“ºor“ëMbº),˜or“aŽ¡’õºâsimple–Áìrecursiv¾9e“instance“of“the“structure“(here,‘íëMFoo–¹–a“bº).Ž¡’õºâThese–þwrestrictions“seem“inconsequen¾9tial“for“real“programs,Ž¡’õºâand›Tha•¾9v“e˜b•AÇeen˜rep“orted˜quite˜indep“endan¾9tly˜in˜[KHL91Ž‘(Ô].ŽŸ! ’õºâ¹2.3Ž’G·The–LÎCoš¹™re“datat˜ypFfeŽŸm’õºâºThe–5extensivš¾9ely“mangled“source“program“ev˜en˜tually“passedŽ¡’õºâto–œ‰the“abstract“inš¾9terpreter“is“a“t˜ypAÇe-annotated“tree,‘¾Vrepre-Ž¡’õºâsenš¾9ting–íÃa“simple“functional“language.‘@Eac˜h“noAÇde“in“the“treeŽ¡’õºâcarries– Fwith“it“an“annotation.‘½GThe“Haskš¾9ell“data“t˜ypAÇe“usedŽ¡’õºâis–áìparameterised“o•¾9v“er–áìbšAÇoth“the“t¾9yp˜e“of“the“annotations,‘ì4andŽ¡’õºâthe–Ttš¾9ypAÇe“of“the“iden˜tier“names:Ž¦’ç¤ëMtype–¹–AnnExpr“a“bŽ¡’f=–¹–(b,“AnnExpr'“a“b)Ž¡¡’ç¤data–¹–AnnExpr'“a“bŽ¡’f=‘¹–AVar‘ŸîaŽ¡’f|‘¹–AConstr‘	s,aŽ¡’f|‘¹–ALit‘ŸîIntŽ¡’f|–¹–AAp‘Y„(AnnExpr“a“b)“(AnnExpr“a“b)Ž¡’f|–¹–ALet‘ŸîBool“[AnnBind“a“b]“(AnnExpr“a“b)ŽŽŽŽŽŸ’çjãº5ŽŽŒ‹zõ •ºâ ý? £ ý€‘
fëM|–¹–ACase‘æX(AnnExpr“a“b)“[AnnAlt“a“b]Ž¤
‘
f|–¹–ALam‘Ÿî[a]“(AnnExpr“a“b)Ž¡¡‘ûç¤type–¹–AnnBind“a“bŽ¡‘
f=–¹–(a,“AnnExpr“a“b)Ž¡¡‘ûç¤type–¹–AnnAlt“a“bŽ¡‘
f=–¹–(a,“([a],“AnnExpr“a“b))ŽŸâ‘íºâºThe–Èrst“and“second“parameters“on“an“ëMAnnExpr“ºt¾9ypAÇe“are“forŽ¡‘íºâthe–Gidenš¾9tier“and“annotation“t˜ypšAÇes“resp˜ectiv¾9ely–ÿ:«.‘±ËF“or‘Gexam-Ž¡‘íºâple,‘Fif–<Uthe“tš¾9ypAÇe“of“iden˜tiers“is“ëMIdº,‘Fand“that“of“t˜ypAÇe“expres-Ž¡‘íºâsions–J·ëMTExprº,‘Xthe“t¾9ypšAÇe“of“the“corresp˜onding“Core“expressionŽ¡‘íºâis‘TëM(AnnExpr–¹–Id“TExpr)º.Ž©
‘íºâMost–³Šcases“are“straigh•¾9tforw“ard.‘÷The–³ŠëMAVar“ºterm“represen¾9tsŽ¡‘íºâan–Ûidenš¾9tifer,‘!=whilst“ëMAConstr“ºrepresen˜ts“a“constructor“name.Ž¡‘íºâLiteral–=v‘ÿ|ralues“are“represenš¾9ted“b˜y“ëMALitº,‘G
and“applications“b˜yŽ¡‘íºâëMAApº.‘ÛÕLamš¾9bAÇda–S‚terms“are“represen˜ted“b˜y“ëMALamº,‘zFwhic˜h“can“bindŽ¡‘íºâan–Tarbitrary“n•¾9um“bAÇer–Tof“formal“parameters.Ž¦‘íºâThat›€llea•¾9v“es˜the˜t“w“o˜tric“ky˜ones.‘]·A‘€let/rec˜expression˜isŽ¡‘íºârepresen•¾9ted›c1b“y˜ëMALetº,‘¶¨whic“h˜has˜a˜b•AÇo“olean˜
ag˜indicatingŽ¡‘íºâwhether–û	this“is“a“recursiv¾9e“binding,›Ka“list“of“bindings,˜and“aŽ¡‘íºâmain–Ðexpression“in“whicš¾9h“those“bindings“can“bAÇe“used.‘DEac˜hŽ¡‘íºâbinding–Säis“an“iden¾9tier“paired“with“the“v‘ÿ|ralue“it“is“bAÇoundŽ¡‘íºâto.‘À_Case–ö¤expressions,›.÷denoted“b¾9y“ëMACaseº,˜conš¾9tain“a“switc˜hŽ¡‘íºâexpression,‘“Rand–za“list“of“alternativ•¾9es.‘JÑEac“h›zalternativ“e˜is˜aŽ¡‘íºâtriple–œ±of“constructor“name,‘¾ˆconstructor“argumen¾9ts“and“theŽ¡‘íºâappropriate–›vrigh¾9t-hand“side.‘óÑThe“use“of“nested“pairs“is“moreŽ¡‘íºâcon•¾9v“enien“t–Tfor“cošAÇding“purp˜oses.Ž¦‘íºâAll–š7phases“doš¾9wnstream“of“the“lam˜bAÇda-lifter“exploit“certainŽ¡‘íºâassumptions–-abAÇout“the“form“of“the“program.‘cÆThe“most“im-Ž¡‘íºâpAÇortan¾9t–,§are“that“there“are“no“nested“ëMALetsº,‘[0that“the“programŽ¡‘íºâis–‰fin“depAÇendancy“order,‘¦kand“that“no“iden¾9tier“is“undenedŽ¡‘íºâor–Tm¾9ultiply“dened“in“the“same“scopAÇe.ŽŸyx‘íºâ¹2.4Ž‘G·Compiling–LÎpa¹™rallel“coFfdeŽŸm‘íºâºEv‘ÿ|raluation–ÓÅtransformers“are“suppAÇosedly“exploited“b¾9y“com-Ž¡‘íºâpiling–³ÿmš¾9ultiple“copies“of“eac˜h“function,‘Ûªup“to“one“cop˜y“forŽ¡‘íºâeac•¾9h›·kcon“text˜in˜whic“h˜the˜result˜migh“t˜bAÇe˜demanded.‘µF‘ÿ:«orŽ¡‘íºâeac•¾9h›Ÿcop“y‘ÿ:«,‘qcompile-time˜analysis˜indicates˜ho“w˜m“uc“h˜de-Ž¡‘íºâmand–ŽÙpropagates“to“the“parameters“of“the“function,‘í:andŽ¡‘íºâth•¾9us›sho“w˜m“uc“h˜the˜argumen“ts˜to˜the˜call˜ma“y˜bAÇe˜ev‘ÿ|raluatedŽ¡‘íºâbAÇefore–æéthe“call.‘÷In“this“manner,‘ð2demand“propagation“is“pre-Ž¡‘íºâservš¾9ed–T­as“far“as“this“st˜yle“of“static“analysis“mak˜es“pAÇossible.Ž¡‘íºâOf–žcourse,‘Ú0all“this“is“done“in“pursuit“of“the“o•¾9v“erall‘žgoal:Ž¡‘íºâmaximising–a~aš¾9v‘ÿ|railable“parallelism.‘íAn“equally“impAÇortan˜t“is-Ž¡‘íºâsue,›2«not–,Ídiscussed“here,˜is“hoš¾9w“to“a˜v˜oid“excessiv˜e“ne-grainŽ¡‘íºâparallelism.Ž¦‘íºâAll–q.wš¾9ell“and“go•AÇo“d,‘H#but–q.the“pAÇoten˜tial“for“coAÇde“explo-Ž¡‘íºâsion–x¥renders“a“naivš¾9e“implemen˜tation“impractical.‘FbCon-Ž¡‘íºâsider–šsa“function“delivš¾9ering“a“result“of“the“con˜triv˜ed“t˜ypAÇeŽ¡‘íºâëM(Grok–¹–Int›2Œ(Foo“Int“Int)“(Grok“Int“Int“Int))˜ºdiscussedŽ¡‘íºâin–­îsection“2.2.2.‘æ>Since“the“domain“has“91“pAÇoinš¾9ts,‘Ôit“w˜ouldŽ¡‘íºâappšAÇear–rnecessary“to“compile“90“v¾9ersions“of“the“co˜de,‘™ùomit-Ž¡‘íºâting–çêthe“v¾9ersion“for“no“demand“at“all“on“the“output.‘
MBurn'sŽ¡‘íºâearly–‡wš¾9ork“simply“ignored“the“problem“b˜y“restricting“itselfŽ¡‘íºâto–ó¶lists“of“ëMIntº,‘+Nfor“whic¾9h“at“most“3“copies“of“coAÇde“are“re-Ž¡‘íºâquired.‘7aQuite–Èúwhat“to“do“abšAÇout“complex“t•¾9yp˜es,‘õãwhic“h‘Èúin-Ž¡‘íºâduce–.ÃproAÇduct“domains,‘5or“non-trivial“instan¾9tiations“of“lists,Ž¡‘íºâis–Tnot“clear.Ž¦‘íºâThis–½unsatisfactory“state“of“aairs“can“to“some“exten¾9t“bAÇeŽ¡‘íºâalleviated–·bš¾9y“restricting“ourselv˜es“to“compiling“just“a“subsetŽŽŽ ý€’õºâof–"Üall“the“pAÇossible“vš¾9ersions“of“eac˜h“function.‘EThen,‘f=whenŽ¤
’õºâthe–Ëîoutput“of“a“function“is“demanded“in“a“conš¾9text“for“whic˜hŽ¡’õºâno–ë½vš¾9ersion“has“bAÇeen“compiled,‘ôthe“v˜ersion“used“is“that“com-Ž¡’õºâpiled–kafor“the“greatest“demand“less“than“the“demand“w¾9e“re-Ž¡’õºâquired.‘­«Observš¾9e–E½that“the“c˜hoice“of“alternativ˜e“is“not“neces-Ž¡’õºâsarily›3unique,–`Qbut,“pro•¾9vided˜w“e˜compiled˜in˜a˜fully˜sequen“tialŽ¡’õºâ(that–4Õis,›<¶WHNF‘4Ídemand)“v¾9ersion,˜an“alternativ¾9e“is“at“leastŽ¡’õºâguaranš¾9teed–±9to“exist.‘ðOf“course,‘Ø2some“pAÇoten˜tial“parallelismŽ¡’õºâma•¾9y›˜w“ell˜bAÇe˜lost:‘!Ïsuc“h˜is˜the˜price˜for˜restricting˜the˜coAÇdeŽ¡’õºâexplosion–Tto“a“tolerable“magnitude.Ž©
’õºâThe–FØcenš¾9tral“question,–p%then,“is–FØwhic˜h“v˜ersions“to“compile“coAÇdeŽ¡’õºâfor.‘NoOne–{TpAÇerson“who“has“v•¾9en“tured›{Tin“to˜this˜quagmire˜isŽ¡’õºâMin•¾9tc“hev.‘£F‘ÿ:«or–Çìhis“MSc“dissertation“[Min92Ž‘o™],‘×gMin•¾9tc“hev‘ÇìbuiltŽ¡’õºâa–á@simš¾9ulation“of“a“parallel“graph“reduction“mac˜hine,‘;whic˜hŽ¡’õºâunderstands–áthree“levš¾9els“of“demand:‘6none“at“all,‘	Åw˜eak“headŽ¡’õºânormal–gÊform“demand,‘|gand“full“demand.‘ÑAn“immediate“ad-Ž¡’õºâv‘ÿ|ranš¾9tage–Ùlis“that“these“pAÇoin˜ts“apply“to“all“structured“t˜ypAÇes,Ž¡’õºâincluding–!Ôtuples“and“complex“instanš¾9tiations“of“t˜ypAÇes,‘Rˆand“areŽ¡’õºâthš¾9us–¨¢more“widely“applicable“than“Burn's“sc˜heme.‘Ö[Encour-Ž¡’õºâagingly‘ÿ:«,›ï$ev¾9en–Ôwith“so“few“ev‘ÿ|raluators,˜Min•¾9tc“hev–Ôfound“thatŽ¡’õºâsubstan•¾9tial›¿–amoun“ts˜of˜parallel˜activit“y˜w“ere˜generated,‘мv‘ÿ|ral-Ž¡’õºâidating–·&his“approac•¾9h.‘åRecen“tly–·&it“has“bAÇeen“suggested“thatŽ¡’õºâa–#Ófourth“ev›ÿ|raluator“migh¾9t“bAÇe“protably“included:‘9nev˜aluationŽ¡’õºâof–ýKthe“enš¾9tire“structure“of“a“recursiv˜e“t˜ypAÇe,‘7Ibut“no“ev‘ÿ|ralua-Ž¡’õºâtion–M of“the“compAÇonenš¾9ts.‘ÅSThis“mak˜es“no“sense,›[³of“course,˜inŽ¡’õºâa–YTnon-recursivš¾9e“t˜ypAÇe,–jTor,“alternativ˜ely‘ÿ:«,“one–YTcan“regard“it“asŽ¡’õºâequiv›ÿ|ralen¾9t–Tto“the“WHNF“ev˜aluator,“in“this“case.Ž¦’õºâA‘.öfurther–/Äcomplication“is“what“to“do“abšAÇout“p˜olymor-Ž¡’õºâphic–‡­functions.‘s|W‘ÿ:«e“maš¾9y“compile“three“v˜ersions“of“theŽ¡’õºâëMreverse–ªºfunction,‘Ï:w¾9orking“from“the“ev‘ÿ|raluators“of“the“sim-Ž¡’õºâplest–…Ÿinstance,‘¡±but“then“what“do“wš¾9e“do“giv˜en“an“ev‘ÿ|raluatorŽ¡’õºâëMUU[U[1,0]]–G*ºapplied“to“a“use“of“ëMreverse“ºat“non-base“instanceŽ¡’õºâëM[(Int,–¹–Int)]“->“[(Int,“Int)]º?‘aêSuce–,}it“to“sa¾9y“that“aŽ¡’õºâpšAÇossible–solution“is“only“to“compile“v¾9ersions“of“p˜olymorphicŽ¡’õºâfunctions–ð½based“on“their“ev‘ÿ|raluators“for“simplest“instances,Ž¡’õºâand–Âause“safe“approš¾9ximation“tec˜hniques“based“on“Conc“mapsŽ¡’õºâto–ä`handle“the“non-base“instances.‘See“[HH91Ž‘>],›î*section“5,˜forŽ¡’õºâan–@–in¾9troAÇduction“to“Conc“maps.‘Õ†My“MSc“dissertation“[Sew91Ž‘/]Ž¡’õºâindicates–#­ho¾9w“Conc“maps“are“useful“in“matters“of“pAÇolymor-Ž¡’õºâphism,–Ta“theme“explored“further“in“[Sew93Ž‘/].Ž¦’õºâNoš¾9w,‘ê¹if–àthe“compiler“is“only“going“to“mak˜e“coAÇde“for“a“few“ofŽ¡’õºâall– äthe“pAÇossible“ev‘ÿ|raluators“for“a“function“returning“an“ob‘ƒŽjectŽ¡’õºâof–)bcomplex“t¾9ypšAÇe,‘.fwhat“is“the“p˜oin¾9t“of“doing“strictness“anal-Ž¡’õºâysis–UÛwith“the“full“complemen¾9t“of“ev‘ÿ|raluators?‘ÞAfter“all,‘eüthisŽ¡’õºâamounš¾9ts–×ato“doing“a“detailed“analysis,‘åthen“thro˜wing“a˜w˜a˜yŽ¡’õºâmost–çof“the“detail“in“the“nal“answš¾9er.‘÷)It“w˜ould“certainlyŽ¡’õºâbAÇe›JØm•¾9uc“h˜quic“k“er˜just˜to˜w“ork˜with˜those˜few˜ev‘ÿ|raluators˜w“eŽ¡’õºâare–—\really“inš¾9terested“in.‘òsNev˜ertheless,‘°Ždoing“that“risks“losingŽ¡’õºâin¾9termediate‘ˆ°detail,–¥‡and,“ultimately‘ÿ:«,“parallelism,“comparedŽ¡’õºâwith––/the“expAÇensivš¾9e“approac˜h.‘òBuilding“an“abstract“in˜terpre-Ž¡’õºâtation–gXfor“the“el“cš¾9heapAÇo“approac˜h“migh˜t“also“bAÇe“rather“dif-Ž¡’õºâcult,‘;and–sthe“inš¾9terpreter“w˜ould“ha˜v˜e“to“bAÇe“rewritten“ev˜eryŽ¡’õºâtime–™®the“particular“subset“of“inš¾9teresting“ev‘ÿ|raluators“c˜hanged.Ž¦’õºâA‘‘xnal–‘™inš¾9teresting“ca˜v˜eat“pAÇertains“to“higher-order“functions.Ž¡’õºâAs–6Üexplained“to•¾9w“ards–6Üthe“end“of“section“1.2,‘=it“loAÇoks“dif-Ž¡’õºâcult–Ä4to“exploit“parallelism“in“higher-order“functions“if“w¾9eŽ¡’õºâdo–é†not“w•¾9an“t–é†to“engage“in“complicated“manipulation“of“ev‘ÿ|ral-Ž¡’õºâuation–˜¬transformers“at“run-time.‘¦xOne“can“therefore“rea-Ž¡’õºâsonably–ÈÞargue“that“the“higher-order“remo¾9v‘ÿ|ral“transformationŽ¡’õºâ(rstication)–ždescribAÇed“in“section“5“enhances“parallelism.Ž¡’õºâWhat–&rstication“doAÇes“is“to“disco•¾9v“er–&statically“some“of“theŽ¡’õºâfunctional–Èparameters“passed“to“higher-order“functions,‘ÓäandŽ¡’õºâspAÇecialise–;them“accordingly‘ÿ:«,‘Ltgenerating“rst-order“replace-ŽŽŽŽŽŸ’çjã6ŽŽŒ‹“§ •ºâ ý? £ ý€‘íºâºmenš¾9ts.‘KøThese–Ï×can“then“bAÇe“parallelised“in“the“normal“w˜a˜y‘ÿ:«,Ž¤
‘íºâwithout–8Vhaš¾9ving“to“resort“to“complicated“run-time“mac˜hinery‘ÿ:«.Ž¡‘íºâMa¾9ybšAÇe,–Ô¦then,“this–Äztransformation“should“b˜e“incorp˜orated“asŽ¡‘íºâa–Tmatter“of“course“in¾9to“go•AÇo“d–Tparallelising“compilers.ŽŸ-‘íºâ¹3Ž‘ü”The–LÎabstract“interp¹™retationŽŸ†´‘íºâ3.1Ž‘G·Prelimina¹™riesŽ¤m‘íºâ3.1.1Ž‘úíThe–LÎnotion“of“fo•¹™rw“a“rds–LÎand“backw•¹™a“rdsŽ¡‘íºâºSemanš¾9tic–`êanalyses“of“functional“languages“seem“to“fall“in˜toŽ¤
‘íºât•¾9w“o›Ôvcamps:‘š³forw“ards˜and˜bac“kw“ards.‘YÕT‘ÿ:«o˜see˜the˜in“tuitiv“eŽ¡‘íºâmeaning–Tof“this,“consider“a“function“application:Ž¤ÐO‘ûç¤ëM(f–¹–x“y“z)Ž¡‘íºâºA‘èforwš¾9ard–è‡analysis“generates“information“abAÇout“ëMf“ºwhic˜hŽ¤
‘íºâtells–MÑus“propAÇerties“of“the“application“ëM(f–¹–x“y“z)–MѺif“wš¾9e“kno˜wŽ¡‘íºâthe–¤epropAÇerties“of“the“individual“argumen¾9ts,–È)ëMxº,“ëMy–¤eºand“ëMzº.‘ɤInŽ¡‘íºâother–Ùšw¾9ords,‘
¬the“analysis“propagates“information“óR¼j‘¹		cmti9ëRforwar‡dsŽ¡‘íºâºthrough–ªµfunctions.‘Ü“F‘ÿ:«orw¾9ard“analyses“tend“to“bšAÇe“exp˜ensiv¾9eŽ¡‘íºâbšAÇecause–зthey“ha•¾9v“e–зto“consider“all“p˜ossible“in¾9teractions“b˜e-Ž¡‘íºât•¾9w“een›²¢argumen“ts.‘ô[On˜the˜other˜hand,‘Ùöone˜gets˜a˜v“ery˜de-Ž¡‘íºâtailed–Tpicture“of“what“is“going“on.Ž©
‘íºâA‘ù§bac•¾9kw“ard›ú$analysis,‘sXb“y˜con“trast,‘sXgenerates˜informationŽ¡‘íºâabšAÇout–ÑúëMf“ºwhic¾9h“tells“us“the“prop˜erties“of“the“individual“argu-Ž¡‘íºâmenš¾9ts–HŒëMxº,‘qëMy“ºand“ëMz“ºif“w˜e“kno˜w“some“propAÇert˜y“of“the“applicationŽ¡‘íºâëM(f–¹–x“y“z)º.‘ñThat–
×is,‘Va“bac•¾9kw“ards–
×analysis“propagates“prop-Ž¡‘íºâerties›®4ëRb•‡ackwar“ds˜ºthrough˜functions.‘úBac•¾9kw“ard˜analyses˜ma“yŽ¡‘íºâb•AÇe›2Ÿc¾9heap“er˜to˜do,‘_÷but˜they˜ma•¾9y˜also˜giv“e˜less˜detailed˜results.Ž¦‘íºâNoš¾9w,‘åfor–ÙŒreasons“whic˜h“will“shortly“bAÇecome“apparen˜t,‘åAnnaŽ¡‘íºâdoAÇes–Åua“comš¾9bined“forw˜ard“and“bac˜kw˜ard“analysis.‘ÐThe“prop-Ž¡‘íºâerties–\>whicš¾9h“Anna“propagates“forw˜ards“through“functionsŽ¡‘íºâare–{the“abstract“v‘ÿ|ralues,‘”‡whilst“those“whicš¾9h“
o˜w“bac˜kw˜ardsŽ¡‘íºâare–h
conš¾9texts.‘â®T‘ÿ:«o“set“the“stage,‘Š¶observ˜e“critically“that“ëRAÃŽnna'sŽ¡‘íºâmain–¥±purpš‡ose“is“to“determine“the“b˜ackwar˜ds“b˜ehaviour“ofŽ¡‘íºâthe›sour•‡c“e˜language˜functionsº.‘ÒThe–Èzpresence“of“forw¾9ard“(ab-Ž¡‘íºâstract)–÷ v‘ÿ|ralues“is“a“necessary“evil“whic¾9h“enables“us“to“dealŽ¡‘íºâcleanly–Ú[with“higher-order“functions.‘k†The“discussion“whic¾9hŽ¡‘íºâno•¾9w›sæfollo“ws˜mak“es˜more˜sense˜if˜y“ou˜k“eep˜a˜clear˜notion˜thatŽ¡‘íºâabstract–=xv‘ÿ|ralues“correspAÇond“to“a“forwš¾9ards“
o˜w“of“information,Ž¡‘íºâwhilst–Tconš¾9texts“correspAÇond“to“a“bac˜kw˜ards“
o˜w.ŽŸ5‘íºâ¹3.1.2Ž‘úíA–LÎfundamental“pš¹™roblem“with“backw˜a˜rds“analysisŽŸm‘íºâºBac•¾9kw“ards–Ø.strictness“analysis“wš¾9ould“bAÇe“straigh˜tforw˜ard,Ž¡‘íºâw¾9ere–_˜it“not“for“the“higher-order“nature“of“the“language“underŽ¡‘íºâanalysis.‘pT‘ÿ:«o–Tsee“the“problem,“consider“ëMapplyº:Ž¤ÐO‘ûç¤ëMapply–¹–f“x“=“f“xŽ¡‘íºâºGiv¾9en–hôsome“demand“on“a“use“of“apply‘ÿ:«,›}ÜëM(apply–¹–g“y)º,˜whatŽ¤
‘íºâdemand–[maš¾9y“bAÇe“propagated“to“ëMyº?‘…Without“kno˜wing“ho˜wŽ¡‘íºâëMg–8ºpropagates“demand“to“its“argumenš¾9t,‘1the“only“safe“answ˜erŽ¡‘íºâis›E\none".‘«‡Ho•¾9w“ev“er,‘òkno“wing˜what˜ëMg˜ºis˜implies˜ha“ving˜aŽ¡‘íºâforw•¾9ard›áµ
o“w˜of˜information,‘ìas˜w“ell˜as˜the˜bac“kw“ard˜
o“w˜ofŽ¡‘íºâdemand–Tw¾9e“started“with.Ž¦‘íºâThings–º«loAÇok“grimmer“when“w¾9e“put“functions“inside“dataŽ¡‘íºâstructures,–Tthen“sh“them“out“and“apply“them:ŽŸÐO‘ûç¤ëM1–¹–+“(head“xs“(y+1))ŽŽŽ ý€’õºâºwhere›½åëMxs–¹–::“[Int“->“Int]º.‘$There˜is˜no˜w•¾9a“y˜to˜tell˜whatŽ¤
’õºâdemand–Tcould“bAÇe“propagated“to“ëMyº.Ž©
’õºâThe–ísolution“really“lies“in“building“a“comš¾9bined“bac˜kw˜ardsŽ¡’õºâand–¯×forwš¾9ards“analysis.‘ëøW‘ÿ:«ra˜y“[W‘ÿ:«ra85Ž‘:C]“made“a“start“on“theŽ¡’õºâproblem,‘Yÿbut–LDit“toAÇok“the“w¾9ork“of“Hughes“[Hug87Ž‘ó']“to“gener-Ž¡’õºâalise–O‰W‘ÿ:«raš¾9y's“results“to“the“pAÇoin˜t“of“general“applicabilit˜y‘ÿ:«.‘Ú‚TheŽ¡’õºâresulting–÷˜analysis“is“rather“hard“to“understand,–0)so,“ratherŽ¡’õºâthan–ˆ×attempting“a“head-on“assault,‘¥¸w¾9e“loAÇok“rst“at“under-Ž¡’õºâlying–Tissues,“starting“o“with“some“new“concepts.ŽŸºç’õºâ¹3.2Ž’G·F¹™unction‘LÎcontextsŽŸm’õºâºDealing–-øwith“functions“propAÇerly“means“turning“them“in¾9toŽ¡’õºârst-class–Âlcitizens“for“the“purpAÇoses“of“the“abstract“in¾9ter-Ž¡’õºâpreter.‘‰Section–ž2.2“discussed“the“notion“of“demand“(or“con-Ž¡’õºâtext)–Q/on“a“data“structure.‘ÐW‘ÿ:«e“no¾9w“extend“the“notion“ofŽ¡’õºâcon¾9text–Tto“functions.Ž¦’õºâSince–
Êa“con¾9text“really“denotes“a“demand“for“ev‘ÿ|raluation,‘ætheŽ¡’õºâidea–¶of“a“function“conš¾9text“seems“prett˜y“meaningless:‘]ßafterŽ¡’õºâall,‘¹§hoš¾9w–˜Écan“a“function“bAÇe“ev‘ÿ|raluated?‘¦ÐBut“imagine“w˜e“de-Ž¡’õºâned–¼#a“function“conš¾9text“as“a“pair,‘å×con˜taining“the“abstractŽ¡’õºâv‘ÿ|ralue–RÚof“the“argumenš¾9t,‘b<and“the“con˜text“for“the“result“of“anŽ¡’õºâapplication–Áof“the“function.‘ ·By“making“the“analysis“fullyŽ¡’õºâcurried–v3from“noš¾9w“on,‘Žkw˜e“can“consider“all“functions“as“ha˜v-Ž¡’õºâing–æ;just“one“argumen¾9t.‘½Then,›ï§for“example,˜the“con¾9text“on“aŽ¡’õºâfunction–Tof“t•¾9w“o›Targumen“ts,˜suc“h˜as˜ëMapplyº,˜loAÇoks˜lik“e:Ž©Y ’ç¤ëM(abstract–¹–value“of“first“argument,Ž¡’f(abstract–¹–value“of“second“argument,Ž¡’Íücontext–¹–on“result)Ž¡’ç¤)Ž¦’õºâºSucš¾9h–Qªa“sc˜heme“w˜ould“solv˜e“the“problem“outlined“abAÇo˜v˜e,‘`¿b˜yŽ¡’õºâsupplying–ÌDthe“v‘ÿ|ralue“of“the“rst“parameter,‘Úáallo¾9wing“demandŽ¡’õºâto–úêbAÇe“propagated“on¾9to“the“second“parameter.‘¢This“abstractŽ¡’õºâv›ÿ|ralue–‹aof“the“rst“parameter“is“just“the“relev˜anš¾9t“con˜text“func-Ž¡’õºâtion,›ßžbut–ƒöwhat“of“the“abstract“v‘ÿ|ralue“of“the“second,˜non-Ž¡’õºâfunctional–Ͷparameter?‘‘W‘ÿ:«ell,‘Ü	wš¾9e“are“simply“not“in˜terested“inŽ¡’õºâit,–Tso“wš¾9e“map“it“to“the“1-pAÇoin˜t“domain.ŽŸ
’õºâThe–ÌÝwš¾9orld“no˜w“bšAÇecomes“p˜opulated“bš¾9y“t˜w˜o“spAÇecies“of“v‘ÿ|ralues:Ž¦’äëPŽŽŽ’:âëNCon´Ctexts–‘±º(also“called“bac•¾9kw“ards›‘±v–ÿ|ralues,‘¬ev“aluators˜orŽ¡’:âdemands).‘QŸIn–'what“follo•¾9ws,‘+}w“e–'often“saš¾9y“\con˜text"“orŽ¡’:â\conš¾9text–+œon"“when“it“w˜ould“bAÇe“more“natural“to“sa˜yŽ¡’:â\demand"–àÐor“\demand“on".‘
ïThis“con•¾9v“en“tion–àÐhas“bAÇeenŽ¡’:âadopted–ÑÆbAÇecause“of“a“wish“to“ha•¾9v“e–ÑÆjust“one“term“forŽ¡’:âeac¾9h‘Tconcept.ŽŸûî’:âConš¾9texts–rUare“the“rst“kind“of“abstract“en˜tit˜y“referredŽ¡’:âto–>ôin“section“2.1.‘™QF‘ÿ:«or“non-function“v‘ÿ|ralues,‘‰\they“areŽ¡’:âas–“~discussed“in“section“2.2.‘–íF‘ÿ:«or“function“v‘ÿ|ralues,‘³theyŽ¡’:âare–HÀa“pair“whicš¾9h“w˜e“write“as“ëM(Fnc–¹–a“c)º,‘•šwhere‘HÀëMFncŽ¡’:âºreminds–æ•that“this“is“a“ëNF‘ÿÌuNction‘}·Con´Ctextº,‘åëMa“ºis“theŽ¡’:âabstract–¯3v‘ÿ|ralue“of“the“argumenš¾9t“and“ëMc“ºis“the“con˜text“onŽ¡’:âthe–9
result.‘‡‘Henceforth,‘A÷v‘ÿ|rariables“denoting“con¾9texts“orŽ¡’:âconš¾9text–Tmaps“ha˜v˜e“'c'“as“their“rst“letter.ŽŸ÷Ü’äëPŽŽŽ’:âëNAbstract‘	@v‘ÿh‰alues–£º(also“called“forw¾9ards“v‘ÿ|ralues).‘ö[TheseŽ¡’:âare–›¬the“second“kind“of“abstract“en•¾9tit“y–›¬describAÇed“in“sec-Ž¡’:âtion–ê2.1.‘÷They“are“designed“purely“to“con•¾9v“ey‘êcon“textsŽ¡’:âto–=^anš¾9y“place“in˜v˜olving“a“call“to“an“unkno˜wn“function,Ž¡’:âsucš¾9h–‰ôas“in“the“t˜w˜o“problematic“examples“abAÇo˜v˜e.‘zOTheŽ¡’:âabstract–+v‘ÿ|ralues“of“non-function“ob‘ƒŽjects“are“alw•¾9a“ys‘+irrel-Ž¡’:âev‘ÿ|ran¾9t–¤ãand“are“mappšAÇed“to“a“1-p˜oin¾9t“domain,‘»`whose“sin-Ž¡’:âgle–G°pšAÇoin¾9t“is“denoted“ëM#º,‘pÒfor“the“time“b˜eing.‘×äThe“abstractŽŽŽŽŽŸ’çjã7ŽŽŒ‹·7 •ºâ ý? £ ýõ¦dŸÂlΑíºâŸ¾S4‰fföÌ̤ÿþ•ÌÍŸwÙš„~Ù˜ffŸ·32‘8ŸÚŒÍ‰ff†C,¡“¤„
ff‘fg„
ff‘33ŸüÿþºDening‘Tequation‘"V¡„
ffŽ‘p·Disassem¾9bles–Ta“...‘"½¤Ÿ„
ffŽ’ß•
proAÇducing–Tthe“...‘a˜Ÿ„
ff‘fg„
ffŽŽ©fh‰ff†C,¡“Ÿ„
ff‘fg„
ff‘hæ„
ffŽ’ÙûtŸ„
ffŽ’„C,Ÿ„
ff‘fg„
ffŽŽ¤
“¤„
ff‘fg„
ff‘33ŸüÿþëMFncA›	s,(Fnc–¹–a“c)˜=“a‘33¡„
ffŽ‘p·ºfunctional‘Tcon¾9text‘ @OŸ„
ffŽ’ß•
abstract–Tv‘ÿ|ralue“of“the“argumen¾9t‘'õ¡Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff‘33ŸüÿþëMFncC›	s,(Fnc–¹–a“c)˜=“c‘33¡„
ffŽ‘p·ºfunctional‘Tcon¾9text‘ @OŸ„
ffŽ’ß•
con¾9text–Ton“the“result‘PRŸ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff›33ŸüÿþëMFvalA–¹–(Fval“c“a)“=“a˜¡„
ffŽ‘p·ºfunctional–Tabstract“v‘ÿ|ralue‘33Ÿ„
ffŽ’ß•
abstract–Tv‘ÿ|ralue“map:‘pargumen¾9t“to“result‘33Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff›33ŸüÿþëMFvalC–¹–(Fval“c“a)“=“c˜¡„
ffŽ‘p·ºfunctional–Tabstract“v‘ÿ|ralue‘33Ÿ„
ffŽ’ß•
conš¾9text–Tmap:‘presult“to“argumen˜t‘ @OŸ„
ff‘fg„
ffŽŽ¡“Ÿ„
ff‘fg„
ff‘hæ„
ffŽ’ÙûtŸ„
ffŽ’„C,Ÿ„
ff‘fg„
ffŽŽ¦‰ff†C,ŽŽŽŸ;ÌÌ’˜TT‘ÿ:«able–T1:‘pSelector“functions“for“functional“en¾9titiesŽŽŸ
Ž’öff„~Ù˜ffŽŽŸx@‰fföÌÌŽŽŽŽ 
Yœ þ¦d‘:âv›ÿ|ralue–2&of“a“function-v˜alued“ob‘ƒŽject“is“also“a“pair“(butŽ¤
‘:âquite–7îunrelated“to“ëMFnc“ºpairs),‘À”written“ëM(Fval–¹–c“a)º,Ž¡‘:âwith–J¡ëMFval“ºreminding“us“this“is“a“ëNF‘ÿÌunctional‘£jabstractŽ¡‘:âV‘þÑALueº.‘ë=The›ît•¾9w“o˜compAÇonen“ts˜are˜bAÇoth˜maps.‘ë=TheŽ¡‘:ârst›v–compAÇonen¾9t,–ŽæëMcº,“maps˜the˜con¾9text˜on˜the˜functionŽ¡‘:âto–7;conš¾9text“on“the“argumen˜t,‘c§whilst“ëMa“ºmaps“the“abstractŽ¡‘:âv›ÿ|ralue–5ëof“the“argumen¾9t“to“the“abstract“v˜alue“of“the“re-Ž¡‘:âsult.‘É
V‘ÿ:«ariables–NÝdenoting“abstract“v‘ÿ|ralues“or“abstractŽ¡‘:âv‘ÿ|ralue–Tmaps“ha•¾9v“e–T'a'“as“their“rst“letter.ŽŸ‹‘íºâNotice–nhoš¾9w“the“t˜w˜o“kinds“of“v‘ÿ|ralues“are“m˜utually“recursiv˜e.Ž¡‘íºâThe›’Œo•¾9v“erall˜output˜of˜the˜abstract˜in“terpreter˜is˜one˜ab-Ž¡‘íºâstract–B}v›ÿ|ralue“pAÇer“Core“function.‘£ëEac¾9h“abstract“v˜alue“con-Ž¡‘íºâtains–®®enough“information“to“propagate“demand“from“theŽ¡‘íºâo•¾9v“erall–½ýresult“to“eacš¾9h“of“the“argumen˜ts,‘Ïuev˜en“in“the“presenceŽ¡‘íºâof–hÉfunctional“parameters.‘ÎThese“concepts“are“confusing,‘}¦soŽ¡‘íºâsome–>2examples“are“in“order.‘ÔºFirst,‘i9dene“four“selectors“ëMFncAº,Ž¡‘íºâëMFncCº,–Ø„ëMFvalA›Øtºand“ëMFvalC˜ºto“disassem¾9ble“ëMFncºs“and“ëMFvalºs,‘ä­withŽ¡‘íºâthe–¯œbAÇehaš¾9viour“sho˜wn“in“T›ÿ:«able“1.‘úˆHopAÇefully˜,‘Ãôtheir“names“willŽ¡‘íºâserv¾9e–Tas“a“reminder“of“their“meaning.Ž©
‘íºâLet's–	©‰start“with“the“simplest“function“imaginable:Ž¡‘íºâëMid–¹–::“Int“->“Intº.‘ðThe–
Óonly“remotely“inš¾9teresting“thing“w˜eŽ¡‘íºâcan–“îsaš¾9y“abAÇout“ëMid“ºis“that“it“simply“propagates“the“con˜text“onŽ¡‘íºâits–4£result“to“the“conš¾9text“on“its“argumen˜t.‘z]So,‘<wsuppAÇosing“w˜eŽ¡‘íºânoš¾9w–Xwrite“do˜wn“a“mapping“from“the“con˜text“on“the“resultŽ¡‘íºâto–Tthe“conš¾9text“on“the“argumen˜t,“w˜e“get:Ž¤y®‘ûç¤ëM(\c–¹–->“c)Ž¡‘íºâºLet's–]ÃbAÇe“clear“what“this“is.‘õ½It's“ëRnot“ºa“con¾9text,‘oßand“it's“alsoŽ¤
‘íºâëRnot–Ë{ºan“abstract“v‘ÿ|ralue.‘ÒIt's“a“map“from“conš¾9texts“to“con˜texts.Ž¦‘íºâBut–×that's“not“go•AÇo“d–×enough.‘aúW‘ÿ:«e“said“earlier“that“AnnaŽ¡‘íºâprošAÇduces–êone“abstract“v‘ÿ|ralue“p˜er“Core“function.‘32So“what“doŽ¡‘íºâw¾9e–«(proAÇduce“for“ëMidº?‘ÝíF‘ÿ:«or“a“start,›Ðsince“ëMid“ºis“a“function,˜w¾9eŽ¡‘íºâmš¾9ust–²Wget“a“functional“abstract“v‘ÿ|ralue:‘êñan“ëMFval“ºterm.‘ûqIt“m˜ustŽ¡‘íºâloAÇok‘Tlik¾9e:Ž©‹‘ûç¤ëMid–¹–=“Fval“context_mapŽ¡‘+'€abstract_value_mapŽ¦‘íºâºNo•¾9w,‘Éthe›¶con“text˜map,‘Éas˜w“e˜just˜men“tioned,‘Émaps˜the˜con-Ž¡‘íºâtext–]ªon“ëMid“ºto“the“conš¾9text“on“ëMidº's“argumen˜t.‘ß7And“the“con˜textŽ¡‘íºâon–÷±ëMidº,›ýžsince“ëMid“ºis“a“function,˜mš¾9ust“bAÇe“a“function“con˜text,‘ýžofŽ¡‘íºâthe–øÜform“ëM(Fnc–¹–a“c)º,‘1¾where–øÜëMc“ºis“the“bit“w¾9e're“really“after.Ž¡‘íºâThis–&givš¾9es“a“con˜text“map“of“ëM(\c–¹–->“FncC“c)º,‘Úso–&w˜e'v˜e“no˜wŽ¡‘íºâgot:Ž¦‘ûç¤ëMid–¹–=“Fval“(\c“->“FncC“c)Ž¡‘+'€abstract_value_mapŽŽŽ þ¦d’õºâºWhat–¸ñof“the“abstract“v‘ÿ|ralue“map?‘HIt“tells“us“what“the“ab-Ž¤
’õºâstract–Yv›ÿ|ralue“of“ëMidº's“result“is“giv¾9en“the“abstract“v˜alue“of“ëMidº'sŽ¡’õºâargumen¾9t.‘Ý°But,›;/for–ithis“instance“of“ëMidº,˜the“result“t¾9ypAÇe“isŽ¡’õºâëMIntº.‘e¦All–ƒnon-function“tš¾9ypAÇes“ha˜v˜e“a“correspAÇonding“abstractŽ¡’õºâv‘ÿ|ralue,–õŸdenoted›í²ëM#º,“in˜a˜1-pAÇoin•¾9t˜domain.‘:So˜w“e˜don't˜actuallyŽ¡’õºâcare–Þ@what“the“abstract“v‘ÿ|ralue“of“ëMid“ºis“{“it“can“only“bAÇe“ëM#“ºan¾9y-Ž¡’õºâw•¾9a“y‘ÿ:«.‘oThat–·Tmeans,‘ßÔafter“installing“the“abstract“v‘ÿ|ralue“map,Ž¡’õºâwš¾9e–YŸcould“write“either“of“the“follo˜wing,‘j²although“the“secondŽ¡’õºâis–Ta“little“clearer:Ž©ÐO’ç¤ëMid–¹–=“Fval“(\c“->“FncC“c)Ž¡’3'€(\a–¹–->“a)Ž¡¡’ç¤id–¹–=“Fval“(\c“->“FncC“c)Ž¡’3'€(\a–¹–->“#)Ž¦’õºâºIf–&ây¾9ou“are“confused,‘kEgo“no“further!‘QIt“is“bAÇetter“to“returnŽ¡’õºâto–t€the“start“of“this“section,‘ŒKconsider“again“the“meanings“ofŽ¡’õºâconš¾9texts–6Øand“abstract“v‘ÿ|ralues,‘?9and“iterate“un˜til“the“exampleŽ¡’õºâmak¾9es‘Tsense.ŽŸ
’õºâMoš¾9ving–Ton“to“ëM(+)–¹–::“Int“->“Int“->“Int‘Tºgiv˜es:Ž¦’ç¤ëM(+)–¹–=“Fval“(\c1“->“FncC“(FncC“c1))Ž¡’7á(\a1–¹–->“Fval“(\c2“->“FncC“c2)Ž¡’uM´(\a2–¹–->“#))Ž¦’õºâºThis–Õ¨time“currying“comes“inš¾9to“pla˜y‘ÿ:«.‘]kThat's“wh˜y“the“termŽ¡’õºâwhicš¾9h–Qƒmaps“the“abstract“v‘ÿ|ralue“of“the“rst“argumen˜t“to“theŽ¡’õºâabstract–èv‘ÿ|ralue“of“the“result“returns“a“ëMFval“ºterm:‘Ââthe“\re-Ž¡’õºâsult"–oØhere“has“t¾9ypAÇe“ëMInt–¹–->“Intº.‘+ûClearly‘ÿ:«,‘†yëM(+)–oغsimply“prop-Ž¡’õºâagates–5conš¾9text“on“the“o˜v˜erall“result“to“bAÇoth“argumen˜ts,Ž¡’õºâwhicš¾9h–‹§is“wh˜y“the“con˜text“maps“for“the“t˜w˜o“argumen˜tsŽ¡’õºâare›%+ëM(\c1–¹–->“FncC“(FncC“c1))˜ºand˜ëM(\c2“->“FncC“c2)º.‘KõIfŽ¡’õºâthis–seems“a“little“m¾9ysterious,‘*íbšAÇear“in“mind“that“b˜othŽ¡’õºâëM(FncC–¹–(FncC“c1))–Xºand“ëM(FncC‘¹–c2)“ºrefer“to“the“con¾9text“onŽ¡’õºâthe–Ofnal“result.‘
ʧThat's“bAÇecause“ëMc1“ºbinds“to“a“con¾9textŽ¡’õºâin›M¬ëMInt–¹–->“Int“->“Intº,‘ÛÁwhic¾9h˜is˜necessarily˜of˜the˜formŽ¡’õºâëM(Fnc–¹–#“(Fnc“#“cc))–ܺwhere“ëMcc“ºis“the“con¾9text“on“the“nalŽ¡’õºâresult.‘òeSimilarly‘ÿ:«,‘°nëMc2–—4ºis“a“conš¾9text“of“t˜ypAÇe“ëMInt–¹–->“Intº,‘°nha˜vingŽ¡’õºâthe–~;form“ëM(Fnc–¹–#“cc)–~;ºwhere“ëMcc“ºis“again“the“con¾9text“on“theŽ¡’õºânal‘Tresult.ŽŸ
’õºâNoš¾9w–Û?for“something“altogether“more“adv˜en˜turous:‘ÿfthe“famil-Ž¡’õºâiar–ªxëMapply“ºfunction,‘ÏÁat“t¾9ypAÇe“ëM(Int–¹–->“Int)“->“Int“->“Intº.Ž¡’õºâThis–ÔÈexample“is“easier“to“follo¾9w“if“one“bAÇears“in“mind“thatŽ¡’õºâëM(apply–¹–f“x)–íºreduces“immediately“to“ëM(f‘¹–x)º,‘“so“anš¾9y“con˜textŽ¡’õºâapplied–öÖto“the“former“expression“also“applies“directly“to“theŽ¡’õºâlatter.‘ZWhat–á¢the“rather“formidable“term“bšAÇelo¾9w“do˜es“is“toŽ¡’õºâroute–[†the“con¾9text“from“the“result“of“calling“ëMapply“ºto“theŽ¡’õºâresult–Tof“calling“the“higher-order“parameter.ŽŽŽŽŽŽŸ’çjã8ŽŽŒ‹	Ör •ºâ ý? £ ý€‘ûç¤ëMapply–¹–=“Fval“(\c1“->“Fnc“(FncA“(FncC“c1))Ž¤
‘rJ(FncC–¹–(FncC“c1)))Ž¡‘9TB(\a1–¹–->“Fval“(\c2“->“(FvalC“a1)Ž¡’œ(Fnc–¹–(FncA“c2)Ž¡’´-~(FncC‘¹–c2))Ž¡‘vÀà(\a2–¹–->“(FvalA“a1)“a2))ŽŸj‘íºâºFirst–Hfof“all,‘Õ*consider“what“the“function“con¾9text“ëMc1“ºwillŽ¡‘íºâget–3bšAÇound“to“m¾9ust“lo˜ok“lik¾9e:‘-ëM(Fnc›¹–a_ho“(Fnc˜#˜c_final))Ž¡‘íºâºwhere–‚¹ëMa_ho“ºus“the“abstract“(or“forw¾9ard)“v‘ÿ|ralue“of“the“func-Ž¡‘íºâtional–º˜parameter“and“ëMc_final“ºis“the“con¾9text“on“the“resultŽ¡‘íºâof–Èapplying“this“functional“parameter“to“something.‘4ÏNo¾9w,Ž¡‘íºâterm‘NëM(\c1–¹–->“Fnc“(FncA“(FncC“c1))“(FncC“(FncC“c1)))Ž¡‘íºâºmaps–ì;conš¾9text“on“ëMapply“ºto“con˜text“on“the“rst“parameter.Ž¡‘íºâAs–˜ythis“is“a“functional“parameter,‘¹Bit“mak¾9es“sense“that“thisŽ¡‘íºâexpression–4is“built“from“a“ëMFncº.‘ÑXSo“just“what“con¾9text“is“propa-Ž¡‘íºâgated–Ðnto“the“functional“parameter?‘yW‘ÿ:«ell,‘Þ6the“abstract“v‘ÿ|ralueŽ¡‘íºâm¾9ust–åîbAÇe“the“same“as“the“abstract“v‘ÿ|ralue“of“the“second“pa-Ž¡‘íºârameter–¬½to“ëMapplyº,‘Ò—and“this“v‘ÿ|ralue“(whicš¾9h“m˜ust“bAÇe“ëM#º)“is“ex-Ž¡‘íºâtracted–´qb¾9y“the“term“ëM(FncA–¹–(FncC“c1))–´qºSimilarly‘ÿ:«,‘Ü8the“con-Ž¡‘íºâtext–sson“the“result“of“the“functional“parameter“m¾9ust“bAÇe“theŽ¡‘íºâsame–øsas“the“conš¾9text“on“the“o˜v˜erall“result“of“ëMapplyº,‘þ9giv˜en“b˜yŽ¡‘íºâëM(FncC–¹–(FncC“c1))º.Ž©
‘íºâEvš¾9erything–”else“is“easier“to“follo˜w.‘Ç…V‘ÿ:«ariable“ëMa1“ºwill“get“bAÇoundŽ¡‘íºâto– cthe“abstract“v‘ÿ|ralue“of“the“functional“parameter,‘'whic¾9hŽ¡‘íºâm¾9ust–"bAÇe“a“ëMFval“ºterm.‘
So“ëM(FvalC‘¹–a1)“ºreturns“the“map“usedŽ¡‘íºâbš¾9y–Çdthe“functional“parameter“to“translate“con˜text“on“itself“toŽ¡‘íºâconš¾9text–½on“its“rst“argumen˜t.‘¬The“map“is“applied“to“theŽ¡‘íºâsame–ÜYfunction“conš¾9text“as“w˜as“built“in“the“preceding“para-Ž¡‘íºâgraph,‘;„except–3áthat“references“to“ëM(FncC‘¹–c1)“ºare“replaced“b¾9yŽ¡‘íºâëMc2º,–Twhic¾9h“is“the“same“thing.Ž¦‘íºâFinally‘ÿ:«,‘ëÆthe–Àâabstract“v‘ÿ|ralue“of“the“result“is“givš¾9en“b˜y“apply-Ž¡‘íºâing–æJthe“abstract“v‘ÿ|ralue“map“of“the“functional“parameter,Ž¡‘íºâëM(FvalA‘¹–a1)º,‘–to–¦the“abstract“v‘ÿ|ralue“of“the“second“parameter,Ž¡‘íºâëMa2º.Ž¦‘íºâTw•¾9o›Aimpro“v“emen“ts˜are˜pAÇossible.‘ŸÎFirstly‘ÿ:«,‘Lthe˜abstract˜v‘ÿ|ralueŽ¡‘íºâof–+the“result“mš¾9ust“simply“bAÇe“ëM#º,‘0~since“the“result“t˜ypAÇe“is“ëMIntº.Ž¡‘íºâSecondly‘ÿ:«,‘examination–C~of“the“denition“of“ëMFncA‘C0ºand“ëMFncCŽ¡‘íºâºshoš¾9ws–u'that“ëM(Fnc–¹–(FncA“c)“(FncC“c))–u'ºis“equiv‘ÿ|ralen˜t“simplyŽ¡‘íºâto–TëMcº.‘pThe“impro•¾9v“ed›Tv“ersion˜is:Ž©j‘ûç¤ëMapply–¹–=“Fval“(\c1“->“FncC“c1)Ž¡‘9TB(\a1–¹–->“Fval“(\c2“->“(FvalC“a1)“c2)Ž¡‘vÀà(\a2–¹–->“#))Ž¦‘íºâºThe–ƒmec¾9hanism“for“dealing“with“functions“and“applicationsŽ¡‘íºâis–jLthe“hardest“part“of“the“abstract“in¾9terpreter“to“understand.Ž¡‘íºâA‘1õlittle–2/time“spAÇen¾9t“making“sense“of“this“last“example“is“a“wiseŽ¡‘íºâin•¾9v“estmen“t.ŽŸ
‘íºâWhš¾9y–Gšis“it“necessary“to“propagate“demand“in˜to“functionalŽ¡‘íºâparameters?‘pW‘ÿ:«ell,‘Tconsider:Ž¦‘ûç¤ëMadd1–¹–x“=“apply“(+“x)“1Ž¦‘íºâºIf–ë5demand“isn't“propagated“in¾9to“ëMapplyº's“functional“parame-Ž¡‘íºâter,‘$there–Xwill“bAÇe“no“demand“on“term“ëM(+‘¹–x)“ºand“none“on“ëMxº,Ž¡‘íºâgiving–[the“impression“that“ëMadd1“ºis“not“strict,‘ when“really“itŽ¡‘íºâis.ŽŸ
e‘íºâ¹3.3Ž‘G·Mo¹™re–LÎabFfout“abstract“valuesŽŸm‘íºâºAll–:onon-function“expressions“yield“an“abstract“v‘ÿ|ralue“in“a“unitŽ¡‘íºâdomain.‘Ï3Ho•¾9w“ev“er,–Ê{v‘ÿ|ralue›¦@ëM#º,“used˜in˜the˜examples˜abAÇo•¾9v“e,‘Ê{isŽŽŽ ý€’õºâtoAÇo–Ëindiscriminating.‘=—The“Hask¾9ell“declaration“for“abstractŽ¤
’õºâv‘ÿ|ralues–TloAÇoks“(almost)“lik¾9e“this:Ž©ÐO’ç¤ëMdata‘¹–AbsValŽ¡’f=‘¹–ANonRec‘	s,[AbsVal]Ž¡’f|‘¹–ARec‘Ÿî[AbsVal]Ž¡’f|–¹–Fval‘ŸîContext“AbsValŽ¡¡’f|‘¹–AbsVar‘,ÂIdŽ¡’f|–¹–AbsLam‘,ÂId“AbsValŽ¡’f|–¹–AbsAp‘æXAbsVal“AbsValŽ¡¡’f|‘¹–FncA‘ŸîContextŽ¡’f|‘¹–FvalA‘æXAbsValŽ¡’f|–¹–SelA‘ŸîInt“AbsValŽ¡’f|‘¹–AMeet‘æX[AbsVal]Ž¦’õºâºThe–¢ëMARec“ºand“ëMANonRec“ºterms“dene“abstract“v‘ÿ|raluesŽ¡’õºâfor–ø3recursivš¾9e“and“non-recursiv˜e“t˜yp•AÇes,‘°êresp“ectiv˜ely‘ÿ:«.‘Å
InŽ¡’õºâbšAÇoth–¬cases,‘¾the“asso˜ciated“list“of“ëMAbsValºs“are“the“ab-Ž¡’õºâstract–v‘ÿ|ralues“of“the“parameters“of“the“t¾9ypAÇe.‘èF‘ÿ:«or“ex-Ž¡’õºâample,‘|þa–Üterm“of“t¾9ypAÇe“ëM[(Int,‘¹–Int)]“ºhas“abstract“v‘ÿ|ralueŽ¡’õºâëM(Rec–¹–[NonRec“[NonRec“[],“NonRec“[]]])º,‘†½giv¾9en–pthat“ëMIntŽ¡’õºâºis–NFtreated“as“an“enš¾9umeration“and“th˜us“maps“to“ëM(NonRec‘¹–[])º.Ž¡’õºâIt–
Ôis“impAÇortanš¾9t“to“realise“that“this“v‘ÿ|ralue“is“still“unitary‘ÿ:«,‘Tlik˜eŽ¡’õºâëM#º,‘”Êbut–Hhas“the“added“adv‘ÿ|ran¾9tage“that“it“can“bAÇe“disassem-Ž¡’õºâbled–“~to“revš¾9eal“its“unitary“sub•AÇcomp“onen˜ts,‘­vas–“~necessitated“b˜yŽ¡’õºâthe–µƒabstract“inš¾9terpretation“of“ëMcase“ºstatemen˜ts.‘ü€ConstructorŽ¡’õºâëMSelA–Tºis“used“for“this,“with“meaning:Ž©ÐO’ç¤ëMSelA–¹–n“(ARec‘æX[a1“...“an“...“ak])‘	s,=“anŽ¡’ç¤SelA–¹–n“(ANonRec“[a1“...“an“...“ak])‘	s,=“anŽ¦’õºâFvalº,‘pµëMFncA–^[ºand›^nëMFvalA“ºw•¾9ere˜in“troAÇduced˜in˜the˜previous˜sec-Ž¡’õºâtion.‘ÎÒëMAbsVarº,‘[
ëMAbsLam–,{ºand“ëMAbsAp“ºallo¾9w“references“to“abstract-Ž¡’õºâv–ÿ|ralued›°qv“ariables,‘8and˜for˜the˜creation˜and˜application˜ofŽ¡’õºâabstract-v‘ÿ|ralued–g9mappings.‘Observš¾9e“that“w˜e“often“omitŽ¡’õºâëMAbsVar–îRºand“ëMAbsApº,›$’when“the“meaning“is“ob¾9vious,˜and“ab-Ž¡’õºâbreviate›TëM(AbsLam–¹–a“e)˜ºto˜ëM(\a“->“e)º.ŽŸ
’õºâConsider‘TagainŽ¤ÐO’ç¤ëM1–¹–+“(head“xs“(y+1))Ž¡’õºâºwhere›tÕëMxs–¹–::“[Int“->“Int]º.‘:ôW‘ÿ:«e˜expAÇect˜ëMxs˜ºto˜ha•¾9v“e˜bAÇeenŽ¤
’õºâbAÇound–Ô*to“an“abstract“v‘ÿ|ralue“whic¾9h“can“supply“a“sensibleŽ¡’õºâconš¾9text-mapping–:$function.‘ŠàOnce“again,‘CXw˜e“c˜haracterise“theŽ¡’õºâlist–F0bš¾9y“the“least“elemen˜t,‘ožthis“time“the“least“con˜text“function,Ž¡’õºâin–Tit.‘pSo,“suppAÇosingŽ¤ÐO’ç¤ëMxs–¹–=“[id,“id]“where“id“x“=“xŽ¡’õºâºthe–Tabstract“v‘ÿ|ralue“of“ëMxs“ºwill“bAÇe:Ž¡’ç¤ëMARec–¹–[‘	s,Fval“(\c1“->“FncC“c1)Ž©
’ATB(\a1–¹–->“ANonRec“[])‘	s,]Ž¡’õºâºThe–ìÅeect“of“the“ëMhead“ºfunction“is“to“wrap“ëMSelA‘¹–1“ºaroundŽ¦’õºâthis–ƒöterm,‘ŸŸmaking“the“abstract“v›ÿ|ralue“of“ëMid“ºa¾9v˜ailable“whereŽ¦’õºâit–Tis“needed.‘pBut,“noš¾9w,“if“ëMxs“ºw˜ere“dened“asŽ¡’ç¤ëMxs–¹–=“[id,“const]“where“id“x‘Ÿî=“xŽ¦’p”const–¹–x‘	s,=“42ŽŽŽŽŽŸ’çjãº9ŽŽŒ‹
óÆ •ºâ ý? £ ý€‘íºâºwš¾9e–²need“to“bAÇe“more“cautious.‘òµSince“the“abstract“in˜terpre-Ž¤
‘íºâtation–ybcannot“distinguish“items“in“lists,‘Òewš¾9e“m˜ust“arrangeŽ¡‘íºâthat–´öthe“function“whicš¾9h“emerges“from“the“list“represen˜ts“theŽ¡‘íºâw•¾9eak“er–b˜ev‘ÿ|raluator:‘¶ùëMconstº.‘=That“requires“the“list“as“a“wholeŽ¡‘íºâto›Tha•¾9v“e˜v‘ÿ|ralue:Ž©Zû‘ûç¤ëMARec–¹–[‘	s,Fval“(\c1“->“_)Ž¡‘9TB(\a1–¹–->“ANonRec“[])‘	s,]Ž¦‘íºâºThe–2upshot“of“all“this“is“that“the“abstract“v‘ÿ|ralue“of“a“listŽ¡‘íºâconš¾9taining–©functions“is“c˜haracterised“b˜y“the“least“functionŽ¡‘íºâin–ʾthe“list,‘øwith“the“principle“extending“analogously“to“allŽ¡‘íºâother–„8structures.‘iIn“order“to“carry“that“out,‘ßða“greatest-Ž¡‘íºâlo•¾9w“er-b•AÇound›¯‘op“eration˜is˜needed˜for˜abstract˜v‘ÿ|ralues.‘ú„This˜isŽ¡‘íºâwhat–Tthe“ëMAMeet“ºterm“is“for.ŽŸìÑíºâ¹3.4Ž‘G·Mo¹™re–LÎabFfout“contextsŽŸm‘íºâºThis–æ.is“a“go•AÇo“d›æ.p“oin•¾9t˜at˜whic“h˜to˜wheel˜in˜the˜Hask“ell˜decla-Ž¡‘íºâration–0&for“conš¾9texts.‘læUnfortunately‘ÿ:«,‘6Ûit“is“ev˜en“more“cum˜bAÇer-Ž¡‘íºâsome–Tthan“the“ëMAbsVal“ºdeclaration.‘pNev¾9ertheless:Ž¦‘ûç¤ëMdata‘¹–ContextŽ¡‘
f=‘¹–Stop1Ž¡‘
f|‘¹–Up1‘Y„[Context]Ž¡‘
f|‘¹–Stop2Ž¡‘
f|‘¹–Up2Ž¡‘
f|‘¹–UpUp2‘æX[Context]Ž¡‘
f|–¹–Fnc‘Y„AbsVal“ContextŽ¡¡‘
f|‘¹–FncC‘ŸîContextŽ¡‘
f|‘¹–FvalC‘æXAbsValŽ¡¡‘
f|‘¹–CJoin‘æX[Context]Ž¡‘
f|‘¹–CMeet‘æX[Context]Ž¡¡‘
f|‘¹–CtxVar‘,ÂIdŽ¡‘
f|–¹–CtxLam‘,ÂId“ContextŽ¡‘
f|–¹–CtxAp‘æXContext“ContextŽ¡¡‘
f|–¹–SelU‘ŸîInt“ContextŽ¡‘
f|–¹–SelUU‘æXInt“ContextŽ¡‘
f|–¹–CaseU‘æXContext“Context“ContextŽ¡‘
f|–¹–CaseUU‘,ÂContext“Context“Context“ContextŽ¡¡‘
f|‘¹–DefU‘ŸîContextŽ¡‘
f|‘¹–DefUU‘æXContextŽ¦‘íºâºThe–Srst“six“are“for“building“literal“con¾9texts.‘Õ«ëMStop1“ºandŽ¡‘íºâëMUp1–yOºpšAÇertain“to“p˜oin¾9ts“in“ëMLift–¹–(D1“x“...“x“Dn)º,‘˜„with‘yOëMStop1Ž¡‘íºâºrepresen¾9ting–§the“bšAÇottom“p˜oin¾9t“ëM_º,‘Y|and“ëM(Up1–¹–[x1“...“xn])Ž¡‘íºâºrepresenš¾9ting–the“pAÇoin˜t“ëMU[x1–¹–...“xn]º.‘Similarly‘ÿ:«,–TëMStop2º,“ëMUp2Ž¡‘íºâºand›$uëM(UpUp2–¹–[x1“...“xn])˜ºrepresen•¾9t˜the˜pAÇoin“ts˜ëM_º,‘h=ëMU_˜ºandŽ¡‘íºâëMUU[x1–¹–...“xn]–&ºin“the“domain“ëMLift2–¹–(D1“x“...“x“Dn)º.‘ɶëMFncŽ¡‘íºâºis–Šeused“for“building“function-v‘ÿ|ralued“con¾9texts,‘¦/as“discussed“inŽ¡‘íºâsection–Hj3.2.‘µ³Finally‘ÿ:«,‘U0ëMDefU›H]ºand“ëMDefUU˜ºexist“to“help“the“termŽ¡‘íºârewriting–Tsystem,“as“describAÇed“in“section“4.4.Ž©
‘íºâëMFncC–(åºand›)!ëMFvalC“ºw¾9ere˜also˜discussed˜in˜section˜3.2.‘Í´ëMCJoin˜ºandŽ¡‘íºâëMCMeet–]=ºunsurprisingly“denote“the“least“uppAÇer“and“greatestŽ¡‘íºâlo•¾9w“er–TbšAÇounds“of“their“resp˜ectivš¾9e“argumen˜t“lists.Ž¦‘íºâëMCtxVarº,‘ÙæëMCtxLam–L0ºand“ëMCtxAp“ºare“exact“equiv‘ÿ|ralen¾9ts“to“theŽ¡‘íºâëMAbsVarº,‘"åëMAbsLam–ìûºand“ëMAbsAp“ºdiscussed“in“section“3.3.‘£fTheyŽ¡‘íºâproš¾9vide–ÿ¤a“w˜a˜y“to“reference“con˜text-v›ÿ|ralued“v˜ariables,‘úand“al-Ž¡‘íºâloš¾9w–8the“creation“and“application“of“con˜text-v‘ÿ|ralued“maps.ŽŽŽ ý€’õºâOnce–¡šagain,‘«note“that“w¾9e“often“omit“ëMCtxVar“ºand“ëMCtxApº,Ž¤
’õºâwhen–³the“meaning“is“ob¾9vious,‘ƺand“abbreviate“ëM(CtxLam–¹–c“e)Ž¡’õºâºto‘TëM(\c–¹–->“e)º.ŽŸ
’õºâF‘ÿ:«ar–ù%and“a•¾9w“a“y–ù%the“most“in¾9teresting“constructs“are“the“lastŽ¡’õºâfour.‘¢yëMCaseU–Aöºand›BëMCaseUU“ºallo•¾9w˜partial˜disassem“bly˜of˜v‘ÿ|raluesŽ¡’õºâin›6mëMLift–¹–(D1“x“...“x“Dn)˜ºand˜ëMLift2“(D1“x“...“x“Dn)˜ºre-Ž¡’õºâspAÇectiv¾9ely‘ÿ:«,‘…fin–;Éthe“manner“discussed“in“section“2.2.3.‘ÎTheŽ¡’õºâexact–Tseman¾9tics“are:Ž©´º’ç¤ëMCaseU–¹–Stop1‘,Âx“y‘	s,=“xŽ¡’ç¤CaseU–¹–(Up1“_)“x“y‘	s,=“yŽ¡¡’ç¤CaseUU–¹–Stop2‘Ÿîx“y“z‘	s,=“xŽ¡’ç¤CaseUU–¹–Up2‘!x“y“z‘	s,=“yŽ¡’ç¤CaseUU–¹–(UpUp2“_)“x“y“z‘	s,=“zŽ¦’õºâºNote–üdthat“the“switc¾9h“v‘ÿ|ralues“are“restricted“to“bAÇeing“in“do-Ž¡’õºâmains›½ëMLift–¹–(D1“x“...“x“Dn)˜ºand˜ëMLift2“(D1“x“...“x“Dn)Ž¡’õºâºrespAÇectiv•¾9ely‘ÿ:«.‘Switc“h–¾…v‘ÿ|ralues“from“an¾9y“other“domain“consti-Ž¡’õºâtute–$´an“ill-formed“con¾9text.‘J‘ëMCaseU›$°ºand“ëMCaseUU˜ºterms“denoteŽ¡’õºâa–îmapping“from“their“switc¾9h“expressions“to“one“of“the“al-Ž¡’õºâternativ•¾9es.‘ò(As›<suc“h,‘C¶a˜w“ell-formed˜ëMCaseU–ýºor˜ëMCaseUU“ºm¾9ustŽ¡’õºâdenote–7aa“monotonic“mapping,‘åso“wš¾9e“impAÇose“the“seman˜ticŽ¡’õºâconstrain¾9t–Tthat“ëMxŽ‘
`°ëPv‘‘ÆëMyŽ‘	Ý"ëPv‘‘ÆëMzŽ‘K\º.ŽŸ
’õºâAs–~,yš¾9ou“migh˜t“suspAÇect,‘˜aëMSelU›~ºand“ëMSelUU˜ºare“selectors“in“theŽ¡’õºâspirit–Tof“ëMSelAº,“discussed“in“section“3.3.‘pSeman¾9tics“are:Ž¦’ç¤ëMSelU‘	s,n–¹–(Up1‘,Â[x1“...“xn“...“xk])“=“xnŽ¡’ç¤SelUU–¹–n“(UpUp2“[x1“...“xn“...“xk])“=“xnŽ¦’õºâºBut–åthere“is“a“vš¾9ery“strong“seman˜tic“constrain˜t“here:‘+“it“isŽ¡’õºâillegal–Â'to“apply“ëMSelU›Âºor“ëMSelUU˜ºto“a“v›ÿ|ralue“unless“that“v˜alue“isŽ¡’õºâproš¾9v–ÿ|rably‘Eequiv“alen˜t–Eto“an“ëMUp1›¹–[...]“ºor“ëMUpUp2˜[...]“ºv‘ÿ|ralueŽ¡’õºârespAÇectivš¾9ely‘ÿ:«.‘¦ùThis–C‚means,‘O
for“some“arbitrary“con˜text“ëMcº,‘O
theŽ¡’õºâfolloš¾9wing–Texpressions“are“lik˜ely“to“bAÇe“ill-formed:Ž¦’ç¤ëMSelU‘	s,n‘¹–cŽ¡’ç¤SelUU–¹–n“cŽ¦’õºâºThe–×>one“and“only“w•¾9a“y–×>to“makš¾9e“them“w˜ell-formed“is“to“wrapŽ¡’õºâthe–rappropriate“spAÇecies“of“ëMCase“ºterm“around“them,‘‰Élea¾9vingŽ¡’õºâthe–TëMSel“ºin“the“greatest-v‘ÿ|ralue“arm:Ž¦’ç¤ëMCaseU‘	s,c–¹–(...whatever...)“(SelU“n“c)Ž¡¡’ç¤CaseUU–¹–c“(...whatever...)“(...whatever...)Ž¡’~Àà(SelUU–¹–n“c)Ž¦’õºâºIn–ŽìbšAÇoth“cases,‘­Rthe“term“ëM(Sel–¹–n“c)–Žìºma¾9y“not“app˜ear“in“an¾9yŽ¡’õºâplace–Ôømark¾9ed“\ëM...whatever...º".‘[]Note“that“the“ëMSel“ºtermŽ¡’õºâmaš¾9y–2—appAÇear“an˜ywhere“within“the“greatest-v‘ÿ|ralue“arm,‘yçandŽ¡’õºâis–“|not“restricted“to“the“top“lev¾9el,‘³as“this“example“seems“toŽ¡’õºâsuggest.ŽŸþ'’õºâ¹3.5Ž’G·Constructo¹™r–LÎfunctions“and“case“statementsŽŸm’õºâºThe–˜source-language“trappings“of“structured“tš¾9ypAÇes“giv˜e“riseŽ¡’õºâto–Nôsome“of“the“more“inš¾9teresting“parts“of“the“abstract“in˜ter-Ž¡’õºâpreter,‘NOand›Bêw•¾9arran“t˜a˜section˜to˜themselv“es.‘¥1First,‘NOthough,Ž¡’õºâsome–Tterminology‘ÿ:«.‘pA“structured“tš¾9ypAÇe“is“dened“lik˜e“this:Ž¦’ç¤ëMdata–¹–typeName“v1“...“vk“=“C1“t11“...“t1mŽ¡’uM´|‘Ÿî...Ž¡’uM´|–¹–Cn“t1n“...“tnmŽŽŽŽŽŸ’åäº10ŽŽŒ‹
› •ºâ ý? £ ý€‘íºâºThis–˜denes“a“tš¾9ypAÇe“called“ëMtypeNameº,‘¿©param˜terised“b˜y“t˜ypAÇeŽ¤
‘íºâv‘ÿ|rariables–Î@ëMv1“ºto“ëMvkº,‘Üxwith“constructors“ëMC1“ºto“ëMCnº.‘¿The“t¾9ypAÇe“ex-Ž¡‘íºâpressions–÷ýëMt11“ºto“ëMtnmº,‘ýÛwhicš¾9h“form“the“argumen˜ts“to“the“con-Ž¡‘íºâstructors,‘ñare–Åhea¾9vily“constrained“in“the“manner“discussedŽ¡‘íºâin–
1section“2.2.6:‘*they“maš¾9y“only“bAÇe“either“one“of“the“t˜ypAÇeŽ¡‘íºâv‘ÿ|rariables,›i
ëMv1–¹–...“vkº,˜or–XLa“direct“recursivš¾9e“call“to“the“t˜ypAÇe:Ž¡‘íºâëM(typeName–¹–v1“...“vk)º.ŽŸ
‘íºâBecause–€of“this“constrain•¾9t,‘š¹eac“h–€constructor“argumen¾9t“in“aŽ¡‘íºâv‘ÿ|ralid–&ìdenition“can“bAÇe“classied“either“as“a“recursiv¾9e“call“ëMRecº,Ž¡‘íºâor–Yas“one“of“the“tš¾9ypAÇe“v‘ÿ|rariables,‘jžëMVar‘¹–n“ºwhere“ëMn“ºis“a“n˜um˜bAÇerŽ¡‘íºâdenoting–Twhic¾9h“v‘ÿ|rariable.‘pF‘ÿ:«or“example,“the“denitionŽ©ÐO‘ûç¤ëMdata–¹–AVLTree“i“a“bŽ¡‘
f=‘¹–ALeafŽ¡‘
f|–¹–ANode“i“(AVLTree“i“a“b)“a“b“(AVLTree“i“a“b)Ž¦‘íºâºcan,–Tin“principle,“bAÇe“rewritten“asŽ¦‘ûç¤ëMdata–¹–AVLTree“(of“3“type“variables)Ž¡‘
f=‘¹–ALeafŽ¡‘
f|–¹–ANode“(Var“1)“Rec“(Var“2)“(Var“3)“RecŽ¦‘íºâºW‘ÿ:«e–)
noš¾9w“dene“t˜w˜o“strange“functions,‘-øëMargkind“ºand“ëMupdateº,Ž¡‘íºâto–ÓŽassist“in“the“discussion“bAÇeloš¾9w.‘	WNeither“are“mean˜t“toŽ¡‘íºâbAÇe–¿implemenš¾9table.‘”Rather,‘éxthey“serv˜e“as“con˜v˜enien˜t“nota-Ž¡‘íºâtional–êRdevices,‘‘and“are“bAÇest“illustrated“b¾9y“example.‘›jTheyŽ¡‘íºâare–§ÍbAÇoth“meaningless“unless“the“particular“constructor“ap-Ž¡‘íºâplication–Tthey“are“assoAÇciated“with“is“stated.ŽŸ
‘íºâëMargkind–…ºtells“us“what“part“of“a“data“tš¾9ypAÇe“a“giv˜en“construc-Ž¡‘íºâtor–×ìargumenš¾9t“correspAÇonds“to:‘ý¼either“a“certain“t˜ypAÇe“v‘ÿ|rariable,Ž¡‘íºâor–ý3a“recursivš¾9e“instance“of“the“t˜ypšAÇe.‘eF‘ÿ:«or“example,‘b˜earing“inŽ¡‘íºâmind–~the“declaration“abAÇo•¾9v“e,‘˜Pgiv“en–~the“constructor“applica-Ž¡‘íºâtion‘TëM(ANode–¹–i“l“a“b“r)º:Ž¦‘ûç¤ëMargkind–¹–i“=“Var“1Ž¡‘ûç¤argkind–¹–l“=“RecŽ¡‘ûç¤argkind–¹–a“=“Var“2Ž¡‘ûç¤argkind–¹–b“=“Var“3Ž¡‘ûç¤argkind–¹–r“=“RecŽ¦‘íºâupdate–G	ºreplaces“a“particular“v‘ÿ|ralue“in“a“supplied“list“withŽ¡‘íºâanother–Œ†v‘ÿ|ralue.‘‚It“nds“out“whic¾9h“lošAÇcation“to“up˜date“b¾9yŽ¡‘íºâusing–wëMargkindº,‘J@expAÇecting“an“answ¾9er“of“the“form“ëM(Var‘¹–i)º,Ž¡‘íºâwhereupšAÇon–B‡ëMi“ºis“used“as“the“lo˜cation.‘¤	It“is“in¾9v‘ÿ|ralid“to“useŽ¡‘íºâëMupdate–ëºin“a“w•¾9a“y›ëwhic“h˜w“ould˜cause˜the˜call˜to˜argkindŽ¡‘íºâto–Ö_return“ëMRecº.‘	_’Again,‘F¡using“the“constructor“applicationŽ¡‘íºâëM(ANode–¹–i“l“a“b“r)º:Ž¦‘ûç¤ëMupdate–¹–i“"my"‘,Â["the",“"cat",“"sat"]Ž¡‘
f=–¹–["my",‘	s,"cat",“"sat"]Ž¡¡‘ûç¤update–¹–a“"dog"‘	s,["the",“"cat",“"sat"]Ž¡‘
f=–¹–["the",“"dog",“"sat"]Ž¡¡‘ûç¤update–¹–b“"ran"‘	s,["the",“"cat",“"sat"]Ž¡‘ZÐ=–¹–["the",“"cat",“"ran"]Ž¦‘íºâºButŽ¦‘ûç¤ëMupdate–¹–l“x“xsŽ¡‘ûç¤update–¹–r“x“xsŽ¦‘íºâºare–TbAÇoth“illegal“since“ëMargkind›¹–l“º=“ëMargkind˜r“º=“ëMRecº.ŽŽŽ ý€’õºâThe–$Êexample“used“ëMupdate“ºto“replace“w¾9ords“in“a“list“thereof“toŽ¤
’õºâemphasise–C6ëMupdateº's“pAÇolymorphic“nature.‘¦Note“that“ëMupdateŽ¡’õºâºis›Ïalw•¾9a“ys˜used˜with˜a˜constructor˜wrappAÇed˜round˜the˜nalŽ¡’õºâlist–ö¸argumenš¾9t.‘<This“constructor“is“re-attac˜hed“to“the“result:Ž©¹’ç¤ëMupdate–¹–i“"my"Ž¡’‡’(SomeConstructor–¹–["the",“"cat",“"sat"])Ž¡’f=–¹–(SomeConstructor“["my",‘	s,"cat",“"sat"])Ž¦’õºâºF‘ÿ:«or–`
the“sakš¾9e“of“clarit˜y‘ÿ:«,‘r¸this“inconsequen˜tial“detail“is“hence-Ž¡’õºâforth‘Tignored.ŽŸ
’õºâRecall–wªfrom“section“2.2.5“that“function“ëMD‘wOºreturns“the“do-Ž¡’õºâmain–Ì.assošAÇciated“with“a“particular“t¾9yp˜e.‘@ýF‘ÿ:«our“more“handyŽ¡’õºâfunctions–wcof“similar“ilk“are“ëMtopº,–çëMbotº,“ëMtopfv–wcºand“ëMwhnfº.‘BTheŽ¡’õºârst›‚´t•¾9w“o˜simply˜generate˜the˜greatest˜and˜least˜con“texts˜in˜aŽ¡’õºâparticular–5©domain.‘ÑâëMtopfv(D)‘5pºgenerates“the“greatest“abstractŽ¡’õºâv‘ÿ|ralue–Tin“domain“ëMDº.Ž¦’ç¤ëMtop–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=–¹–Up1‘,Â[top(D1)“...“top(Dn)]Ž¡’ç¤top–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=–¹–UpUp2“[top(D1)“...“top(Dn)]Ž¡’ç¤top–¹–(Ds“->“Dt)Ž¡’f=–¹–(\c“->“top(Ds))Ž¡¡’ç¤bot–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=‘¹–Stop1Ž¡’ç¤bot–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=‘¹–Stop2Ž¡’ç¤bot–¹–(Ds“->“Dt)Ž¡’f=–¹–(\c“->“bot(Ds))Ž¡¡’ç¤topfv–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=–¹–ANonRec“[topfv(D1)“...“topfv(Dn)]Ž¡’ç¤topfv–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=–¹–ARec‘æX[topfv(D1)“...“topfv(Dn)]Ž¡’ç¤topfv–¹–(Ds“->“Dt)Ž¡’f=–¹–Fval“(\c“->“top(Ds))Ž¡’3'€(\a–¹–->“topfv(Dt))Ž¦’õºâwhnf(D)‘ž…ºis–ž£the“w¾9eak“head“normal“form“ev‘ÿ|raluator“for“domainŽ¡’õºâëMDº.–TThis“only“mak¾9es“sense“for“certain“v‘ÿ|ralues“of“ëMDº:Ž¦’ç¤ëMwhnf–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=‘,ÂUp1–¹–[bot(D1)“...“bot(Dn)]Ž¡’ç¤whnf–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=–¹–UpUp2“[bot(D1)“...“bot(Dn)]Ž¦’õºâºFinally‘ÿ:«,–Tfor“the“record,“a“Core“ëMcase“ºexpression“loAÇoks“lik¾9eŽ¦’ç¤ëMcase–¹–switchExpression“ofŽ¡’fC1–¹–p11“...“p1m“->“rhs1Ž¡’3'€...Ž¡’fCn–¹–p1n“...“pnm“->“rhsnŽ¦’õºâºwhere–X%it“is“assumed“that“all“constructors“are“presen¾9t.‘ääThisŽ¡’õºâis–Tassured“bš¾9y“the“pattern-matc˜hing“phase“of“the“desugarer.ŽŸ
’õºâThe–ífour“folloš¾9wing“sections“doAÇcumen˜t“the“
o˜w“of“abstractŽ¡’õºâv‘ÿ|ralues–^and“con¾9texts“through“constructor“applications“andŽ¡’õºâëMcase–¤'ºexpressions.‘ö¶In“some“w•¾9a“ys,‘ºÊthe›¤'t“w“o˜are˜oppAÇosites:‘ãÚcon-Ž¡’õºâstructor–kapplications“build“structures,‘O1whilst“ëMcase“ºexpres-Ž¡’õºâsions–‹Mdisassemš¾9ble“them.‘~ZAn“in˜teresting“dualit˜y“arises“fromŽ¡’õºâthis.‘ÌThe–
o¾9w“of“abstract“v‘ÿ|ralues“though“case“expressionsŽ¡’õºâis– uncannily“similar“to“the“
oš¾9w“of“con˜texts“v‘ÿ|ralues“throughŽ¡’õºâconstructors,–Tand“vice“v¾9ersa.ŽŽŽŽŽŸ’åä11ŽŽŒ‹& •ºâ ý? £ ý€‘íºâ¹3.5.1Ž‘úíConstructoš¹™r–LÎfunctions:‘fhabstract“value“p˜ropagationŽŸm‘íºâºHoš¾9w–1do“abstract“v‘ÿ|ralues“
o˜w“through“a“constructor?‘4TheŽ¤
‘íºâdiscussion–§Éof“section“3.3“implied“that“the“the“ëM(:)“ºfunctionŽ¡‘íºâm•¾9ust›TbAÇeha“v“e˜something˜lik“e:Ž¤eh‘ûç¤ëM(:)–¹–=“\x“xs“->“AMeet“[xs,“ARec“[x]]Ž¡‘íºâºObservš¾9e–‹¦that“the“apparen˜tly“pAÇolymorphic“nature“of“this“def-Ž¤
‘íºâinition–©is“incidenš¾9tal.‘ï7In“general,‘¨Ìgiv˜en“an“arit˜y-n“constructorŽ¡‘íºâëMC‘öºand–ùargumen¾9ts“ëMa1–¹–...“an–ùºwhere“ëM(C–¹–a1“...“an)“::“tauº,Ž¡‘íºâthe–Tforwš¾9ard“bAÇeha˜viour“of“C“is:Ž©eh‘ûç¤ëM\a1–¹–...“an“->“AMeet“[e1“...“en]Ž¡¡‘ûç¤ei–¹–=“aiŽ¡‘‡’if–¹–argkind“ai“=“RecŽ¡¡‘
f=–¹–ARec“(update“ai“ai“topfv(D(tau)))Ž¡‘‡’if‘,Âargkind–¹–ai“==“Var“xŽ¡‘‡’and‘	s,C–¹–is“from“a“recursive“typeŽ¡¡‘
f=–¹–ANonRec“(update“ai“ai“topfv(D(tau)))Ž¡‘‡’if‘,Âargkind–¹–ai“==“Var“xŽ¡‘‡’and‘	s,C–¹–is“from“a“non-recursive“typeŽ¦‘íºâºNullary–„fconstructors“simply“acquire“the“top“abstract“v‘ÿ|ralueŽ¡‘íºâof–¸‡the“relev‘ÿ|ran¾9t“domain“(bAÇear“in“mind“that,‘Ëfor“a“domain“notŽ¡‘íºâcon¾9taining–“ófunction“spaces,‘³›this“is“the“same“as“the“bAÇottomŽ¡‘íºâpAÇoin¾9t).‘pThe–TëM[]“ºcase“for“ëM[Int]º,“for“example,“is:Ž¦‘ûç¤ëM[]–¹–=“topfv(D(“[Int]“))Ž¡‘
f=–¹–topfv(“Lift2“(Lift“())“)Ž¡‘
f=–¹–ARec“[ANonRec“[]]Ž¦‘íºâºThe–Ã3motiv¾9e“in“all“this“is“to“ensure“that“the“abstract“v‘ÿ|ralue“ofŽ¡‘íºâa–Žconstructor“application“is“cš¾9haracterised,‘µfor“eac˜h“parame-Ž¡‘íºâterising–Ttš¾9ypAÇe,“b˜y“the“least“v‘ÿ|ralue“of“that“t˜ypAÇe.ŽŸ
‘íºâAs–K[an“example,‘×consider“an“ob‘ƒŽjectŽ¡‘íºâof–‹þtš¾9ypAÇe“ëM(AVLTree–¹–Int“Int“Int)º.‘€oCon˜texts–‹þfor“that“t˜ypAÇeŽ¡‘íºâare–®ædra¾9wn“from“the“domain“ëMLift2–¹–(Lift“()“x“Lift“()“xŽ¡‘íºâLift‘¹–())º.‘
#ÀW‘ÿ:«e–ÄexpAÇect“the“abstract“v‘ÿ|ralue“returned“b¾9yŽ¡‘íºâbšAÇoth–þ¾the“ëMALeaf“ºand“ëMANode“ºconstructors“to“b˜e“of“the“formŽ¡‘íºâëMARec–¹–[ii,“aa,“bb]–ͺwhere“ëMii“ºrepresen¾9ts“the“least“abstractŽ¡‘íºâv‘ÿ|ralue–Qof“anš¾9y“ob‘ƒŽject“correspAÇonding“to“t˜ypAÇe“v‘ÿ|rariable“ëMi“ºin“theŽ¡‘íºât¾9ypAÇe–TAdenition,›cüand“similarly“for“ëMaa“ºand“ëMbbº.‘Ù7So,˜at“this“in-Ž¡‘íºâstanš¾9tiation,‘ Wthe–ƒabstract“v‘ÿ|ralue“bAÇeha˜viour“of“the“constructorsŽ¡‘íºâis:Ž©J®‘ûç¤ëMALeaf–¹–=“ARec“[ANonRec“[],“ANonRec“[],“ANonRec“[]]Ž¡¡‘ûç¤ANodeŽ¡‘ûç¤=–¹–\i“l“a“b“r“->Ž¡‘ZÐAMeetŽ¡‘ZÐ[–¹–ARec“[i,‘/?ÜANonRec“[],“ANonRec“[]],Ž¡‘Íül,Ž¡‘ÍüARec–¹–[ANonRec“[],“a,‘/?ÜANonRec“[]],Ž¡‘ÍüARec–¹–[ANonRec“[],“ANonRec“[],“b‘*†F],Ž¡‘ÍürŽ¡‘ZÐ]Ž¦‘íºâºNon-recursiv•¾9e›`~t“ypAÇes˜are˜dealt˜with˜in˜an˜exactly˜analogousŽ¡‘íºâmanner.‘ÒJF‘ÿ:«or–6âexample,‘c`the“bAÇeha¾9viour“of“the“pairing“construc-Ž¡‘íºâtor–Tat“t¾9ypAÇe“ëMInt–¹–->“Int“->“(Int,“Int)‘TºisŽŽŽ ý€’ç¤ëM(,)Ž¤
’ç¤=–¹–\x“y“->Ž¡’
ZÐAMeetŽ¡’
ZÐ[–¹–ANonRec“[x,‘/?ÜANonRec“[]],Ž¡’ÍüANonRec–¹–[ANonRec“[],“y‘*†F]Ž¡’
ZÐ]Ž©q’õºâºIf–_¨yš¾9our“instincts“tell“y˜ou“this“is“m˜uc˜h“ado“abAÇout“nothing,‘ƒþy˜ouŽ¡’õºâare–;!correct.‘ØSince“all“these“examples“build“structures“with-Ž¡’õºâout–¦ïem¾9bAÇedded“function“spaces,‘½the“result“v‘ÿ|ralues“are“unitary‘ÿ:«,Ž¡’õºâand–Tma¾9y“bAÇe“written:Ž¦’ç¤ëM[]‘	s,=‘/?ÜARec–¹–[ANonRec“[]]Ž¡’ç¤(:)–¹–=“\x“xs“->“ARec“[ANonRec“[]]Ž¡¡’ç¤(,)–¹–=“\x“y“->“ANonRec“[ANonRec“[],“ANonRec“[]]Ž¡¡’ç¤ALeaf–¹–=“ARec“[ANonRec“[],“ANonRec“[],“ANonRec“[]]Ž¡’ç¤ANode–¹–=“\i“l“a“b“r“->Ž¡’)´TARec–¹–[ANonRec“[],“ANonRec“[],“ANonRec“[]]ŽŸ?’õºâ¹3.5.2Ž’úíConstructoš¹™r–LÎfunctions:‘fhcontext“p˜ropagationŽŸm’õºâºThe–Qname“of“the“game“here“is“to“saš¾9y“what“con˜text“propagatesŽ¡’õºâfrom–ƒMa“non-nš¾9ullary“constructor“to“its“argumen˜ts.‘fZIn˜tuitingŽ¡’õºârst–Ton“ëM[Int]º,“ëM(:)“ºexhibits“the“folloš¾9wing“bAÇeha˜viour:Ž¦’õºâëMDemand–¹–on“(x:xs)›Y„Demand“on“x˜Demand“on“xsŽ¡’õºâ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Ž¡’ÿ.UU[U[]]‘FßÊU[]‘B&4UU[U[]]Ž¡’ÿ.UU[_]‘PRö_‘K™`UU[_]Ž¡’ÿ.U_‘^¸_‘K™`_Ž¡’ÿ._‘c9N_‘K™`_Ž¦’õºâºA‘÷½ëMUU[U[]]–÷źconš¾9text“causes“ev‘ÿ|raluation“of“the“en˜tire“structureŽ¡’õºâof–,pthe“list,‘27and“all“the“ëMIntºs“in“it“toAÇo.‘aÅSo“wš¾9e“ma˜y“propagateŽ¡’õºâëMU[]–˜!ºto“ëMx“ºand“ëMUU[U[]]“ºto“the“tail“of“the“list.‘¤ÖThe“sameŽ¡’õºâreasoning–9œexplains“the“propagation“of“a“ëMUU[_]“ºcon•¾9text.‘Ó3No“w,Ž¡’õºâwhat–`iof“ëMU_º?‘à"This“ev›ÿ|raluator“simply“ev˜aluates“to“WHNF,“thatŽ¡’õºâis,–‹the,“rst›ýØconstructor,“and˜giv•¾9es˜up.‘œSo˜zero˜con“text˜ma“yŽ¡’õºâbAÇe–Èýpropagated“to“either“head“or“tail.‘þSimilarly‘ÿ:«,‘ØBzero“con¾9textŽ¡’õºâpropagates–Tfrom“zero“con¾9text“on“ëM(x:xs)º.ŽŸ
’õºâIs–;Žthere“a“pattern“here?‘The“con¾9text“on“ëMxs“ºis“that“same“asŽ¡’õºâthe–ÜMconš¾9text“on“ëM(x:xs)“ºexcept“at“the“WHNF‘ÜpAÇoin˜t,‘
whilstŽ¡’õºâthe–#'con¾9text“on“ëMx“ºis“\ëMyº"“in“the“ëMUU[y]“ºcases,‘&œand“none“other-Ž¡’õºâwise.‘áÊThis–¬rlatter“opšAÇeration“could“b˜e“regarded“as“droppingŽ¡’õºâthe–rdouble-lifting,‘É*and“selecting“the“rst“prošAÇduct“comp˜o-Ž¡’õºânenš¾9t.‘”W‘ÿ:«riting–ÍÁthe“con˜text“on“ëM(x:xs)“ºas“ëMalphaº,‘Ücon˜text“on“ëMxŽ¡’õºâºand–TëMxs“ºrespšAÇectiv¾9ely“could“b˜e“written“as:Ž¦’ç¤ëMDropUU–¹–1“alphaŽ¡’ç¤ZapWHNF‘¹–alphaŽ¦’õºâºImplemen¾9ting–ºZëMDropUU›¹íºand“ëMZapWHNF˜ºdirectly“causes“ma‘ƒŽjorŽ¡’õºâproblems–Ÿ³in“the“term-rewriting“system.‘»F–ÿ:«ortunately“,‘JtheŽ¡’õºâëMCaseUU–Tºand“ëMSelUU“ºprimitiv¾9es“can“bAÇe“used“instead:Ž¦’útxëMDropUU–¹–n“alpha“=“CaseUU“alpha“_“_“(SelUU“n“alpha)Ž¡’útxZapWHNF–¹–alpha‘	s,=“CaseUU“alpha“_“_“alphaŽ¦’õºâºAnalogising–Š•the“informal“argumen¾9t“leads“to“a“general“rule.Ž¡’õºâGivš¾9en–@an“arit˜y-ëMn“ºconstructor“ëMC‘?´ºand“argumen˜ts“ëMa1–¹–...“anŽ¡’õºâºwhere›S$ëM(C–¹–a1“...“an)“::“tauº,‘¢˜con¾9text˜ëMalpha˜ºon˜the˜con-Ž¡’õºâstructor–Tapplication“proAÇduces“conš¾9text“on“ëMai“ºas“follo˜ws:ŽŽŽŽŽŸ’åä12ŽŽŒ‹
=ý •ºâ ý? £ ý€‘ûç¤ëMai‘	s,=–¹–ZapWHNF“alphaŽ¤
‘A(if‘,Âargkind–¹–ai“==“RecŽ¡¡‘Íü=–¹–DropUU“x“alphaŽ¡‘A(if‘,Âargkind–¹–ai“==“Var“xŽ¡‘A(and‘	s,C–¹–is“from“a“recursive“typeŽ¡¡‘Íü=–¹–DropU“x“alphaŽ¡‘A(if‘,Âargkind–¹–ai“==“Var“xŽ¡‘A(and‘	s,C–¹–is“from“a“non-recursive“typeŽŸ¹'‘íºâºThe–}iëMAVLTree“ºexample“at“instance“ëM(AVLTree–¹–Int“Int“Int)Ž¡‘íºâºbAÇeha•¾9v“es–Lqas“folloš¾9ws“for“a“con˜text“ëMalpha“ºapplied“toŽ¡‘íºâëM(ANode–¹–i“l“a“b“r)º:Ž©s]‘ûç¤ëMVariable‘!DemandŽ¡‘ûç¤~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Ž¡‘ûç¤i‘B&4DropUU–¹–1“alphaŽ¡‘ûç¤l‘B&4ZapWHNF‘	s,alphaŽ¡‘ûç¤a‘B&4DropUU–¹–2“alphaŽ¡‘ûç¤b‘B&4DropUU–¹–3“alphaŽ¡‘ûç¤r‘B&4ZapWHNF‘	s,alphaŽ¦‘íºâºConš¾9text–9%propagation“for“non-recursiv˜e“t˜ypšAÇes“b˜eha•¾9v“es–9%in“aŽ¡‘íºâsimilar–N¬manner,‘]except“that“it“is“no“longer“pAÇossible“to“gen-Ž¡‘íºâerate–)]ëMZapWHNFº,“and“the“drop-select“opAÇerator“only“drops“oneŽ¡‘íºâpAÇoinš¾9t,‘ö%instead–îYof“t˜w˜o.‘rThis“opAÇerator,‘ö%called“ëMDropUº,“is“imple-Ž¡‘íºâmen¾9ted‘TasŽ¤¹'‘ûç¤ëMDropU–¹–n“alpha‘	s,=“CaseU“alpha“_“(SelU“n“alpha)Ž¡‘íºâºF‘ÿ:«or–ÿ7a“con¾9text“ëMalpha“ºapplied“to“ëM(x,–¹–y)“::“(Int,“Int)º,‘£theŽ¤
‘íºâcon¾9texts–ÒËpropagated“to“ëMx“ºand“ëMy“ºare“ëM(DropU–¹–1“alpha)‘Ò˺andŽ¡‘íºâëM(DropU–¹–2“alpha)‘TºrespAÇectiv¾9ely‘ÿ:«.ŽŸ
‘íºâT‘ÿ:«ranslation–gvof“ëMDropUº,“ëMDropUU›gJºand“ëMZapWHNF˜ºin¾9to“the“ëMCase“ºandŽ¡‘íºâëMSel–
ݺprimitiv¾9es“requires“some“passing“around“of“domains,‘[soŽ¡‘íºâthat–¥the“appropriate“kind“of“bšAÇottom“v‘ÿ|ralues“can“b˜e“man¾9ufac-Ž¡‘íºâtured.ŽŸÿ‘íºâ¹3.5.3Ž‘úíCase–LÎexpš¹™ressions:‘fhabstract“value“p˜ropagationŽŸm‘íºâºThe–æQtask“here“is“to“gure“out“what“abstract“v‘ÿ|ralues“to“at-Ž¡‘íºâtacš¾9h–ôÚto“constructor“v‘ÿ|rariables“in“a“case“expression,‘ûYgiv˜en“theŽ¡‘íºâabstract–TUv‘ÿ|ralue“of“the“switc¾9h“expression.‘ÙrThe“solution“is“re-Ž¡‘íºâmark‘ÿ|rably–`äsimilar“to“propagation“of“con¾9texts“to“constructorŽ¡‘íºâargumen•¾9ts,‘^3and›O follo“ws˜a˜theme˜whic“h˜should˜b•AÇe˜b“ecomingŽ¡‘íºâfamiliar.‘pGiv¾9en–Ta“case“expressionŽ©¹'‘ûç¤ëMcase–¹–sw“ofŽ¡‘
f...Ž¡‘
fC–¹–a1“...“an“->“rhsŽ¡‘
f...Ž¦‘íºâºand–L¹an“abstract“v‘ÿ|ralue“assoAÇciated“with“ëMsw“ºof“ëMfswº,‘tØthe“abstractŽ¡‘íºâv‘ÿ|ralue–TassoAÇciated“with“ëMai“ºisŽ¦‘ûç¤ëMai‘	s,=‘¹–fswŽ¡‘A(if‘,Âargkind–¹–ai“==“RecŽ¡¡‘Íü=–¹–SelA“x“fswŽ¡‘A(if‘,Âargkind–¹–ai“==“Var“xŽ¦‘íºâºLet–wØthe“abstract“v‘ÿ|ralue“of“the“switc¾9h“expression“bAÇe“denotedŽ¡‘íºâëMfswº.‘pF‘ÿ:«or–TëM[Int]“ºwš¾9e“ha˜v˜e:ŽŽŽ ý€’ç¤ëMcase–¹–sw“ofŽ¤
’f[]‘Ÿî->‘	s,rhs1Ž¡’f(x:xs)‘¹–->‘	s,rhs2Ž¤ƒ’õºâºgiving–Tbindings“ofŽ¡’ç¤ëMx–	s,--->“SelA–¹–1“fswŽ©
’ç¤xs‘¹–--->‘	s,fswŽ¡’õºâ(AVLTree–¹–Int“Int“Int)‘Tºgiv¾9es:Ž¡’ç¤ëMcase–¹–sw“ofŽ¦’fALeaf‘8³->‘¹–rhs1Ž¦’fANode–¹–i“l“a“b“r‘	s,->“rhs2Ž¦¦’ç¤i–	s,--->“SelA–¹–1“fswŽ¦’ç¤l–	s,--->“fswŽ¦’ç¤a–	s,--->“SelA–¹–2“fswŽ¦’ç¤b–	s,--->“SelA–¹–3“fswŽ¦’ç¤r–	s,--->“fswŽ¡’õºâºFinally‘ÿ:«,–TëM(Int,‘¹–Int)“ºgiv¾9es:Ž¡’ç¤ëMcase–¹–sw“ofŽ¦’f(x,–¹–y)‘	s,->“rhs1Ž¦¦’ç¤x–	s,--->“SelA–¹–1“fswŽ¦’ç¤y–	s,--->“SelA–¹–2“fswŽ¤ô’õºâ¹3.5.4Ž’úíCase–LÎexpš¹™ressions:‘fhcontext“p˜ropagationŽŸm’õºâºThis–Ñösection“establishes“hoš¾9w“con˜text“on“a“ëMcase“ºexpressionŽ¦’õºâpropagates–kto“conš¾9text“on“the“switc˜h“expression.‘¦First,‘ÀaŽ¦’õºâsubsidiary‘Tresult.Ž¡’õºâ¹F•¹™o“rw“a“rds›LÎp“ropagation˜of˜contexts˜though˜constructo“rsŽŸm’õºâºGiv¾9en–5%a“constructor“application“ëM(C–¹–a1“...“an)“::“tauº,‘aütheŽ¦’õºâmethoAÇd–G˜of“section“3.5.2“can“tell“us“hoš¾9w“con˜text“on“this“ap-Ž¦’õºâplication–C¸maps“to“conš¾9text“on“ëMa1–¹–...“anº.‘§›Ho˜w˜ev˜er,‘OQw˜e‘C¸no˜wŽ¦’õºâneed–Hgto“run“the“proAÇcess“in“rev•¾9erse.‘µªGiv“en–Hgsome“con¾9textsŽ¦’õºâëMc1–¹–...“cn–Lºon“ëMa1–¹–...“anº,‘´w•¾9e›Lw“an“t˜to˜nd˜the˜greatest˜con-Ž¦’õºâtext–õÈëMalpha“ºthat“ma¾9y“bAÇe“put“on“the“application,‘üconstrainedŽ¦’õºâso–that“the“conš¾9texts“that“section“3.5.2“indicates“w˜ould“thenŽ¦’õºâpropagate–ºto“ëMa1–¹–...“an–ººare“less“than“or“equal“ëMc1–¹–...“cnŽ¦’õºâºrespAÇectiv¾9ely‘ÿ:«.ŽŸ
’õºâThe–ñ§folloš¾9wing“sc˜heme“is“oered,‘øÉagain“without“justication.Ž¦’õºâIf–TëMC“ºis“from“a“recursivš¾9e“t˜ypAÇe:Ž¤ƒ’ç¤ëMalpha–¹–=“CJoin“[Up2,“CMeet“[e1“...“en]]Ž¦¦’ç¤ei–¹–=“aiŽ¦’‡’if‘,Âargkind–¹–ai“==“RecŽ¦¦’f=–¹–update“ai“ai“top(D(tau))Ž¦’‡’if‘,Âargkind–¹–ai“==“Var“xŽ¡’õºâºIf–pëMC‘Pºis“from“a“non-recursivš¾9e“t˜ypšAÇe,‘¯6ëM(argkind‘¹–ai)“ºcannot“b˜eŽ¦’õºâëMRecº,–Tso“this“simplies“to:Ž¡’ç¤ëMalpha–¹–=“CMeet“[e1“...“en]Ž¦¦’ç¤ei–¹–=“update“ai“ai“top(D(tau))Ž¦’‡’if‘,Âargkind–¹–ai“==“Var“xŽŽŽŽŽŸ’åäº13ŽŽŒ‹U  •ºâ ý? £ ý€‘íºâºFinally‘ÿ:«,–Tfor“nš¾9ullary“constructors,“lik˜e“ëM[]º:Ž¤k‘ûç¤ëMalpha–¹–=“ctop(D(tau))Ž¡‘íºâºExamples:‘pgiv¾9en›TëM(a1,–¹–a2)“::“(Int,“Int)º,˜w¾9e˜getŽ¡‘ûç¤ëMalpha–¹–=“CMeet“[“Up1“[c1,‘æXU[]“],Ž©
‘GUp1–¹–[U[],‘,Âc2]“]Ž¡‘íºâ(a1:a2)–¹–::“[Int]‘Tºgiv¾9esŽ¡‘ûç¤ëMalpha–¹–=“CJoin“[“Up2,Ž¦‘GCMeet–¹–[“UpUp2“[c1],Ž¦‘mM´c2‘¹–]Ž¦‘>
Ø]Ž¡‘íºâ[]–¹–::“[Int]‘Tºgiv¾9esŽ¡‘ûç¤ëMalpha–¹–=“UpUp2“[Up1“[]]Ž¡‘íºâ(ANode–¹–a1“a2“a3“a4“a5)“::“(ATree“Int“Int“Int)‘Tºgiv¾9esŽ¡‘ûç¤ëMalpha–¹–=“CJoinŽ¦‘!´T[‘¹–Up2,Ž¦‘+'€CMeet–¹–[“UpUp2“[c1,‘æXU[],‘,ÂU[]“],Ž¦‘Pô0c2,Ž¦‘Pô0UpUp2–¹–[U[],‘,Âc3,‘æXU[]“],Ž¦‘Pô0UpUp2‘¹–[U[],–,ÂU[],“c4‘	s,],Ž¦‘Pô0c5‘¹–]Ž¦‘!´T]ŽŸë‘íºâ¹Using–LÎthe“lemmaŽŸm‘íºâºAnd–»inoš¾9w“to“return“to“the“main“theme.‘¯A˜t“this“pAÇoin˜t,‘äîit'sŽ¦‘íºânecessary–{¸to“inš¾9troAÇduce“a“function“w˜e“will“see“a“lot“more“ofŽ¦‘íºâlater.‘ßThe–¾yfunction“ëMC‘¾Mºtells“us“hoš¾9w“m˜uc˜h“con˜text“is“propa-Ž¦‘íºâgated–s]to“a“v‘ÿ|rariable“ëMx“ºwhen“con¾9text“ëMalpha“ºis“propagated“toŽ¦‘íºâsome–>Óarbitrary“expression“ëMeº.‘˜îOf“course,‘I3if“ëMx“ºdošAÇes“not“o˜ccurŽ¦‘íºâfree–Tin“ëMeº,“the“answ¾9er“is“none.‘pW‘ÿ:«e“write“this“asŽ¡‘ûç¤ëMC–¹–x“[e]“rho“alphaŽ¡‘íºâºwith–¿Žthe“ëMe“ºin“square“brac•¾9k“ets–¿Žto“emphasise“that“ëMC‘¿bºregardsŽ¦‘íºâit–m¦as“a“synš¾9tactic“ob‘ƒŽject.‘%fAs“bAÇecomes“apparen˜t“later,‘ƒ»ëMC‘mºalsoŽ¦‘íºârequires–„an“en•¾9vironmen“t–„ëMrho“ºwhic¾9h“supplies“abstract“v‘ÿ|raluesŽ¦‘íºâfor–Tall“free“v‘ÿ|rariables“in“ëMeº.ŽŸ
‘íºâRecall–Tthat“a“ëMcase“ºexpression“loAÇoks“lik¾9e“this:Ž¡‘ûç¤ëMcase–¹–sw“ofŽ¦‘
fC1–¹–p11“...“p1m“->“rhs1Ž¦‘
f...Ž¦‘
fCn–¹–p1n“...“pnm“->“rhsnŽ¡‘íºâºNo•¾9w,‘S•giv“en›ïcon“text˜ëMalpha˜ºo“v“erall,‘S•what˜is˜the˜con“text˜onŽ¦‘íºâëMswº?‘`aThe–Ö¤rst“step“is“to“nd“the“con¾9text“on“ëMp11–¹–...“pnmº.Ž¦‘íºâThese–Tconš¾9text“are“giv˜en“b˜y:Ž¡‘ûç¤ëM(C–¹–p11“[rhs1]“rho1“alpha)‘,Â...Ž¦‘ûç¤(C–¹–p1m“[rhs1]“rho1“alpha)Ž¦¦‘ûç¤...Ž¦¦‘ûç¤(C–¹–p1n“[rhsn]“rhon“alpha)‘,Â...Ž¦‘ûç¤(C–¹–pnm“[rhsn]“rhon“alpha)ŽŽŽ ý€’õºâºF‘ÿ:«or–D=eacš¾9h“particular“constructor,‘Oöthe“original“en˜viron-Ž¤
’õºâmenš¾9t–ÑõëMrho“ºis“augmen˜ted“with“abstract“v‘ÿ|ralue“bindings“forŽ¡’õºâthe–0v‘ÿ|rariables“assoAÇciated“with“that“constructor,‘vÌgeneratingŽ¡’õºâëMrho1–¹–...“rhonº.‘ˆThese–ëœv‘ÿ|ralues“are“deriv¾9ed“from“the“abstractŽ¡’õºâv‘ÿ|ralue–å„of“the“switc¾9h“expression,‘ïas“describAÇed“in“section“3.5.3.Ž©
’õºâThe–ôHnext“step“is“to“gure“out“what“con¾9text“can“bAÇe“safelyŽ¡’õºâapplied–wËto“eacš¾9h“constructor,‘hkno˜wing“the“con˜texts“on“theirŽ¡’õºâindividual–.4argumen¾9ts.‘gThe“methošAÇd“describ˜ed“in“the“lemmaŽ¡’õºâis–}Ùapplied,›×úonce“for“eac¾9h“constructor,˜to“the“con¾9texts“forŽ¡’õºâëMp11–¹–...“pnm–®ºjust“computed,‘TJgiving“ëMalpha1–¹–...“alphanº.Ž¡’õºâThese–<mv‘ÿ|ralues“are“comš¾9bined“to“giv˜e“the“o˜v˜erall“con˜text“onŽ¡’õºâëMsw‘Tºas:Ž¤ÐO’ç¤ëMCMeet–¹–[alpha1“...“alphan]Ž¡’õºâºUsing–6uëMCMeet“ºto“merge“these“v‘ÿ|ralues“re
ects“the“fact“that“w¾9eŽ¤
’õºâcannot–Øknoš¾9w“whic˜h“alternativ˜e“will“bAÇe“selected“at“compileŽ¡’õºâtime.‘ÿThe–½bšAÇest“safe“v‘ÿ|ralue“whic¾9h“can“b˜e“obtained“is“the“leastŽ¡’õºâof–Tanš¾9y“of“alternativ˜es.Ž¦’õºâUnfortunately‘ÿ:«,‘*¹there–ó?is“one“spAÇecial“case“where“this“form¾9u-Ž¡’õºâlation–¤"is“wrong.‘ÈÙWhen“the“switc¾9h“expression“is“of“a“re-Ž¡’õºâcursiv•¾9e›‹èt“ypAÇe,‘éŒlik“e˜ëM[Int]º,‘éŒone˜nds˜that˜propagating˜zeroŽ¡’õºâcon•¾9text›¼®on“to˜the˜ëMcase˜ºexpression˜proAÇduces˜non-zero˜con“textŽ¡’õºâon–x!the“switc¾9h“expression.‘D×This“unsafe“result“can“bAÇe“tracedŽ¡’õºâto–á7the“case“for“recursivš¾9e“t˜ypšAÇes“b˜eing“of“the“form“ëMalpha“º=Ž¡’õºâëMCJoin–¹–[Up2,“...]º,‘swhicš¾9h–
ûimpAÇoses“a“minim˜um“v‘ÿ|ralue“of“ëMUp2Ž¡’õºâºon–²ºthe“conš¾9text“con˜tributed“b˜y“eac˜h“constructor.‘ô¡SimplyŽ¡’õºâthro•¾9wing›o½a“w“a“y˜the˜ëMUp2˜ºclamping˜bit˜causes˜more˜problemsŽ¡’õºâthan–@¨it“solv¾9es.‘žkA‘@bšAÇetter“solution“is“to“explicitly“imp˜ose“theŽ¡’õºârequired–æ¯condition“that“zero“o•¾9v“erall›æ¯con“text˜proAÇduces˜zeroŽ¡’õºâconš¾9text–ì7on“the“switc˜h“expression.‘¡Recalling“that“ëMalpha“ºisŽ¡’õºâthe›To•¾9v“erall˜con“text,˜this˜is˜done˜b“y˜writingŽ¤ÐO’ç¤ëMCaseU–¹–alpha“_“(CMeet“[alpha1“...“alphan])Ž¡’õºâºorŽ¡’ç¤ëMCaseUU–¹–alpha“_“(CMeet“[alpha1“...“alphan])Ž©
’JÇn(CMeet–¹–[alpha1“...“alphan])Ž¡’õºâºdepšAÇending–CÝon“the“domain“of“ëMalphaº.‘ÖžThe“p˜ossible“duplicationŽ¦’õºâof–the“ëM(CMeet–¹–[alpha1“...“alphan])–ºterm“is“regrettable,Ž¦’õºâand–@Ecould“pšAÇoten¾9tially“cause“ma‘ƒŽjor“p˜erformance“problems.Ž¦’õºâSection–T6.1“shoš¾9ws“ho˜w“these“ma˜y“bAÇe“a˜v˜oided.ŽŸ
’õºâThe–®øcomplications“in“this“business“seem“endless.‘é\W‘ÿ:«e“ha•¾9v“eŽ¦’õºâjust–Tcreated“y¾9et“another“problem.‘pConsider:Ž¡’ç¤ëMlet‘	s,id–¹–y“=“y“inŽ¦’‡’case–¹–e“ofŽ¦’)´T[]‘Y„->‘¹–idŽ¦’)´T(x:xs)‘	s,->‘¹–idŽ¡’õºâºThis–míëMcase“ºexpression“returns“a“function,‘„whic¾9h“is“pAÇerfectlyŽ¦’õºâlegitimate.‘ý:But–µ—the“o•¾9v“erall›µ—con“text˜on˜it,–ݨëMalphaº,“will˜bAÇe˜aŽ¦’õºâfunction–Êcon¾9text,‘Igand“it“is“quite“meaningless“to“scrutiniseŽ¦’õºâsuc¾9h–a“v‘ÿ|ralue“with“ëMCaseU›ºor“ëMCaseUUº.“A˜little“thoughš¾9t“rev˜ealsŽ¦’õºâa–yDsimple“solution.‘H?The“ëMcase“ºexpression“returns“a“function,Ž¦’õºâwhic•¾9h‘^Cwill,›‚áev“en“tually‘ÿ:«,˜bAÇe–^Capplied“to“something.‘ßjWhat“reallyŽ¦’õºâmatters–“Jis“the“con¾9text“on“the“nal“result“of“that“application:Ž¦’õºâif–ínon-zero,‘MÏit“means“the“ëMcase“ºexpression“will“ev•¾9en“tually‘íha“v“eŽ¦’õºâto–ú5bAÇe“enš¾9tered,‘ÿ¢in“order“to“generate“a“function“whic˜h“in“turnŽ¦’õºâgenerates–‘ýsome“result“to“satisfy“the“demand.‘ð¨So,‘¬Ball“w¾9e“needŽ¦’õºâdo,›Ùªif–²fëMalpha“ºis“a“function“con¾9text,˜is“test“the“nal“con¾9textŽŽŽŽŽŸ’åä14ŽŽŒ‹hp •ºâ ý? £ ý€‘íºâºencapsulated–„Yin“ëMalphaº,‘¡Yrather“than“ëMalpha“ºitself.‘ìGetting“theŽ¤
‘íºânal–x\conš¾9text“out“of“an“ëMnº-arit˜y“function“con˜text“is“easily“doneŽ¡‘íºâbš¾9y–Ì…wrapping“ëMn“FncC‘ÌVºselectors“round“it.‘BSo“con˜text“on“theŽ¡‘íºâswitcš¾9h–Texpression,“in“terms“of“ëMalphaº,“no˜w“loAÇoks“lik˜e:Ž©«“‘ûç¤ëMCaseUU–¹–(FncC“(FncC“.....“(FncC“alpha)“.....))Ž¡‘ú¾_Ž¡‘ú¾(CMeet–¹–[alpha1“...“alphan])Ž¡‘ú¾(CMeet–¹–[alpha1“...“alphan])Ž¦‘íºâºThe›Á²n•¾9um“bAÇer˜of˜ëMFncCºs˜is˜equal˜to˜the˜arit“y˜of˜ëMalphaº,‘Òlif˜ëMalphaŽ¡‘íºâºhappšAÇens–+to“b˜e“a“function“con¾9text.‘_!ëMcase“ºexpressions“return-Ž¡‘íºâing–=åfunctions“seem“to“bšAÇe“rarities,‘hüso“usually“there“will“b˜e“zeroŽ¡‘íºâëMFncCºs.‘üThe–´ZcorrespšAÇonding“mo˜dication“of“the“ëMCaseU‘´Aºv¾9ersionŽ¡‘íºâis–•Lobš¾9vious,‘®èand“it“only“remains“to“sa˜y“that“c˜hošAÇosing“b˜et•¾9w“eenŽ¡‘íºâthe›Ð.t•¾9w“o˜no“w˜depAÇends˜on˜the˜nal˜con“text˜encapsulated˜inŽ¡‘íºâëMalpha–Tºwhen“ëMalpha“ºis“a“function“con¾9text.ŽŸ
‘íºâAs–élour“long“journey“through“the“forest“of“suppAÇorting“ma-Ž¡‘íºâcš¾9hinery–ò¢comes“to“a“close,‘ù’so“the“nal“destination“dra˜ws“in˜toŽ¡‘íºâsighš¾9t:‘ˆíthe–K“denition“of“the“abstract“in˜terpreter“propAÇer.‘¿,W‘ÿ:«eŽ¡‘íºâpause–ÀGbut“brie
y“to“takš¾9e“respite“in“the“follo˜wing“example,Ž¡‘íºâthen–Temš¾9bark“upAÇon“the“nal“straigh˜t:‘psection“3.6.Ž¦‘ûç¤ëMcase–¹–vs“ofŽ¡‘
f[]‘Y„->‘¹–0Ž¡‘
f(x:xs)‘	s,->‘¹–xŽ¦‘íºâºClearly‘ÿ:«,‘ÿkëMvs–¹–::“[Int]–ùðºand“the“o•¾9v“erall›ùðt“ypAÇe˜is˜ëMIntº.‘OSo˜a˜con-Ž¡‘íºâtext–«ëMalpha“ºplaced“on“the“result“m¾9ust“bAÇe“in“domain“ëMLift‘¹–()º,Ž¡‘íºâwith–Dthe“resulting“con¾9text“on“ëMvs“ºin“ëMLift2–¹–(Lift“())º.‘¨ÁSec-Ž¡‘íºâtion–Ýï3.5.4“indicates“that“the“ëM[]“ºcase“conš¾9tributes“con˜textŽ¡‘íºâëMUpUp2–¹–[Up1“[]]º.‘ØNo¾9w,‘þNpropagating–øŒëMalpha“ºto“the“ëM(:)“ºalter-Ž¡‘íºânativš¾9e–¯Üputs“con˜text“ëMalpha“ºon“ëMx“ºand“ëMStop2“º(that“is,‘Ä'none)“onŽ¡‘íºâëMxsº.‘˜ÙComš¾9bining–”"these“t˜w˜o,›³Õagain“using“section“3.5.4,˜sho¾9wsŽ¡‘íºâthat–Tthe“conš¾9text“propagated“b˜y“this“alternativ˜e“is:Ž¦‘ZÐëMCJoin–¹–[Up2,“CMeet“[alpha,“Stop2]]Ž¡‘ûç¤=–¹–CJoin“[Up2,“Stop2]Ž¡‘ûç¤=‘¹–Up2Ž¦‘íºâºThis–Tgivš¾9es“o˜v˜erall“con˜text“on“ëMvs“ºas:Ž¦‘ZÐëMCaseU–¹–alpha“Stop2Ž¡‘>
Ø(CMeet–¹–[UpUp2“[Up1“[]],“Up2])Ž¡¡‘ûç¤=–¹–CaseU“alpha“Stop2“Up2Ž¦‘íºâºThat's›þin•¾9tuitiv“ely˜correct:‘Ñwith˜no˜demand˜on˜the˜resultingŽ¡‘íºâëMIntº,‘RÐthere's–F„no“(ëMStop2º)“demand“on“the“incoming“list.‘¯ÿOth-Ž¡‘íºâerwise,‘Ûw•¾9e›è&ma“y˜ev‘ÿ|raluate˜the˜list˜to˜WHNF‘çð(ëMUp2º),‘Ûthat˜is,Ž¡‘íºâto–údthe“rst“constructor.‘uIt“is“a“pit¾9y“these“domains“can't“tellŽ¡‘íºâus–w?abAÇout“the“head-strictness“here:‘àGgiv¾9en“non-zero“demand,Ž¡‘íºâit's–~Ýobš¾9vious“w˜e“can“not“only“ev‘ÿ|raluate“to“the“rst“construc-Ž¡‘íºâtor,‘Êbut–û§can“also“ev‘ÿ|raluate“the“rst“elemen¾9t“of“the“list“if“it“isŽ¡‘íºânon-empt¾9y‘ÿ:«.ŽŸ™.‘íºâ¹3.6Ž‘G·Dening–LÎthe“abstract“interp¹™reterŽŸm‘íºâºSection–J3.5.4“inš¾9troAÇduced“the“con˜text-nding“function“ëMCº.“W‘ÿ:«eŽ¡‘íºâno•¾9w›‚Ÿaugmen“t˜this˜with˜ëMZº,˜the˜abstract˜in“terpreter˜itself.‘dPëMCŽ¡‘íºâºtak•¾9es›cJan“y˜Core˜expression,‘†æa˜con“text˜on˜that˜expression,‘†æandŽ¡‘íºâa–ˆ‚v›ÿ|rariable,‘¤­and“returns“the“resulting“con¾9text“on“the“v˜ariable.Ž¡‘íºâëMZ‘ø¯ºtak•¾9es›ø·an“y˜Core˜expression,‘þpand˜returns˜the˜abstract˜v‘ÿ|ralueŽ¡‘íºâof–Çthat“expression.‘XSince“the“forwš¾9ard“and“bac˜kw˜ard“
o˜ws“ofŽ¡‘íºâinformation–ÛÔare“heaš¾9vily“in˜tert˜wined,‘
tëMC›Û¡ºand“ëMZ˜ºare“m¾9utuallyŽ¡‘íºârecursiv¾9e.‘pIn–Ta“call“to“ëMC“ºorëMZŽŽŽ ý€’ç¤C–¹–x“[e]“rho“alphaŽ¤
’ç¤Z‘,Â[e]‘¹–rhoŽ©¦à’õºâx–³Uºis“a“v‘ÿ|rariable,›ÚÔëMe“ºis“a“Core“expression,˜ëMalpha“ºis“a“con¾9text,Ž¡’õºâand–ëMrho“ºis“an“en•¾9vironmen“t–binding“all“free“v‘ÿ|rariables“in“ëMe“ºtoŽ¡’õºâabstract–Æâv‘ÿ|ralues.‘1As“implemen¾9ted,‘óEbAÇoth“functions“carry“anŽ¡’õºâextra–.ßparameter“used“to“help“generate“new“v‘ÿ|rariable“names.Ž¡’õºâëMC‘Rºalso–Tcarries“the“domain“of“ëMx“ºso“it“can“generate“the“appro-Ž¡’õºâpriate–‡€bAÇottom“v‘ÿ|ralue“when“needed.‘rôRecall“also“that“a“CoreŽ¡’õºâexpression–·is“a“pair,‘Ééthe“rst“part“of“whicš¾9h“is“the“t˜ypAÇe“of“theŽ¡’õºâexpression,–Tand“the“second“the“expression“propAÇer.ŽŸ-’õºâ¹3.6.1Ž’úíDenition–LÎof“ëMZŽŸm’õºâºThe–:»abstract“v›ÿ|ralue“of“a“literal“is“a“v˜alue“in“the“appropriateŽ¡’õºâone-pAÇoin¾9t‘Tdomain.Ž¦’ç¤ëMZ–¹–(tau,“ALit“n)“rho‘	s,=“ANonRec“[]Ž¦’õºâºV‘ÿ:«ariables›Tha•¾9v“e˜their˜v‘ÿ|ralues˜loAÇok“ed˜up.Ž¦’ç¤ëMZ–¹–(tau,“AVar“v)“rho‘	s,=“rho“vŽ¦’õºâºApplications–÷are“a“little“more“tric¾9ky‘ÿ:«.‘\YFirst,‘ÚŸthe“abstractŽ¡’õºâv‘ÿ|ralue–æôof“the“function“is“created.‘‘PF‘ÿ:«rom“that,‘\the“abstract-Ž¡’õºâv‘ÿ|ralue-map–ô0is“extracted“using“ëMFvalAº,,‘úÑand“applied“to“the“ab-Ž¡’õºâstract–êv‘ÿ|ralue“of“the“argumenš¾9t“to“giv˜e“the“abstract“v‘ÿ|ralue“ofŽ¡’õºâthe‘Tresult.Ž¦’ç¤ëMZ–¹–(tau,“AAp“f“e)“rhoŽ¡’f=–¹–AbsAp“(FvalA“(Z“f“rho))“(Z“e“rho)Ž¦’õºâºLamš¾9bAÇda–üyterms“are“a“lot“more“tric˜ky‘ÿ:«.‘ÑÞLet“ëMa“ºand“ëMc“ºdenoteŽ¡’õºânew‘Tv‘ÿ|rariables.Ž¦’ç¤ëMZ–¹–(tau,“ALam“[x]“e)“rhoŽ¡’f=–¹–Fval“(CtxLam“c“(C“x“e“rho_c“(FncC“(CtxVar“c))))Ž¡’3'€(AbsLam–¹–a“(Z“e“rho_a))Ž¡’‡’whereŽ¡’)´Trho_c–¹–=“rho“{x“->“FncA“(CtxVar“c)}Ž¡’)´Trho_a–¹–=“rho“{x“->“AbsVar“a}Ž¦’õºâºAn–ëMFval“ºis“returned.‘!ŒIts“rst“compAÇonen¾9t“is“a“map“from“theŽ¡’õºâfunction–™ªconš¾9text“ëMc“ºon“ëM(\x.e)“ºto“the“con˜text“on“parameterŽ¡’õºâëMx.–i>ºBear“in“mind“that“ëMc“ºwill“get“bAÇound“to“a“term“of“theŽ¡’õºâform›eÉëM(Fnc–¹–aa“cc)º,‘yçwhere˜ëMaa˜ºis˜the˜abstract˜v‘ÿ|ralue˜suppliedŽ¡’õºâfor– ëMx,“ºand“ëMcc“ºis“the“conš¾9text“on“ëMe.“ºSo“the“con˜text“on“ëMxŽ¡’õºâºis–š¦found“bš¾9y“nding“ëMC‘šAºof“ëMx“ºin“ëMeº,‘ûúwith“ëMrho“ºaugmen˜ted“b˜yŽ¡’õºâbinding–ïTëMx“ºto“ëMaa,“ºthat“is,›öîto“ëMFncA–¹–(CtxVar“c)º,˜and–ïTwith“theŽ¡’õºâcon¾9text–
zon“the“b•AÇo“dy–
zof“the“function,–ëMeº,“equal–
zto“ëMccº,‘that“is,Ž¡’õºâëMFncC–¹–(CtxVar“c)º.Ž©
’õºâThe–ôJsecond“ëMFval“ºcompAÇonen¾9t“maps“the“abstract“v‘ÿ|ralue“ëMa“ºof“ëMxŽ¡’õºâºto–½µthe“abstract“v‘ÿ|ralue“of“ëMe.“ºThis“is“easily“done“b¾9y“computingŽ¡’õºâëMZ–Tºof“ëMeº,“with“ëMrho“ºmoAÇdied“to“bind“ëMx“ºto“ëMAbsVar‘¹–aº.Ž¦’õºâThe–TëMACase“ºcase“is“quite“easy:Ž©¦à’ç¤ëMZ–¹–(tau,“ACase“sw“[(cname1,“(pars1,“rhs1))“...Ž¡’Xô0(cnamen,–¹–(parsn,“rhsn))])Ž¡’frhoŽ¡’f=–¹–AMeet“[Z“rhs1“rho1“...“Z“rhsn“rhon]Ž¦’õºâºThe–xaugmenš¾9ted“en˜vironmen˜ts“ëMrhoi“(1–¹–<=“i“<=“n)–xºare“ob-Ž¡’õºâtained– Rbš¾9y“extending“ëMrho“ºto“pro˜vide“bindings“for“ëMparsi“ºinŽŽŽŽŽŸ’åä15ŽŽŒ‹ò •ºâ ý? £ ý€‘íºâºview–Œ‡of“the“v‘ÿ|ralue“of“ëMZ–¹–sw“rhoº,‘êSusing–Œ‡the“methoAÇd“of“sec-Ž¤
‘íºâtion‘T3.5.3.ŽŸ
‘íºâFinally‘ÿ:«,‘¾Pthe–¨ëMAConstr“ºcase.‘ø.Although“sections“3.5.1“and“3.5.2Ž¡‘íºâcompletely–rdoAÇcumenš¾9t“abstract“v‘ÿ|ralue“and“con˜text“
o˜wsŽ¡‘íºâthrough–ŽÌconstructors,‘í*wš¾9e“as“y˜et“ha˜v˜e“no“w˜a˜y“of“creatingŽ¡‘íºâabstract–bûv‘ÿ|ralues“for“constructors.‘fStarting“from“a“generalŽ¡‘íºâconstructor‘TapplicationŽ¤\‘ûç¤ëMC–¹–e1“...“enŽ¡‘íºâºw¾9e–Tdesire“to“buildŽ¡‘ûç¤ëMFval–¹–(\c1“->“f1“(FncC^n“c1))Ž¤
‘‡’(\a1–¹–->“Fval“(\c2“->“f2“(FncC^(n-1)“c2))Ž¡‘‡’(\a2–¹–->“...Ž¡‘9TB...Ž¡‘9TB...–¹–->“Fval“(\cn“->“fn“(FncC^1“cn))Ž¡‘rJ(\an–¹–->“aresultant)“...))Ž©\‘íºâºwhere–-ñëMFncC^i‘¹–e“ºmeans“ëMFncC‘-êºapplied“ëMi“ºtimes“to“ëMe.“ºObserv¾9eŽ¡‘íºâthat–j¢eac¾9h“use“of“ëMFncC‘jŒºhere“is“of“the“form“ëMFncC^i‘¹–cj“ºwhereŽ¡‘íºâëMi–¹–+“j“==“n“+“1º,‘»Fand–šso“all“these“terms“simply“denote“theŽ¡‘íºâcon¾9text–`on“the“result“of“the“constructor“application.‘üÇWhatŽ¡‘íºâsection–P3.5.2“proš¾9vides“is“a“w˜a˜y“to“compute“the“ëMn“ºcon˜textŽ¡‘íºâmaps,‘ý÷ëMf1–¹–...“fnº.‘±-Section–œ>3.5.1“generates“a“term“of“theŽ¡‘íºâformŽ¦‘ûç¤ëM\a1–¹–...“\an“->“aresultantŽ¦‘íºâºand›+ÁbAÇet•¾9w“een˜them,‘ñ\that's˜all˜that's˜needed.‘
_¸As˜thisŽ¡‘íºâis–ìÈrather“confusing,‘¢¤here's“a“couple“of“examples.‘¢ËF‘ÿ:«orŽ¡‘íºâëM(:)–¹–::“Int“->“[Int]“->“[Int]:Ž¦‘ûç¤Fval–¹–(\c1“->“DropUU“1“(FncC“(FncC“c1)))Ž¡‘‡’(\a1–¹–->“Fval“(\c2“->“ZapWHNF“(FncC“c2))Ž¡‘Pô0(\a2–¹–->“ARec“[ANonRec“[]]))Ž¦‘íºâºF‘ÿ:«or‘TëM(,)–¹–::“Int“->“Int“->“(Int,“Int)º:Ž¦‘ûç¤ëMFval–¹–(\c1“->“DropU“1“(FncC“(FncC“c1)))Ž¡‘‡’(\a1–¹–->“Fval“(\c2“->“DropU“2“(FncC“c2))Ž¡‘Pô0(\a2–¹–->“ANonRec“[ANonRec“[],Ž¡’¡G&ANonRec‘¹–[]]))ŽŸìù‘íºâ¹3.6.2Ž‘úíDenition–LÎof“ëMCŽŸm‘íºâºPropagation–Tof“a“conš¾9text“on˜to“a“constan˜t“has“no“eect:Ž¦‘ûç¤ëMC–¹–x“(tau,“ALit“n)“rho“alphaŽ¡‘
f=–¹–bot“(domain-of-x)Ž¦‘íºâºThe–Tv‘ÿ|rariable“case“is:Ž¦‘ûç¤ëMC–¹–x“(tau,“AVar“v)“rho“alphaŽ¡‘
f=–¹–if‘æXx“==“vŽ¡‘‡’then‘	s,alphaŽ¡‘‡’else‘	s,bot‘¹–(domain-of-x)Ž¦‘íºâºAs–ØbšAÇefore,‘9the“application“and“lam¾9b˜da“cases“are“a“bit“mindŽ¡‘íºâbAÇending.Ž¦‘ûç¤ëMC–¹–x“(tau,“ALam“[y]“e)“rho“alphaŽ¡‘
f=–¹–C“x“e“rho2“(FncC“alpha)Ž¡‘‡’whereŽ¡‘!´Trho2–¹–=“rho“{y“->“FncA“alpha}ŽŽŽ ý€’õºâºHere,‘9OëMalpha–2ºis“a“function“con¾9text“bAÇeing“applied“to“ëM(\y.e).Ž¤
’õºâºAssuming–@ßthat“ëMx“ºand“ëMy“ºare“not“the“same“v‘ÿ|rariable“(theŽ¡’õºâlamš¾9bAÇda-lifter–Ðassures“this),‘ÿIcon˜text“on“ëMx“ºin“ëM(\y.e)“ºcan“bAÇeŽ¡’õºâfound–	Ïfrom“the“con¾9text“on“ëMx“ºin“ëMeº.‘™Since“ëMalpha“ºis“a“functionŽ¡’õºâconš¾9text,‘€¢ëMFncA‘¹–alpha–k,ºis“an“abstract“v‘ÿ|ralue“whic˜h“ëMy“ºis“bAÇoundŽ¡’õºâto,–Tgenerating“ëMrho2.“FncC‘¹–alpha“ºis“the“con¾9text“on“ëMe“ºitself.Ž©ÐO’ç¤ëMC–¹–x“(tau,“AAp“f“e)“rho“alphaŽ¡’f=–¹–CJoin“[“C“x“f“alpha_f“rho,Ž¡’ATBC–¹–x“e“alpha_e“rho“]Ž¡’‡’whereŽ¡’)´Talpha_f–¹–=“Fnc“(Z“e“rho)“alphaŽ¡’)´Talpha_e–¹–=“CtxAp“(FvalC“(Z“f“rho))“alpha_fŽ¦’õºâºT‘ÿ:«o–·Òdeal“with“applications,‘ʆobservš¾9e“that“ëMx“ºma˜y“ošAÇccur“in“b˜othŽ¡’õºâthe–ª°function“and“argumenš¾9t“expressions,‘Ðso“w˜e“need“to“col-Ž¡’õºâlect–¿up“the“con¾9texts“from“ëMf“ºand“ëMeº,‘ÐUand“\add“them“together"Ž¡’õºâusing–©ëMCJoinº.‘ópThe“only“problem“is“guring“out“what“con-Ž¡’õºâtext–v®propagates“to“ëMf“ºand“ëMeº.‘@~Recall“that“a“function“con-Ž¡’õºâtext–ú˜consists“of“the“abstract“v‘ÿ|ralue“of“the“argumen¾9t,‘ÿñand“theŽ¡’õºâconš¾9text–x1on“the“result.‘EHence,‘Ðèthe“con˜text“on“ëMf“ºm˜ust“bAÇeŽ¡’õºâëMFnc–¹–(Z“e“rho)“alphaº.‘PThe–dôcon¾9text“on“ëMe“ºis“equal“to“theŽ¡’õºâconš¾9text–lythat“ëMf“ºw˜ould“propagate“to“its“argumen˜t,‘ÂBand“w˜eŽ¡’õºâknoš¾9w–Ôthat“the“con˜text“on“ëMf“ºis“ëMalpha_f.“ºSo,‘C4w˜e“build“theŽ¡’õºâabstract–í˜in¾9terpretation“for“ëMf“ºwith“ëMZ–¹–f“rhoº,‘õŠextract–í˜the“con-Ž¡’õºâtext–ìUmap“using“ëMFvalCº,“and“apply“that“to“ëMalpha_fº.‘ÆAll“told,Ž¡’õºâthat's‘TëMCtx–¹–(FvalC“(Z“f“rho))“alpha_fº.ŽŸ
’õºâDue–ëWto“the“heroic“eorts“of“section“3.5.4,‘ó½the“rather“compli-Ž¡’õºâcated–TëMcase“ºclause“is“stated“quite“succinctly:Ž¦’ç¤ëMC–¹–x“(tau,“ACase“sw“[(cname1,“(pars1,“rhs1))“...Ž¡’bg\(cnamen,–¹–(parsn,“rhsn))])Ž¡’Íürho‘¹–alphaŽ¡’f=–¹–CJoin“[“C“x“sw“rho“alpha_sw,Ž¡’ATBCMeet–¹–[“C“x“rhs1“rho1“alpha“...Ž¡’g òC–¹–x“rhsn“rhon“alphaŽ¡’]­Æ]Ž¡’7á]Ž¦’õºâºHere,‘Ý"ëMalpha_sw–µ,ºis“the“conš¾9text“on“ëMsw,“ºgiv˜en“ëMalpha“ºcon˜textŽ¡’õºâon–¦Åthe“ëMcase“ºexpression“itself,‘¼âas“computed“b¾9y“the“methoAÇd“ofŽ¡’õºâsection‘T3.5.4.Ž©
’õºâAs–¸…bAÇefore,‘Ëthe“ëMrhoi“(1–¹–<=“i“<=“n)–¸…ºare“obtained“b¾9y“extend-Ž¡’õºâing–œëMrho“ºto“pro¾9vide“bindings“for“ëMparsi“ºin“view“of“the“v‘ÿ|ralueŽ¡’õºâof›TëMZ–¹–sw“rhoº,˜using˜the˜methoAÇd˜of˜section˜3.5.3.Ž¦’õºâV‘ÿ:«ariable–ëMx“ºcan“appšAÇear“in“b˜oth“the“switc¾9h“expression,‘J[andŽ¡’õºâanš¾9y–&¯of“the“alternativ˜es.‘
P€T‘ÿ:«o“deal“with“the“former,‘«con-Ž¡’õºâtext–»on“ëMsw“ºis“computed“as“pAÇer“section“3.5.4,‘äand“this“con-Ž¡’õºâtext–b0propagated“inš¾9to“ëMsw.“ºCon˜text“for“ëMx“ºin“alterativ˜e“ëMi“ºisŽ¡’õºâëMC–¹–x“rhsi“rhoi“alphaº,‘Ìpbut–§Ñsince“wš¾9e“can't“sa˜y“whic˜h“alter-Ž¡’õºâativš¾9e–:Ÿwill“actually“bAÇe“selected,‘ƒñw˜e“m˜ust“tak˜e“the“greatestŽ¡’õºâlo•¾9w“er–è'bAÇound“o•¾9v“er–è'all“alternativš¾9es.‘”éFinally‘ÿ:«,‘Ûthe“switc˜h“andŽ¡’õºâalterativ•¾9e›àcon“texts˜are˜once˜again˜\added"˜using˜ëMCJoinº.‘IAsŽ¡’õºâwith–5‘the“ëMZ‘5‰ºclause“for“ëMcase“ºrho“is“extended“to“pro¾9vide“bind-Ž¡’õºâings–Tfor“the“v‘ÿ|rariables“assoAÇciated“with“eac¾9h“constructor.Ž¦’õºâFinally‘ÿ:«,‘Dµthe–ëMAConstr“ºcase.‘ôŒAll“the“actual“w¾9ork“of“dealingŽ¡’õºâwith–ÚÞconš¾9text“
o˜w“through“constructors“is“done“in“the“corre-Ž¡’õºâspAÇonding–?³ëMZ‘?¨ºclause.‘›All“wš¾9e“need“do“here“is“observ˜e“that“ëMx“ºisŽ¡’õºânevš¾9er–Tfree“in“an˜y“constructor,“and“so“return“zero“con˜text:ŽŸÐO’ç¤ëMC–¹–x“(tau,“AConstr“c)“rho“alphaŽ¡’f=–¹–bot“(domain-of-x)ŽŽŽŽŽŸ’åäº16ŽŽŒ‹š •ºâ ý? £ ý€‘íºâ¹4Ž‘ü”The–LÎterm“rewriting“systemŽŸ†´‘íºâ4.1Ž‘G·IntroFfductionŽŸm‘íºâºF‘ÿ:«or–*eacš¾9h“Core“function,‘o=the“abstract“in˜terpreter“proAÇducesŽ¤
‘íºâan–¡EëMAbsVal“ºterm.‘õÀRecursivš¾9e“groups“of“terms“require“xpAÇoin˜t-Ž¡‘íºâing,‘-jwhicš¾9h–(™is“done“in“a“straigh˜tforw˜ard“manner.‘V>The“initialŽ¡‘íºâappro¾9ximation–vÿfor“a“function“in“domain“ëMD‘v¤ºis“ëMatop(D)º,“soŽ¡‘íºâthe–héxpšAÇoin¾9ting“pro˜duces“the“greatest“xp˜oin¾9t.‘/Although“itŽ¡‘íºâmighš¾9t–ôÒseem“a“little“un˜usual“to“seek“the“greatest“xed“pAÇoin˜t,Ž¡‘íºâbAÇear–»”in“mind“that“this“approacš¾9h“represen˜ts“starting“o“fromŽ¡‘íºâa–)ôdangerous“v‘ÿ|ralue,‘YëMatop(D)‘)¸ºand“iterating“one's“w•¾9a“y–)ôto“safet¾9y‘ÿ:«.Ž¡‘íºâIn–Ôôforwš¾9ard“analyses“in“the“st˜yle“of“[Sew91Ž‘/],‘Ûdanger“is“rep-Ž¡‘íºâresen•¾9ted›I:b“y˜the˜least˜pAÇoin“t˜in˜the˜domains,‘V3and˜xpAÇoin“tingŽ¡‘íºâyields–³/the“least“xed“pAÇoinš¾9t.‘öIn“an˜y“case,‘Ú¦this“discussion“isŽ¡‘íºârather–W¨academic,‘h>since“w¾9e“can“claim“to“bšAÇe“lo˜oking“for“leastŽ¡‘íºâxpšAÇoin¾9ts–¯Uhere“to˜o“simply“b¾9y“turning“all“the“domains“upside-Ž¡‘íºâdo¾9wn–pñ{“as“they“are“nite,›‡Ùcomplete“lattices,˜sucš¾9h“a“tric˜k“isŽ¡‘íºâquite‘Tallo•¾9w“able.Ž©
‘íºâThe–‘)term“rewriter“exists“bAÇecause“of“the“need“to“compare“ap-Ž¡‘íºâproš¾9ximations–Xduring“xpAÇoin˜ting.‘é}F‘ÿ:«or“non-recursiv˜e“terms,Ž¡‘íºâthere–ºóis,›Ístrictly“spAÇeaking,˜no“need“to“use“the“rewriter.‘þPNev-Ž¡‘íºâertheless,‘‘bAÇecause–²Rwhat“emerges“from“the“abstract“in¾9ter-Ž¡‘íºâpreter–fˆis“usually“grossly“redundan¾9t,‘ºÔall“terms“are“sub‘ƒŽjectŽ¡‘íºâto–JBrewriting,‘—}and“the“recursivš¾9e“ones“are“subsequen˜tly“x-Ž¡‘íºâpAÇoin¾9ted.Ž¦‘íºâWhat–•the“rewriter“došAÇes“is“to“transform“eac¾9h“p˜ossible“termŽ¡‘íºâinš¾9to–Â}a“normal“form,‘Ósuc˜h“that“seman˜tically“equiv‘ÿ|ralen˜t“formsŽ¡‘íºâmap–9ðto“the“same“normal“form.‘ŠEDetection“of“xed“pAÇoin¾9tsŽ¡‘íºâis–;Úthen“a“simple“matter“of“detecting“synš¾9tactic“equalit˜y“ofŽ¡‘íºâthe–normal“forms.‘%øF›ÿ:«or“higher“order“terms,‘YLunfortunately˜,Ž¡‘íºâthis–ximplies“an“abilitš¾9y“to“solv˜e“the“halting“problem.‘D‹W‘ÿ:«eŽ¡‘íºâtherefore–Vdeal“with“higher“order“functions“as“describAÇed“inŽ¡‘íºâsection–j¦5,‘ŒÉand“restrict“ourselv¾9es“to“generating“unique“normalŽ¡‘íºâforms–)Ôfor“the“abstract“in¾9terpretations“of“rst“order“functions,Ž¡‘íºâsomething–Twhic¾9h“is,“fortunately‘ÿ:«,“decidable.Ž¦‘íºâThe–Ñáterm“rewriter“propšAÇer“is“an“elab˜orate“system“whic¾9h“gen-Ž¡‘íºâerates–a,normal“forms“bš¾9y“applying“man˜y“loAÇcal“transformationsŽ¡‘íºâto–v¥a“term.‘@bWhen“no“more“transformations“can“bAÇe“applied,Ž¡‘íºâthe–Mäterm“is“deemed“to“bAÇe“in“normal“form.‘Æ!Eac¾9h“kind“of“al-Ž¡‘íºâlo•¾9w“able–jÓtransformation“is“encapsulated“in“a“so-called“rewriteŽ¡‘íºârule.‘óÜEacš¾9h–]#rule“m˜ust“implemen˜t“a“seman˜tically“in˜v‘ÿ|rarian˜tŽ¡‘íºâtransformation.‘	»¸Section–õ3.2“in¾9troAÇduced“a“few“equalities,Ž¡‘íºâwhicš¾9h,–Twhen“giv˜en“a“directionalit˜y‘ÿ:«,“bAÇecome“rewrite“rules:Ž©ÐO‘ûç¤ëMFncA–¹–(Fnc“a“c)‘Ÿî===>‘,ÂaŽ¡‘ûç¤FncC–¹–(Fnc“a“c)‘Ÿî===>‘,ÂcŽ¡‘ûç¤FvalA–¹–(Fval“c“a)–,Â===>“aŽ¡‘ûç¤FvalC–¹–(Fval“c“a)–,Â===>“cŽ¦‘íºâºMost–(×rules“are“complicated“b¾9y“the“presence“of“side-Ž¡‘íºâconditions:Ž¦‘ûç¤ëMFnc–¹–(FncA“c1)“(FncC“c2)–,Â===>“c1Ž¡‘ûç¤providedŽ¡‘
fc1–¹–==“c2Ž¦‘íºâºThese–6yexamples“illustrate“the“problem“of“whether“to“simplifyŽ¡‘íºâterms–~starting“from“the“lea•¾9v“es–~(innermost-rst)“or“from“theŽ¡‘íºâroAÇot–MÁ(outermost-rst).‘Å·Since,››Üin“the“second“example,˜theŽ¡‘íºârule–F¾only“applies“if“subterms“ëMc1“ºand“ëMc2“ºare“pro¾9v‘ÿ|rably“equal,Ž¡‘íºâinnermost-rst–Æ9rewriting“seems“necessary‘ÿ:«.‘	/But“the“sameŽ¡‘íºâstrategy–Jµapplied“to“ëMFvalC–¹–(Fval“c“a))–Jµºcould“w¾9aste“a“lotŽŽŽ ý€’õºâof–Û¯eort“simplifying“ëMa,“ºonly“to“throš¾9w“it“a˜w˜a˜y‘ÿ:«,‘ç7so“outermost-Ž¤
’õºârst–Tmighš¾9t“giv˜e“bšAÇetter“p˜erformance.Ž©
’õºâProš¾9viding–ÚDthe“rules“are“nitely“con
uen˜t“and“terminating,Ž¡’õºâbAÇoth–:‡approacš¾9hes“still“giv˜e“the“same“normal“forms.‘ŒObserv˜eŽ¡’õºâho•¾9w“ev“er–˜ðthat“whatevš¾9er“approac˜h“is“used,‘ù×m˜ultiple“passesŽ¡’õºâo•¾9v“er–'the“tree“will,›Zin“general,˜bAÇe“needed“to“arriv¾9e“at“nor-Ž¡’õºâmal–ÿçform.‘Ü)The“decision“can“therefore“bAÇe“based“purely“onŽ¡’õºâwhic•¾9hev“er›žœsc“heme˜giv“es˜b•AÇetter˜p“erformance.‘¸HExp“erimen¾9ta-Ž¡’õºâtion›~"sho•¾9w“ed˜that˜outermost-rst˜rewriting˜w“as˜up˜to˜tenŽ¡’õºâtimes›ZDslo•¾9w“er˜than˜innermost-rst˜for˜realistically˜sized˜termsŽ¡’õºâemitted–•?bš¾9y“the“abstract“in˜terpreter.‘œ1Although“it“w˜ould“bAÇeŽ¡’õºâfoAÇolish–Boto“claim“that“this“is“alw•¾9a“ys–Boso,‘lthe“evidence“suggestedŽ¡’õºâan–b innermost-rst“scš¾9heme“w˜ould“usually“bAÇe“m˜uc˜h“quic˜k˜er,‘…÷soŽ¡’õºâan–Tinnermost-rst“sc•¾9hemeŸü-=ó*¹Aa¨cmr6Õ1ŽŽ‘?ûºw“as‘Tadopted.ŽŸ5’õºâ¹4.2Ž’G·P•¹™erfo“rming–LÎa“single“simplication“passŽŸm’õºâºBecause–¿¾the“ëMAbsVal“ºand“ëMContext“ºtš¾9ypAÇes“are“m˜utually“re-Ž¡’õºâcursivš¾9e,‘ÖËthe–°term“rewriter“propAÇer“consists“of“t˜w˜o“functionsŽ¡’õºâof–ÂGtš¾9ypAÇe“ëMAbsVal–¹–->“AbsVal–ÂGºand“ëMContext–¹–->“Contextº,‘í„eac˜hŽ¡’õºâof–qwhicš¾9h“pAÇerforms“m˜ultiple“innermost-rst“simplicationŽ¡’õºâpasses–N¦with“an“auxiliary“function.‘Ú6When“stabilitš¾9y“is“reac˜hed,Ž¡’õºâit–gômeans“normal“form“has“bAÇeen“ac•¾9hiev“ed.‘OThis–gôsection“dis-Ž¡’õºâcusses–ÛWhoš¾9w“those“auxiliary“functions“w˜ork.‘nxF‘ÿ:«or“simplicit˜y‘ÿ:«,Ž¡’õºâthey–¬!are“treated“as“a“single“function,›ÑÔcalled“ëMsimpº,˜w¾9orkingŽ¡’õºâon–Tthe“union“of“ëMAbsVal“ºand“ëMContextº,“called“ëMTermº.Ž¦’õºâT‘ÿ:«o–iþmaximise“pAÇerformance,‘)eac¾9h“pass“of“ëMsimp“ºtries“to“do“asŽ¡’õºâm•¾9uc“h–éÑas“pšAÇossible,‘ðso“as“to“minimise“the“n•¾9um“b˜er–éÑof“passesŽ¡’õºârequired.‘€AMeasuremen•¾9ts›6šsho“w“ed˜the˜v‘ÿ|rast˜ma‘ƒŽjorit“y˜of˜termsŽ¡’õºâreac¾9h–Å#normal“form“in“one“pass,‘ñand“no“term“has“bAÇeen“ob-Ž¡’õºâserv¾9ed–Tto“require“more“than“three“passes.Ž¦’õºâThe–L?individual“rewrite“rules“are“classied“in¾9to“groups“(rep-Ž¡’õºâresenš¾9ted–Åïas“lists)“b˜y“the“roAÇot“sym˜bAÇol“of“the“term“whic˜h“theyŽ¡’õºârewrite.‘¼±The–J¿mecš¾9hanism“whic˜h“directs“the“application“ofŽ¡’õºârewrite–ðÖrules“ensures“that“eac¾9h“rule“is“only“applied“to“termsŽ¡’õºâpšAÇossessing–xÈthe“relev‘ÿ|ran¾9t“ro˜ot“sym•¾9b˜ol.‘FÌEac“h–xÈrule“is“imple-Ž¡’õºâmenš¾9ted–Tas“a“function“of“t˜ypAÇe“ëMTerm–¹–->“Maybe“Termº,‘Twhere:Ž¤ÐO’ç¤ëMdata–¹–Maybe“a“=“Nothing“|“Just“aŽ¡’õºâºAs–•bAÇecomes“clear“shortly‘ÿ:«,‘"wš¾9e“need“to“kno˜w“whether“the“ap-Ž¤
’õºâplication–q¡of“a“rewrite“rule“has“had“an¾9y“eect.‘1VW‘ÿ:«e“couldŽ¡’õºâmak•¾9e›ì6eac“h˜rule˜ha“v“e˜t“ypAÇe˜ëMTerm–¹–->“Term˜ºand˜compare˜theŽ¡’õºâterm–­
bšAÇefore“and“after“application,‘öbut“this“seems“ab˜om-Ž¡’õºâinably–.Œinecienš¾9t,‘tÚbAÇecause“the“rule“itself“\kno˜ws"“when“itŽ¡’õºâhas–¹`made“a“c•¾9hange.‘”Therefore,‘âcw“e–¹`encoAÇde“that“kno¾9wledgeŽ¡’õºâin–³Ythe“return“v‘ÿ|ralue“bš¾9y“passing“bac˜k“ëMNothing“ºif“there“is“noŽ¡’õºâc•¾9hange.‘ÖŽObserv“e–S^that“the“returned“ëMMaybe‘¹–Term“ºv‘ÿ|ralue“is“in-Ž¡’õºâstan•¾9tly›¨“disassem“bled˜using˜a˜Hask“ell˜case˜expression,‘¾Sto˜ndŽ¡’õºâout–¹whether“the“rule“has“succeeded.‘ä Therefore,‘>a“Hask¾9ellŽ¡’õºâimplemen•¾9tation›íŽwhic“h˜returns˜constructors˜in˜registers,‘õ‚lik“eŽ¡’õºâGlasgo•¾9w›—¦Hask“ell˜[PJ92Ž‘L],‘¸:nev“er˜actually˜builds˜the˜ëMNothingŽ¡’õºâºor–TëMJust“ºclosure“in“the“heap,“a“pleasing“little“eciency‘ÿ:«.Ž¦’õºâLet–9oëMt“ºdenote“a“term,‘‚uand“ëMrulesfor(t)“ºdenote“the“list“ofŽ’õºâŸ@‰ff_ÿ Ÿ×‘
r}Ÿüûró†›Zcmr5°1ŽŽ‘Y±One–5of“the“sharp7er“wits“in“the“functional“programming“commÈãu-Ž¤nitšÈãy‘ÿZª,–±Èon“reading“an“early“draft,“commen˜ted:ŽŸ‘€HošÈãw–%could“y˜ou“let“suc˜h“a“w˜onderful“example“of“self-Ž¡‘€reference–Aègo“bšÈãy“unremark˜ed?‘hðI‘AÌthough˜t“it“w˜as“absolutelyŽ¡‘€marvšÈãelous–:that“y˜ou“decided“to“use“an“innermost-rstŽ¡‘€scšÈãheme–A¥in“the“term“rewriter“whic˜h“is,›Xafter“all,˜the“wholeŽ¡‘€p7oinÈãt–øof“Anna's“existance“in“the“Real“W‘ÿZªorld“outside“it-Ž¡‘€self‘!Ž¡ŽŽŽŽŸ’åäº17ŽŽŒ‹²È •ºâ ý? £ ý€‘íºâºrewrite–Ðœrules“relev‘ÿ|ranš¾9t“to“the“roAÇot“sym˜bAÇol“of“ëMt.“simp(t)“ºisŽ¤
‘íºâcomputed–Tas“follo¾9ws:Ž©ÐO‘ûç¤ëMsimp(t)Ž¡‘
f=‘¹–schedule(t_inner_simp)Ž¡‘‡’whereŽ¡‘!´Tt_inner_simpŽ¡‘/á=–¹–t“with“simp“applied“to“t's“subtermsŽ¡¡‘ûç¤schedule(t)Ž¡‘
f=–¹–rewrite_with(rulesfor(t),“t)Ž¡¡‘ûç¤rewrite_with([],‘¹–t)Ž¡‘
f=‘¹–tŽ¡¡‘ûç¤rewrite_with((rule:rules),‘¹–t)Ž¡‘
f=–¹–case“(rule“t)“ofŽ¡‘!´TNothing–¹–->“rewrite_with(rules,t)Ž¡‘!´TJust–¹–t2“->“schedule(t2)Ž¦‘íºâºFirstly‘ÿ:«,›6$ëMtº's–üasubterms“are“simplied,˜giving“ëMt_inner_simp.Ž¡‘íºâºThis–"óis“passed“to“inš¾9termediary“ëMscheduleº,‘f[whic˜h“examinesŽ¡‘íºâthe–ƒ¼rošAÇot“sym¾9b˜ol“to“determine“the“relev‘ÿ|ran¾9t“list“of“rewriteŽ¡‘íºârules.‘)OëMschedule–ÄIºpasses“the“rules“and“its“argumen¾9t“toŽ¡‘íºâëMrewrite_withº,‘™¬whic•¾9h›zÂw“orks˜its˜w“a“y˜through˜the˜list˜of˜rules.Ž¡‘íºâIf–2ºit“runs“out“of“rules,‘`
it“simply“returns“the“term.‘ÐçBut“if“thereŽ¡‘íºâis–Þ a“rule,‘é‘it“is“applied“to“the“term.‘
4This“either“has“no“eect,Ž¡‘íºâin–÷whic¾9h“case“the“next“rule“is“tried,‘/‚or“it“proAÇduces“a“newŽ¡‘íºâterm–'eëMt2º.‘R¢Noš¾9w“ëMt2“ºma˜y“w˜ell“ha˜v˜e“a“dieren˜t“roAÇot“sym˜bAÇol,Ž¡‘íºâwhic•¾9h›¶Ýw“ould˜in“v‘ÿ|ralidate˜all˜the˜remaining˜rules.‘üóSo˜rewritingŽ¡‘íºâof–TëMt2“ºis“con•¾9tin“ued›Tb“y˜passing˜it˜bac“k˜to˜ëMscheduleº.ŽŸ
‘íºâThe–mnet“eect“of“ëMschedule(t)“ºis“thš¾9us“to“k˜eep“applyingŽ¡‘íºârewrite–¯„rules“to“the“roAÇot“of“ëMt“ºun¾9til“no“applicable“rules“canŽ¡‘íºâbšAÇe–5¢found.‘
}ZThis“pro˜cess“deals“prop˜erly“with“c¾9hanges“inŽ¡‘íºâthe–ôrošAÇot“sym•¾9b˜ol.‘¸®Observ“e–ôthat“the“call“to“ëMschedule“ºfromŽ¡‘íºâëMrewrite_with–HSºis“not“necessary“for“correctness.‘µmW‘ÿ:«e“couldŽ¡‘íºâsimply–+´return“ëMt2“ºat“this“pAÇoinš¾9t.‘ÎWhat“this“w˜ould“mean“is“thatŽ¡‘íºâanš¾9y–8ípAÇossible“rewrites“of“ëMt2“ºw˜ould“bAÇe“dela˜y˜ed“un˜til“the“nextŽ¡‘íºâsimplication–7Îpass,‘drather“than“bAÇeing“done“straighš¾9t“a˜w˜a˜y‘ÿ:«.‘Ò™SoŽ¡‘íºâomitting–~the“re-sc¾9hedule“implies“more“simplication“passesŽ¡‘íºâand–Ta“serious“loss“of“eciency‘ÿ:«.ŽŸ5‘íºâ¹4.3Ž‘G·Dealing–LÎwith“lambFfdas“and“applicationsŽŸm‘íºâºThe–éŸpresence“of“ëMAbsLamº,‘^²ëMAbsAp“ºand“ëMAbsVar“ºterms“in¾9tro-Ž¡‘íºâduces–Ö?the“need“to“pšAÇerform“lam¾9b˜da“calculus-lik¾9e“substi-Ž¡‘íºâtution.‘*What–çfollo¾9ws“applies“equally“to“the“dual“con-Ž¡‘íºâstructions–°ªëMCtxLamº,‘—ëMCtxAp“ºand“ëMCtxVarº.‘îsIn“particular,Ž¡‘íºâëMsimp–|Uºneeds“to“bAÇe“able“to“deal“with“terms“of“the“formŽ¡‘íºâëM(AbsAp–¹–(AbsLam“v“e)“a)º.‘pNaturally‘ÿ:«,‘‚wš¾9e–Ûàcan“reac˜h“di-Ž¡‘íºârectly–Béfor“the“blunderbuss“solution:‘
w™devise“a“functionŽ¡‘íºâëMsubst(e,v,a)–Xžºto“replace“free“oAÇccurrences“of“ëMv“ºin“ëMe“ºwith“ëMa,Ž¡‘íºâºand–Templo¾9y“it“in“the“rewrite“rule:Ž¦‘ûç¤ëMAbsAp–¹–(AbsLam“v“e)“a–,Â===>“subst(e,v,a)Ž¦‘íºâºTwš¾9o–Adefects“are“apparen˜t.‘ ðFirstly‘ÿ:«,‘L‰since“ëMsimp“ºis“committedŽ¡‘íºâto–8Ðdoing“innermost-rst“simplication,‘dëbAÇoth“function“and“ar-Ž¡‘íºâgumenš¾9t–B–are“simplied“extensiv˜ely“bšAÇefore“substitution“b˜egins.Ž¡‘íºâOur–­ßhands“are“noš¾9w“tied:‘èµw˜e“cannot“mak˜e“the“lam˜bAÇda/applyŽ¡‘íºâterm–ãereduction“an¾9y“lazier.‘†¤Ineciency“is“the“second“com-Ž¡‘íºâplain•¾9t.‘0‹This›q]sc“heme˜demands˜a˜complete˜substitution˜passŽ¡‘íºâo•¾9v“er–TëMe“ºfor“evš¾9ery“argumen˜t.ŽŽŽ ý€’õºâAn–R±altogether“nicer“solution“is“to“forget“abAÇout“ëMsubst“ºand“theŽ¤
’õºârewrite–»drule.‘ŸInstead,‘äèwš¾9e“equip“ëMsimp“ºwith“an“en˜vironmen˜tŽ¡’õºâëMenv–?oºwhic¾9h“binds“ëMAbsº-v›ÿ|rariables“to“v˜alues.‘šÀNo•¾9w,‘‰õgiv“e‘?oëMsimpŽ¡’õºâºa–©couple“of“spAÇecial“cases.‘ØöThese“omit“the“usual“simplica-Ž¡’õºâtion–›·of“subterms,‘½Oand“bš¾9ypass“the“general“rewriting“mec˜ha-Ž¡’õºânism.‘¥6In–˜Athis“w•¾9a“y›˜Aw“e˜regain˜precise˜con“trol˜o“v“er˜the˜orderŽ¡’õºâof–ý×rewrites,‘‰and“no“separate“substitution“passes“are“needed.Ž¡’õºâV‘ÿ:«ariables–Tare“simply“loAÇok¾9ed“up:Ž¤ÐO’ç¤ëMsimp–¹–env“(AbsVar“v)“=“env“vŽ¡’õºâºOn–Ýencounš¾9tering“ëM(AbsAp–¹–f“a)º,‘îw˜e–Ýneed“to“try“and“turn“ëMfŽ¤
’õºâºinš¾9to– ³an“ëM(AbsLam–¹–v“e)º.‘>The– ³ob˜vious“w˜a˜y“to“do“this“is“b˜yŽ¡’õºâapplying–ôÒëMsimp“ºto“ëMfº,‘ûSbut“this“wš¾9ould“bAÇe“a“big“w˜aste“of“time“ifŽ¡’õºâëMf–×ãºis“in“that“form“already‘ÿ:«.‘õSo“there“is“a“spAÇecial“c•¾9hec“k–×ãfor“thisŽ¡’õºâcase.‘‰¼The›ämen•¾9vironmen“t˜is˜then˜augmen“ted˜with˜a˜bindingŽ¡’õºâfor–³¹ëMvº,‘ÛRand“simplication“con•¾9tin“ues–³¹with“ëMeº.‘÷žBy“c¾9hoAÇosing“toŽ¡’õºâbind–íÉëMv“ºto“ëMa“ºor“ëMsimp–¹–env“aº,‘õ²w¾9e–íÉcan“again“v‘ÿ|rary“the“strictnessŽ¡’õºâof–y;the“scš¾9heme.‘H$The“latter“c˜hoice“giv˜es“bšAÇetter“p˜erformance,Ž¡’õºâso–Tthe“spAÇecial“case“for“ëM(AbsAp–¹–f“a)‘Tºis:Ž©ÐO’ç¤ëMsimp–¹–env“(AbsAp“f“a)Ž¡’f=–¹–let“sa“=“simp“env“aŽ¡’.mêsf–¹–=“simp“env“fŽ¡’‡’inŽ¡’‡’case–¹–f“ofŽ¡’)´TAbsLam–¹–v“eŽ¡’7á->–¹–simp“env{v“:->“sa}“eŽ¡’)´TotherŽ¡’7á->–¹–case“sf“ofŽ¡’T:šAbsLam–¹–v2“e2Ž¡’bg\->–¹–simp“env{v2“:->“sa}“e2Ž¡’T:šotherŽ¡’bg\->–¹–AbsAp“sf“saŽ¦’õºâºIf–òÁëMf“ºsimply“refuses“to“bAÇe“rewritten“in¾9to“an“ëMAbsLamº,‘ù«the“termŽ¡’õºâhas–,òits“subterms“simplied“and“is“then“returned“as-is.‘cJThisŽ¡’õºâis–Dzconsistenš¾9t“with“ho˜w“normal“cases“are“dealt“with,‘CsinceŽ¡’õºâthere–Tare“no“more“ëMAbsAp“ºrewrite“rules.ŽŸ
’õºâAn–—-ëMAbsVar“ºconstruct“can“refer“not“just“to“v‘ÿ|rariables“bAÇoundŽ¡’õºâb¾9y–=‹a“surrounding“ëMAbsLamº,‘‡˜but“also“to“the“abstract“v‘ÿ|raluesŽ¡’õºâof–6/other“functions.‘T‘ÿ:«o“deal“with“these,‘~fw¾9e“\preload"“theŽ¡’õºâëMAbsº-en•¾9vironmen“t–°Fwith“suitable“bindings“bAÇefore“starting“sim-Ž¡’õºâplication.‘}òFinally‘ÿ:«,‘èŸnote–‹*that“the“dual“ëMCtxº-constructionsŽ¡’õºâare–ü¿dealt“with“in“the“same“w•¾9a“y‘ÿ:«,‘6™so–ü¿ëMsimp“ºcarries“t•¾9w“o‘ü¿en“vi-Ž¡’õºâronmen¾9ts,‘HËrather–>€than“just“one.‘—óThe“only“dierence“is“thatŽ¡’õºâa–þëMCtxVar“ºcan“only“refer“to“ëMCtxLam“ºbAÇound“v‘ÿ|rariables.‘nTheseŽ¡’õºât•¾9w“o›rÙen“vironmen“ts˜are˜henceforth˜referred˜to˜as˜ëMaenv˜ºandŽ¡’õºâëMcenv‘TºrespAÇectiv¾9ely‘ÿ:«.ŽŸ5’õºâ¹4.4Ž’G·Avoiding–LÎinnite“b¹™ranchingŽ¤m’õºâ4.4.1Ž’úíA–LÎnaive“app¹™roachŽ¡’õºâºSection–323.4“in¾9troAÇduced“the“ëMCaseU›3*ºand“ëMCaseUU˜ºconstructionsŽ¤
’õºâas–¹yone“of“the“fundamenš¾9tal“mec˜hanisms“for“disassem˜blingŽ¡’õºâconš¾9texts.‘uA‘‡Øserious–ˆ8problem“whic˜h“bAÇecomes“apparen˜t“asŽ¡’õºâsošAÇon–UÄas“one“starts“xp˜oin¾9ting“is“the“p˜oten¾9tial“for“inniteŽ¡’õºâbranc•¾9hing.‘pFixpšAÇoin“ting–Tpro˜duces“expressions“lik¾9eŽ¦’ç¤ëMCaseU–¹–e“(CaseU“e“w“x)“(CaseU“e“y“z)Ž¦’õºâºwhicš¾9h–Tis“equiv‘ÿ|ralen˜t“to:ŽŽŽŽŽŸ’åä18ŽŽŒ‹Ó¦ •ºâ ý? £ ý€‘ûç¤ëMCaseU–¹–e“w“zŽ©ÐO‘íºâºW‘ÿ:«e–¶©can“get“round“this“b¾9y“designing“the“normal“form“so“thatŽ¤
‘íºâfor–±a“term“ëM(CaseU–¹–e“a“b)º,‘
Ÿneither–±subterm“ëMa“ºnor“ëMb“ºma¾9y“doŽ¡‘íºâa–fÕëMCaseU‘fÀºon“ëMeº.‘òT‘ÿ:«o“ac•¾9hiev“e–fÕthis“normalisation“requires“usingŽ¡‘íºâpartial–˜fkno¾9wledge“abAÇout“the“v‘ÿ|ralue“of“ëMe“ºwhen“simplifying“ëMaŽ¡‘íºâºand‘TëMbº.ŽŸ
‘íºâT‘ÿ:«o–@óimplemenš¾9t“this,‘‹Úw˜e“could“adopt“the“follo˜wing“sc˜heme.Ž¡‘íºâGivš¾9e–^#ëMsimp“ºy˜et“another“en˜vironmen˜t,–°VëMselenvº,“whic˜h‘^#mapsŽ¡‘íºâswitc¾9h–…expressions“seen“in“surrounding“ëMCaseU‘„ÿºand“ëMCaseUUsŽ¡‘íºâºto–N"partial“information“abAÇout“their“v‘ÿ|ralue.‘ÆÚWhen“a“nestedŽ¡‘íºâëMCase–s ºexpression“is“encounš¾9tered,‘‹3loAÇok“up“its“switc˜h“v‘ÿ|ralue“inŽ¡‘íºâëMselenvº.‘`¥If–,there“is“a“correspAÇonding“en¾9try‘ÿ:«,‘1¿this“ëMCase“ºexpres-Ž¡‘íºâsion–¿›mš¾9ust“bAÇe“examining“a“con˜text“whic˜h“has“already“bAÇeenŽ¡‘íºâloAÇokš¾9ed–—Öat,‘¸vso“the“ëMCase“ºexpression“is“replaced“b˜y“whic˜hev˜erŽ¡‘íºâarm–é;the“table“enš¾9try“sa˜ys“is“correct.‘˜$F‘ÿ:«or“example,‘4giv˜en“aŽ¡‘íºâcallŽ¦‘ûç¤ëMsimp–¹–selenv“(CaseU“e“(CaseU“e“w“x)“(CaseU“e“y“z))Ž¦‘íºâºsimplication–,Ëof“ëM(CaseU–¹–e“w“x)–,˺is“done“with“ëMselenv“ºbindingŽ¡‘íºâëMe–/ƒºto“ëMStop1º,‘]zand“simplication“of“ëM(CaseU–¹–e“y“z)–/ƒºis“done“withŽ¡‘íºâëMselenv–`Lºbinding“ëMe“ºto“some“v‘ÿ|ralue“of“the“form“ëMUp1‘¹–[...]º.‘àThisŽ¡‘íºâpartial–_$information“abAÇout“ëMe“ºimmediately“allo¾9ws“the“systemŽ¡‘íºâto–‡(reduce“the“t•¾9w“o–‡(subterms“to“ëMw“ºand“ëMz“ºrespAÇectiv¾9ely‘ÿ:«.‘qìProp-Ž¡‘íºâagation–ûìof“information“abAÇout“ëMCaseUU‘ûåºselector“v‘ÿ|ralues“is“doneŽ¡‘íºâanalogously‘ÿ:«.ŽŸ
‘íºâëMselenv–(cºis“augmenš¾9ted“eac˜h“time“a“ëMCaseU›(^ºor“ëMCaseUU˜ºis“\goneŽ¡‘íºâpast".‘?îA‘Ë problem–ËÓis“what“happAÇens“when“w¾9e“go“pastŽ¡‘íºâa›ÙÍëM(CtxLam–¹–v“e)º,‘Jësince˜this˜w•¾9ould˜in“v‘ÿ|ralidate˜an“y˜k“eys˜inŽ¡‘íºâëMselenv–9ºconš¾9taining“free“v‘ÿ|rariable“ëMvº.‘" Remem˜bAÇer“that“the“k˜eysŽ¡‘íºâare–üarbitrary“expressions,‘5²rather“than“mere“v‘ÿ|rariables.‘ІAnŽ¡‘íºâexpAÇensivš¾9e–£Wsolution“is“to“lter“out“all“(k˜ey‘ÿ:«,‘º$v‘ÿ|ralue)“pairs“whic˜hŽ¡‘íºârefer–àœto“ëMvº,‘nbut“that's“o•¾9v“erkill.‘~HIt–àœis“c¾9heapAÇer“to“completelyŽ¡‘íºâemptš¾9y–{°ëMselenv“ºat“ev˜ery“ëMCtxLamº.‘O„This“doAÇesn't“lose“informa-Ž¡‘íºâtion–kbAÇecause“the“abstract“inš¾9terpreter“nev˜er“builds“con˜textŽ¡‘íºâexpressions–÷ewhere“wš¾9e“need“to“main˜tain“selector“informationŽ¡‘íºâacross–”’ëMCtxLam“ºbAÇoundaries.‘ñ…F‘ÿ:«or“example,‘®Sit“nevš¾9er“builds“an˜y-Ž¡‘íºâthing‘Tlik¾9e:Ž¦‘ûç¤ëMCaseU–¹–s1“(\c1“->“...“(CaseU“s2“....))Ž¡‘&mê(\c2–¹–->“...“(CaseU“s2“....))ŽŸ5‘íºâ¹4.4.2Ž‘úíGeneralising–LÎthe“schemeŽŸm‘íºâºA‘œ›little–œ¾thoughš¾9t“sho˜ws“our“solution,‘¾˜whilst“pAÇerfectly“w˜ork-Ž¡‘íºâable,‘µDis–@toAÇo“wš¾9eak.‘ôiW‘ÿ:«e“need“a“more“general“w˜a˜y“to“propagateŽ¡‘íºâso-called–ëá\ëMselenv“ºinformation"“around,‘!„as“can“bAÇe“seen“b¾9yŽ¡‘íºâconsidering:Ž¦‘ûç¤ëMCMeet–¹–[e,“UpUp2“[Stop1,“Stop1]]Ž¦‘íºâºInitially‘ÿ:«,‘Òit–¬UlošAÇoks“lik¾9e“nothing“more“can“b˜e“done“with“this.Ž¡‘íºâBut–®if,›ab¾9y“loAÇoking“in“ëMselenvº,˜wš¾9e“can“sho˜w“that“ëMe“ºhas“anŽ¡‘íºâëMUpUp2‘¹–[...]–Tºv‘ÿ|ralue,“then:Ž¦‘ZÐëMCMeet–¹–[e,“UpUp2“[Stop1,“Stop1]]Ž¡‘ûç¤=–¹–UpUp2“[Stop1,“Stop1]Ž¦‘íºâºWhat–}twš¾9e“really“need“is“a“general“mec˜hanism“for“propagat-Ž¡‘íºâing–ÓTëMselenv“ºinformation.‘VqT‘ÿ:«o“bAÇe“fully“general,‘Ôwš¾9e“will“ha˜v˜eŽ¡‘íºâto–W¯searcš¾9h“ëMselenv“ºfor“eac˜h“term“ëMsimp“ºencoun˜ters.‘ã€This“pro-Ž¡‘íºâcess–ÆÀcan“bAÇe“rolled“inš¾9to“the“general“mec˜hanism“of“ëMsimpº,‘ób˜yŽŽŽ ý€’õºâsearc¾9hing–«ÄëMselenv“ºafter“ëMsimp“ºruns“out“of“applicable“rewriteŽ¤
’õºârules.‘5ÂW‘ÿ:«e–ÅexpšAÇect“to“disco•¾9v“er–Ånothing“ab˜out“the“v‘ÿ|rast“ma-Ž¡’õºâjoritš¾9y–Xµof“terms,‘iin“whic˜h“case“ëMsimp“ºacts“as“bAÇefore.‘æ’But,‘iforŽ¡’õºâa–luc¾9ky“few,‘?ëMselenv“ºtells“us“a“little“abAÇout“the“term:‘øÉit“isŽ¡’õºâeither›>jëMStop1º,–ˆ°ëMStop2º,“ëMUp2º,“ëMUp1–¹–[...]˜ºor˜ëMUpUp2“[...]º.‘—³InŽ¡’õºâthe–¼Ôrst“three“cases,‘·wš¾9e“can“ob˜viously“replace“the“term“withŽ¡’õºâthe–relev›ÿ|ran¾9t“v˜alue,‘õbut“the“other“t•¾9w“o–are“problematic.‘'Ho¾9wŽ¡’õºâcan–ywš¾9e“exploit“partial“information“lik˜e“this?‘G™Conceptually‘ÿ:«,Ž¡’õºâwš¾9e–%need“to“add“a“foAÇotnote“to“the“v‘ÿ|ralue“sa˜ying,‘	ûfor“example,Ž¡’õºâ\P‘ÿ:«.S.–)£This“v‘ÿ|ralue“is“kno¾9wn“to“bšAÇe“ëMUpUp2‘¹–[...]º",‘.·and“mo˜difyŽ¡’õºâthe–Trewrite“rules“to“takš¾9e“accoun˜t“of“suc˜h“foAÇotnotes.ŽŸ
’õºâThis–LHall“sounds“rather“clumsy‘ÿ:«,‘Zbut“there“is“a“neat“solution.Ž¡’õºâRecall–
qsection“3.4“in¾9troAÇduced“ëMDefU‘
1ºand“ëMDefUUº.“ëMDefºs“standŽ¡’õºâfor–Ÿg\denitely",‘¶ýand“are“inš¾9tended“as“a“w˜a˜y“of“attac˜hing“suc˜hŽ¡’õºâa–TèfoAÇotnote“to“a“v‘ÿ|ralue.‘Û-The“in•¾9tuitiv“e–Tèreading“of“ëM(DefU‘¹–e)“ºisŽ¡’õºâ\I'm–†not“sure“what“the“exact“v‘ÿ|ralue“of“ëMe“ºis,‘¢¾but“I‘…ódo“kno¾9w“it'sŽ¡’õºâan–zòëMUp1‘¹–[...]“ºv‘ÿ|ralue".‘MISo“noš¾9w,‘”Yon“disco˜v˜ering“from“ëMselenvŽ¡’õºâºthat–x¶a“term“ëMc“ºhas“an“ëMUp1›¹–[...]“ºor“ëMUpUp2˜[...]“ºv‘ÿ|ralue,‘‘Žw¾9eŽ¡’õºâmerely–èµneed“to“wrap“ëMc“ºin“ëMDefU›è~ºor“ëMDefUU˜ºrespAÇectiv¾9ely‘ÿ:«.‘–“AllŽ¡’õºâthat–’/remains“to“do“is“moAÇdify“rewrite“rules“to“takš¾9e“accoun˜t“ofŽ¡’õºâëMDefU–BHºand›BTëMDefUU“ºas˜appropriate.‘£pThis˜mec¾9hanism˜subsumesŽ¡’õºâthe–Tprevious“one.‘pConsider“again:Ž©½ì’ç¤ëMsimp‘¹–selenvŽ¡’‡’(CaseU–¹–e“(CaseU“e“w“x)“(CaseU“e“y“z))Ž¦’õºâºIgnoring–‚ÀpAÇossible“c¾9hanges“to“ëMwº,–žëMxº,“ëMy–‚Àºand“ëMzº,‘žëMsimp“ºtranformsŽ¡’õºâthis‘Tto:Ž¦’ç¤ëMCaseU–¹–e“(CaseU“Stop1“w“x)“(CaseU“(DefU“e)“y“z)Ž¦’õºâºApplication–Tof“the“rewrite“rulesŽ¦’ç¤ëMCaseU–¹–Stop1‘æXa“b–,Â===>“aŽ¡’ç¤CaseU–¹–(DefU“e)“a“b–,Â===>“bŽ¦’õºâºyields–Tthe“desired“result:Ž¦’ç¤ëMCaseU–¹–e“w“zŽ¦’õºâºRecall–&the“other“example,‘j,in“whic¾9h“ëMselenv“ºbinds“ëMe“ºto“anŽ¡’õºâëMUpUp2‘¹–[...]‘Tºv‘ÿ|ralue:Ž¦’ç¤ëMCMeet–¹–[e,“UpUp2“[Stop1,“Stop1]]Ž¦’õºâºAfter–Î}wrapping“ëMDefUU‘ÎMºaround“ëMeº,‘üÇthe“follo¾9wing“sequence“ofŽ¡’õºârewrites–Tis“pAÇossible:Ž¦’
ZÐëMCMeet–¹–[DefUU“e,“UpUp2“[Stop1,“Stop1]]Ž¡¡’ç¤=–¹–UpUp2“[“CMeet“[SelUU“1“e,“Stop1],Ž¡’3'€CMeet–¹–[SelUU“2“e,“Stop1]“]Ž¡¡’ç¤=–¹–UpUp2“[Stop1,“Stop1]Ž¦’õºâºAgain,‘ôåthe–È/desired“result“is“obtained.‘5All“w¾9e“had“to“do“isŽ¡’õºâinclude–Ta“rewrite“rule“deriv¾9ed“from“this:Ž¦’ç¤ëMCMeet–¹–[“UpUp2“[x1,“x2],‘	s,UpUp2“[y1,“y2]“]Ž¡’f===>‘,ÂUpUp2–¹–[“CMeet“[x1,“y1],Ž¡’Xô0CMeet–¹–[x2,“y2]“]Ž¦’õºâºBy–\ŸmoAÇdifying“the“rule“so“that“one“of“the“initial“terms“isŽ¡’õºâëM(DefUU‘¹–e)º,‘ÛHand–ÌÄbAÇearing“in“mind“the“meanings“of“ëMDefUU‘̲ºandŽ¡’õºâëMSelUU–Tº(see“section“3.4),“one“can“easily“sho¾9w“that:ŽŽŽŽŽŸ’åä19ŽŽŒ‹îs •ºâ ý? £ ý€‘ûç¤ëMCMeet–¹–[“DefUU“e,‘	s,UpUp2“[y1,“y2]“]Ž¤
‘
f===>‘,ÂUpUp2–¹–[“CMeet“[SelUU“1“e,“y1],Ž¡‘Pô0CMeet–¹–[SelUU“2“e,“y2]“]Ž©ÐO‘íºâºAll–™in“all,‘ú‰a“rather“eleganš¾9t“solution“to“a“tric˜ky“problem.Ž¡‘íºâThere–Tis“just“one“nal“ca•¾9v“eat.‘pConsider:Ž¦‘ûç¤ëMsimp–¹–selenv“(CaseU“e“a“b)Ž¦‘íºâºIf–ùFw¾9e“cannot“nd“a“v‘ÿ|ralue“for“ëMe“ºin“ëMselenvº,‘þãthe“ëMCaseU‘ù?ºexpres-Ž¡‘íºâsion–Í—maš¾9y“still“bAÇe“remo˜v‘ÿ|rable“b˜y“the“follo˜wing“means.‘E:FindŽ¡‘íºâin–ÔëMselenv“ºa“kš¾9ey“ëMk“ºfor“whic˜h“w˜e“can“pro˜v˜e“that“ëMkŽ‘ëPv‘zgëMeŽ‘
3ýº,Ž¡‘íºâand–æ(for“whic¾9h“ëMk“ºis“bAÇound“to“some“ëMUp1‘¹–[...]“ºv‘ÿ|ralue.‘ŽìSo“ëMeŽ¡‘íºâºmš¾9ust–&also“bind“to“some“ëMUp1‘¹–[...]“ºv‘ÿ|ralue,‘*Cso“w˜e“can“replaceŽ¡‘íºâëM(CaseU–¹–e“a“b)–àºb¾9y“ëM(CaseU–¹–(DefU“e)“a“b)º.‘'ëMCaseUUºs‘àare,‘ÃasŽ¡‘íºâev•¾9er,‘W¬analogous.‘»ªSo›Jgw“e˜migh“t˜bAÇe˜able˜to˜do˜just˜a˜little˜bitŽ¡‘íºâbAÇetter–	¼mš¾9y“taking“monotonicit˜y“of“k˜eys“in˜to“accoun˜t“whenŽ¡‘íºâsearc¾9hing‘TëMselenvº.ŽŸ5‘íºâ¹4.5Ž‘G·Avoiding–LÎan“expFfonential“explosionŽŸm‘íºâºAlthough–4¶wš¾9e“ha˜v˜e“a˜v˜oided“non-termination“via“inniteŽ¡‘íºâbrancš¾9hing,‘ïŠanother–³insidious“problem“lurks:‘.terms“whic˜hŽ¡‘íºâexpand–™,expšAÇonen¾9tially“for“a“while,‘º"b˜efore“shrinking“bac¾9k“toŽ¡‘íºâa–#compact“normal“form.‘ÝSucš¾9h“bAÇeha˜viour“causes“the“termŽ¡‘íºârewriter–Âlto“run“out“of“memory“simplifying“seemingly“in-Ž¡‘íºâsignican¾9t–¸expressions.‘yThe“problem“manifests“itself,‘à­onceŽ¡‘íºâagain,‘nŸwith–\ÃëMCaseU›\±ºand“ëMCaseUU˜ºterms.‘ò¾The“normal“form“re-Ž¡‘íºâquires–ª¸that“the“switc¾9h“expression“cannot“itself“bAÇe“a“ëMCaseU‘ªºorŽ¡‘íºâëMCaseUUº,–Tgiving“rise“to“some“rules“of“the“form:Ž¦‘ûç¤ëMCaseUU–¹–(CaseUU“a“b“c“d)“e“f“gŽ¡‘ûç¤===>Ž¡‘ûç¤CaseUU–¹–a“(CaseUU“b“e“f“g)Ž¡‘&mê(CaseUU–¹–c“e“f“g)Ž¡‘&mê(CaseUU–¹–d“e“f“g)Ž¦‘íºâºThe–Ðzproblem“ošAÇccurs“b˜ecause“of“the“w•¾9a“y–ÐzëMrewrite_with“ºat-Ž¡‘íºâtempts–ž5to“apply“rewrite“rules“to“the“roAÇot“term“un¾9til“no“moreŽ¡‘íºâcan–ËbAÇe“found.‘óÔIf“ëMa“ºis“itself“a“ëMCaseUU‘Œºterm,‘DhëMrewrite_withŽ¡‘íºâºwill–îéimmediately“reapply“the“rule,‘¥Mtrebling“the“expres-Ž¡‘íºâsion–Æÿsize“again.‘1rIt“w¾9ould“bšAÇe“b˜etter“to“lo˜ok“to“see“ifŽ¡‘íºâw¾9e–åâcan“do“some“simplications“on“the“ëM(CaseUU–¹–b“e“f“g)º,Ž¡‘íºâëM(CaseUU–¹–c“e“f“g)–køºand“ëM(CaseUU–¹–d“e“f“g)–køºterms“ëRb•‡efor“e‘køºse-Ž¡‘íºâlecting–FÖanother“rewrite“rule“for“the“roAÇot“term.‘°öThere's“aŽ¡‘íºâv¾9ery›yZgo•AÇo“d˜c•¾9hance˜w“e˜can,‘˜bAÇecause˜it˜is˜lik“ely˜that˜w“e˜alreadyŽ¡‘íºâkno¾9w–üËenough“abšAÇout“ëMbº,‘³ëMc“ºand“ëMd“ºto“eliminate“their“asso˜ciatedŽ¡‘íºâëMCaseUUºs.‘iÙIt–/"ma¾9y“also“turn“out“that“ëMa“ºis“the“same“as“ëMbº,‘5•ëMc“ºorŽ¡‘íºâëMdº,–Tand“this“is“helpful“toAÇo.ŽŸ
‘íºâImplemenš¾9ting–oÍthis“is“not“only“easy‘ÿ:«,‘Æjbut“essen˜tial.‘+ÚWhenŽ¡‘íºâëMrewrite_with–I$ºdetects“that“a“rewrite“rule“has“created“aŽ¡‘íºâëMCaseUU‘3ºterm,‘»Îit–4doAÇes“not“immediately“seek“out“anotherŽ¡‘íºârewrite–àarule“for“the“roAÇot“term.‘}–Instead,‘$it“tries“to“rewriteŽ¡‘íºâthe–’subterms“as“m•¾9uc“h–’as“pšAÇossible,‘¬Âand“only“then“lo˜oks“againŽ¡‘íºâat–3<the“rošAÇot“term.‘v'This“minor“mo˜dication“pro•¾9v“es›3<v“ery˜suc-Ž¡‘íºâcessful–Tat“a•¾9v“oiding›TexpAÇonen“tial˜explosions.ŽŸ5‘íºâ¹4.6Ž‘G·T‘ÿ,Ìyp•Ffe-sp“ecic–LÎëMAbsVal“¹optimisationŽŸm‘íºâºThe–ì abstract“v‘ÿ|ralues“(ëMAbsValsº)“of“all“non-function-space“ob-Ž¡‘íºâjects–—‘are“pšAÇoin¾9ts“in“a“one“p˜oinš¾9t“domain.‘£(Therefore,‘¸ for“an˜yŽ¡‘íºâëMAbsVal–
Xºat“all,‘‹if“w¾9e“can“determine“that“the“ob‘ƒŽject's“domainŽ¡‘íºâis–È+non-functional,‘ôàwš¾9e“can“man˜ufacture“an“equiv‘ÿ|ralen˜t“v‘ÿ|ralueŽŽŽ ý€’õºâfrom–)@ëMARec“ºand“ëMANonRecº.›X3This“is“extremely“useful.˜The“def-Ž¤
’õºâinition–/cof“ëMAbsValº,›5çpresen¾9ted“in“section“3.3,˜is“augmen¾9ted“soŽ¡’õºâwš¾9e–¥.can“iden˜tify“the“domain“for“an˜y“term.‘ËÿThis“is“done“b˜yŽ¡’õºâtagging–^Æeacš¾9h“ëMAbsVal“ºwith“a“con˜text“domain“v‘ÿ|ralue,‘ƒJexcept“forŽ¡’õºâthe–TëMARec“ºand“ëMANonRec“ºcases,“where“the“domain“is“ob¾9vious.ŽŸ
’õºâThe–•žëMsimp“ºaction“for“ëMAbsValºs“noš¾9w“bAÇegins“b˜y“extracting“theŽ¡’õºâconš¾9text–®domain,‘¯and“building“a“literal“replacemen˜t“if“appro-Ž¡’õºâpriate.‘pLet–TëMdomainof(a)“ºbAÇe“the“domain“of“ëMaº.Ž©7’’ç¤ëMsimp‘¹–aŽ¡’f=–¹–let“a_ctx_domain“=“domainof(a)Ž¡’‡’inŽ¡’‡’if‘æXunitary_ctx_domain(a_ctx_domain)Ž¡’‡’then‘	s,unit_value(a_ctx_domain)Ž¡’‡’else‘	s,(...–¹–do“as“before“...)Ž¡¡’ç¤unitary_ctx_domain–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=–¹–unitary_ctx_domain(D1)“&&“...“&&Ž¡’‡’unitary_ctx_domain(Dn)Ž¡¡’ç¤unitary_ctx_domain–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=–¹–unitary_ctx_domain(D1)“&&“...“&&Ž¡’‡’unitary_ctx_domain(Dn)Ž¡¡’ç¤unitary_ctx_domain–¹–(Ds“->“Dt)Ž¡’f=‘¹–FalseŽ¡¡’ç¤unit_value–¹–(Lift‘	s,(D1“x“...“x“Dn))Ž¡’f=–¹–ANonRec“[unit_value(D1)“...“unit_value(Dn)]Ž¡¡’ç¤unit_value–¹–(Lift2“(D1“x“...“x“Dn))Ž¡’f=–¹–ARec‘æX[unit_value(D1)“...“unit_value(Dn)]Ž¦’õºâºThis–T—wš¾9orks“ne,–¤gbut,“as‘T—usual,“w˜e–T—can“do“a“little“bAÇetter.Ž¡’õºâPresenš¾9ted–&with“a“term“already“compAÇosed“en˜tirely“of“ëMARecŽ¡’õºâºand–•øëMANonRecºs,‘¯qthe“scš¾9heme“returns“a“cop˜y“of“the“term,‘¯qgivingŽ¡’õºâa–k
pšAÇoten¾9tial“loss“of“sharing.‘‘A‘j±small“mo˜dication“detectsŽ¡’õºâsuc¾9h–Tterms“and“returns“them“as-is.ŽŸ€’õºâ¹4.7Ž’G·Impš¹™roving–LÎthe“rep˜resentation“of“contexts:‘fhëMApplyETŽŸm’õºâºF‘ÿ:«or–;tmanš¾9y“trivial-loAÇoking“functions,‘Düthe“abstract“in˜terpreterŽ¡’õºâemits–wa“remark‘ÿ|rably“cumš¾9bAÇersome“and“unin˜tuitiv˜e-loAÇokingŽ¡’õºâterm.‘ÝÂExamination–YJof“terms“from“rst“order“functions“sho¾9wsŽ¡’õºâa›èsw•¾9a“y˜to˜cut˜do“wn˜their˜sizes.‘
zSince˜all˜abstract˜v‘ÿ|ralues˜pAÇer-Ž¡’õºâtaining–à¶to“the“argumen¾9ts“and“result“of“a“rst“order“functionŽ¡’õºâare–H
unitary‘ÿ:«,‘T·the“only“thing“one“can“ask“abAÇout“it“is“ho¾9w“theŽ¡’õºâconš¾9text–˜ùon“the“result“propagates“to“eac˜h“argumen˜t.‘òüSuppAÇos-Ž¡’õºâing–“Õwš¾9e“ha˜v˜e“ëMfº,‘­¼a“rst“order“function“of“óO5ùž"		cmmi9ëOm“ºargumen˜ts,‘­¼and“w˜eŽ¡’õºâw•¾9an“t–^to“knoš¾9w“what“con˜text“propagates“to“the“ëOnº'th“argumen˜tŽ¡’õºâif–aØthe“result“is“demanded“in“conš¾9text“ëMalphaº.‘ýA˜t“presen˜t,‘túw˜eŽ¡’õºâget–Ta“large“term“of“the“form:Ž¦’ç¤ëMCtxAp‘	s,(FvalC–¹–(AbsAp“(GetA“...“(AbsAp“(FvalA“f)Ž¡’¼-~a1)Ž¡’ƒzv...Ž¡’kÚˆai)Ž¡’$ú¾))Ž¡¡’$ú¾(Fnc–¹–aj“...“(Fnc“am“alpha)“...)Ž¦’õºâºwhere‘“áëMiŽ›²(º=‘d±ëOn–b–ëP“º1–“áand“ëMjŽ˜º=‘d±ëOn–b–º+“1.‘˜What–“áthis“doAÇes“it“to“useŽ¡’õºâthe›©ªëM(AbsAp–¹–(GetA“...))˜ºconstruction˜ëOn–6äëP“º1˜times˜to˜supplyŽ¡’õºâthe–wrst“ëOn–OëP“º1–wabstract“v‘ÿ|ralue“argumen•¾9ts,‘€whic“h–wexpAÇoses“theŽŽŽŽŽŸ’åä20ŽŽŒ‹	Ö •ºâ ý? £ þ§þ ÿi€‘íºâ ÿefg‰fföÌÌŸÿþÌÍ )³4„0³2ff þäÿþ‘33ëMFsqDiffŽ¤
‘	ìÉ=–¹–(Fval“(\c1“->“(CJOINŽ¡‘^ùU(ApplyET#0–¹–F+“(ApplyET#1“F*“(FncC“(FncC“c1))))Ž¡‘^ùU(ApplyET#0–¹–F-“(ApplyET#0“F*“(FncC“(FncC“c1))))))Ž¡‘/¹y(\a1–¹–->“(Fval“(\c2“->“(CJOINŽ¡’¡‰(ApplyET#1–¹–F+“(ApplyET#1“F*“(FncC“c2)))Ž¡’¡‰(ApplyET#1–¹–F-“(ApplyET#0“F*“(FncC“c2)))))Ž¡‘qß­(\a2–¹–->“(ANonRec“[])))))Ž¡¡‘33FsqDiffŽ¡‘	ìÉ=–¹–(Fval“(\c1“->“(CJOINŽ¡‘^ùU{(FvalC‘¹–F+)Ž¡‘c²ë(Fnc–¹–(ANonRec“[])“(Fnc“(ANonRec“[])“{(FvalC“{*(FvalA“F*)“(ANonRec“[])*})Ž¡’…™(Fnc–¹–(ANonRec“[])“(FncC“(FncC“c1)))}))}Ž¡‘^ùU{(FvalC‘¹–F-)Ž¡‘c²ë(Fnc–¹–(ANonRec“[])“(Fnc“(ANonRec“[])“{(FvalC“F*)Ž¡’…™(Fnc–¹–(ANonRec“[])“(Fnc“(ANonRec“[])Ž¡’2(FncC–¹–(FncC“c1))))}))}))Ž¡‘/¹y(\a1–¹–->“(Fval“(\c2“->“(CJOINŽ¡’¡‰{(FvalC–¹–{*(FvalA“F+)“(ANonRec“[])*})Ž¡’¥Ù(Fnc–¹–(ANonRec“[])“{(FvalC“{*(FvalA“F*)“(ANonRec“[])*})Ž¡’ÿŸA(Fnc–¹–(ANonRec“[])“(FncC“c2))})}Ž¡’¡‰{(FvalC–¹–{*(FvalA“F-)“(ANonRec“[])*})Ž¡’¥Ù(Fnc–¹–(ANonRec“[])“{(FvalC“F*)Ž¡’ÿŸA(Fnc–¹–(ANonRec“[])“(Fnc“(ANonRec“[])“(FncC“c2)))})}))Ž¡‘qß­(\a2–¹–->“(ANonRec“[])))))ŽŸ‘^®rºFigure–T1:‘pAbstract“in¾9terpretation“of“ëMsqDiffº,“with“and“without“using“ëMApplyETŽŽ¡Ž’öff„0³2ffŽŽ *š‰fföÌÌŽŽŽŽ X€ þÃþ‘íºâëOnº'th–ªcon¾9text“map.‘ÚxThis“is“then“applied“to“ëMalpha“ºwrappAÇedŽ¤
‘íºâup–NÍin“a“cš¾9hain“of“ëM(Fnc‘¹–...)“ºconstructions“whic˜h“supply“theŽ¡‘íºâremaining›TëOm–8ëP“ëOn“ëP“º1˜abstract˜v‘ÿ|ralue˜argumen¾9ts.Ž©
‘íºâThis–^seems“an“enormously“wš¾9asteful“w˜a˜y“to“sa˜y“what“amoun˜tsŽ¡‘íºâto:Ž¤Ú‘ûç¤ëMApplyET–¹–n“f“alphaŽ¡‘íºâºThat–##is,‘S”\extract“the“ëOnº'th“con¾9text“map“from“ëMf“ºand“apply“it“toŽ¤
‘íºâthe–M¯con¾9text“ëMalphaº".–ÅW‘ÿ:«ell,›[Æalmost.“In–M¯fact,˜ëMfº's“ëOnº'th“con¾9textŽ¡‘íºâmap–ïHexpšAÇects“to“b˜e“applied“not“directly“to“ëMalphaº,‘öäbut“to“theŽ¡‘íºâterm›œèëM(Fnc–¹–aj“...“(Fnc“am“alpha)“...)º.‘³+It˜loAÇoks˜at˜rstŽ¡‘íºâlik•¾9e›‚~w“e˜need˜to˜include˜the˜abstract˜v‘ÿ|ralues˜ëMaj˜ºto˜ëMam˜ºin˜theŽ¡‘íºâëMApplyET‘=šºterm.‘–'F–ÿ:«ortunately“,‘ˆ
that–=æis“a•¾9v“oidable:‘m”since‘=ætheyŽ¡‘íºâare–9vall“unitary‘ÿ:«,‘‚~wš¾9e“should“nev˜er“need“to“kno˜w“what“theyŽ¡‘íºâare.‘’÷Instead,‘†·wš¾9e–<Ösimply“record“in“the“ëMApplyET‘<Šºterm“ho˜wŽ¡‘íºâmanš¾9y–8Iof“these“\trailing"“argumen˜ts“there“are.‘…OWhen“theŽ¡‘íºâterm–ê%rewriter“nally“gets“hold“of“ëMfº's“ëOnº'th“con¾9text“map,‘ZitŽ¡‘íºâuses–Tthis“n•¾9um“bAÇer–Tto“build“a“suitable“\dumm¾9y“term"Ž¤Ú‘ûç¤ëM(Fnc–¹–Error“...“(Fnc“Error“alpha)“...)Ž¡‘íºâºto–~üwhicš¾9h“it“applies“the“relev‘ÿ|ran˜t“con˜text“map.‘YhIn“eect,‘™fw˜eŽ¤
‘íºâa•¾9v“oided–9storing“those“trailing“argumenš¾9ts,‘ïand“fak˜ed“themŽ¡‘íºâinstead,›F using–<^ëMError“ºterms,˜bAÇecause“wš¾9e“can“guaran˜tee“theyŽ¡‘íºâwill–žònevš¾9er“bAÇe“used.‘¹JF‘ÿ:«rom“this“it“follo˜ws“that“it“is“an“errorŽ¡‘íºâfor–TëMError“ºto“appAÇear“in“the“normal“form“of“an¾9y“term.Ž¦‘íºâUse–î°of“ëMApplyET‘îwºshrinks“man¾9y“terms“dramatically‘ÿ:«,‘%and“en-Ž¡‘íºâhances– Çthe“time“and“space“pAÇerformance“of“the“analyser.‘>ÉAsŽ¡‘íºâan–Texample,“Figure“1“shoš¾9ws“the“abstract“in˜terpretation“ofŽŸÚ‘ûç¤ëMsqDiff–¹–x“y“=“(x“+“y)“*“(x“-“y)ŽŽŽ þÃþ’õºâºwith–LÎand“without“using“ëMApplyETº.“Of“course,‘Z­when“the“de-Ž¤
’õºânitions–Öof“ëM(+)º,›®vëM(-)“ºand“ëM(*)“ºare“substituted“in,˜bAÇoth“termsŽ¡’õºâreduce–'Zto“the“same“thing.‘RNote“that“ëM(CtxAp–¹–e1“e2)‘'ZºandŽ¡’õºâëM(AbsAp–¹–e1“e2)–õoºare“written“as“ëPfëMe1›¹–e2ëPg“ºand“ëPfëM*e1˜e2*ëPg“ºre-Ž¡’õºâspAÇectiv¾9ely‘ÿ:«.ŽŸ5’õºâ¹4.8Ž’G·No•¹™rmal›LÎfo“rms˜and˜termination˜p“ropFfertiesŽ©m’õºâºShoš¾9wing–÷that“the“term“rewriting“system“alw˜a˜ys“terminates,Ž¡’õºâand–\`prošAÇduces“normal“forms,‘^is“imp˜ortan¾9t.‘ÞÉF‘ÿ:«or“a“system“withŽ¡’õºâas–B½man¾9y“rewrite“rules“and“complications“as“this,‘NproAÇducingŽ¡’õºâa–	ªcorrectness“argumen¾9t“is“a“formidable“task.‘ùrW‘ÿ:«e“hopAÇe“toŽ¡’õºâinclude–›¦one“in“a“later“v¾9ersion“of“this“papšAÇer.‘¯fAlso“to“b˜eŽ¡’õºâincluded–Ewill“bAÇe“a“listing“of“the“rewrite“rules,‘‘
along“withŽ¡’õºâtheir–D€assošAÇciated“pro˜ofs“of“correctness.‘©ôThere“are“at“presen¾9tŽ¡’õºâin–Tthe“region“of“sixt¾9y“rewrite“rules.ŽŸ-’õºâ¹5Ž’”Firstication–LÎand“monomo¹™rphisationŽŸ†´’õºâ5.1Ž’G·IntroFfductionŽ¦’õºâºAlthough–¹·rst“order“functions“are“easily“handled“b¾9y“term-Ž¡’õºârewriting–­ based“xpAÇoinš¾9ting,‘Áøhigher“order“recursiv˜e“functionsŽ¡’õºâgivš¾9e–Ttrouble,“as“t˜ypied“b˜y“foldr:Ž©ÐO’ç¤ëMfoldr–¹–f“a“[]‘Y„=“aŽ¡’ç¤foldr–¹–f“a“(x:xs)‘	s,=“f“x“(foldr“f“a“xs)Ž¦’õºâºNaiv•¾9ely›\ÍxpAÇoin“ting˜this˜giv“es˜an˜series˜of˜appro“ximationsŽ¡’õºâin–­whicš¾9h“a“term“in˜v˜olving“functional“parameter“ëMf“ºis“appliedŽ¡’õºâev¾9er–J(more“times“to“an“initial“term.‘Ø·The“term“rewriter“cannotŽŽŽŽŽŽŸ’åä21ŽŽŒ‹% •ºâ ý? £ ý€‘íºâºshoš¾9w–Õ½that“t˜w˜o“appro˜ximations“are“the“same,‘Öso“a“xpAÇoin˜tŽ¤
‘íºâis–-œapparenš¾9tly“nev˜er“reac˜hed.‘eHWhat's“really“going“on“is“thatŽ¡‘íºâthe–TxpšAÇoin¾9t“of“ëMfoldr“ºdep˜ends“on“the“xp˜oin¾9t“of“ëMfº.Ž©
‘íºâThere– lare“only“t•¾9w“o› lw“a“ys˜round˜this.‘=¸The˜rst˜is˜to˜iter-Ž¡‘íºâate–Ÿenough“times“to“bšAÇe“sure“that“the“xp˜oin¾9t“is“certainlyŽ¡‘íºâreac•¾9hed.‘ЂW‘ÿ:«ork›QZb“y˜Nielson˜and˜Nielson˜[NN92Ž‘>]˜giv“es˜safeŽ¡‘íºâlo•¾9w“er–ö™bšAÇounds“on“the“n•¾9um“b˜er–ö™of“iterations“needed.‘À>Unfor-Ž¡‘íºâtunately‘ÿ:«,‘Wthe–¼expAÇense“of“doing“this“makš¾9es“it“unattractiv˜e.Ž¡‘íºâNote–Talso“that“this“approac¾9h“demands“monomorphisation.Ž¦‘íºâThe–M9second“solution“requires“us“to“supply“a“v‘ÿ|ralue“for“ëMf“ºbAÇe-Ž¡‘íºâfore–š%xpAÇoinš¾9ting“ëMfoldr,“ºso“that“w˜e“are,›»Yin“eect,˜no“longerŽ¡‘íºâdealing–¿xwith“a“higher-order“function.‘ÜThere“are“n¾9umerousŽ¡‘íºâw•¾9a“ys–T¾to“do“this,‘d™some“rather“obscure“in“that“they“partiallyŽ¡‘íºâsubstitute–g?in“functional“parameters“as“part“of“the“xpAÇoin¾9t-Ž¡‘íºâing–¶hproAÇcess“[ëN?Ž‘sº].‘ÿ­By“con¾9trast,‘­Anna“adopts“a“completelyŽ¡‘íºâstraigh•¾9tforw“ard›päapproac“h:‘Ó‘transform˜the˜source˜program.Ž¡‘íºâProgram–ñvtransformation“is“a“pAÇopular“sub‘ƒŽject,‘(~and“v‘ÿ|rariousŽ¡‘íºâpap•AÇers›—¶describ“e˜higher-order˜function˜remo•¾9v‘ÿ|ral˜(also˜kno“wnŽ¡‘íºâas–Ðœrstication“or“spAÇecialisation)“[CD91Ž‘þä]‘¡8[NelŽ‘
žº].‘ˆThe“sc¾9hemeŽ¡‘íºâpresen•¾9ted›TbAÇelo“w˜is˜based˜on˜w“ork˜b“y˜George˜Nelan˜[NelŽ‘
žº].Ž¦‘íºâNot–Àall“functional“parameters“can“bAÇe“remo•¾9v“ed.‘ÇF‘ÿ:«or‘Àexam-Ž¡‘íºâple,‘õrecursivš¾9e–ífunctions“whic˜h“ha˜v˜e“accum˜ulating“functionalŽ¡‘íºâparameters–Iare“not“transformable,‘Æat“least“with“the“sc¾9hemeŽ¡‘íºâbAÇelo¾9w:Ž©:¢‘ûç¤ëMf–¹–g“x“=“if‘æXx“==“0Ž¡‘!´Tthen‘	s,g‘¹–1Ž¡‘!´Telse‘	s,x–¹–*“f“(\y“->“g“x“+“y)“(x-1)Ž¦‘íºâºW‘ÿ:«e– _justify“this“design“decision“on“the“basis“that“the“v‘ÿ|rastŽ¡‘íºâma‘ƒŽjorit¾9y–Yof“functions“that“pšAÇeople“really“write“can“b˜e“rsti-Ž¡‘íºâed,‘T‰and–Gåthe“v‘ÿ|rast“ma‘ƒŽjoritš¾9y“of“the“rest“can“bAÇe“handled“b˜y“aŽ¡‘íºâsecondary–=§mec¾9hanism“outlined“in“section“6.4.‘•jIn“doing“thisŽ¡‘íºâwš¾9e–±Yimplicitly“appAÇeal“to“the“measuremen˜t-lead“approac˜h“toŽ¡‘íºâdesign–Ô¼discussed“in“the“in¾9troAÇduction.‘Z©W‘ÿ:«e“only“need“to“re-Ž¡‘íºâmo•¾9v“e–PÛfunctional“parameters“for“recursiv¾9e“functions,–_½but,“asŽ¡‘íºâbAÇecomes–’fclear,‘¬–this“means“rstifying“non-recursiv¾9e“functionsŽ¡‘íºâtoAÇo.ŽŸæ‘íºâ¹5.2Ž‘G·Firstication–LÎb¹™y“examplesŽŸm‘íºâºF‘ÿ:«or–þcthe“momen¾9t,‘x§let's“use“ëMfoldr“ºas“a“running“example.Ž¡‘íºâGivš¾9en–Ta“use“of“ëMfoldrº,“lik˜eŽ¦‘ûç¤ëMsum–¹–xs“=“foldr“(+)“0“xsŽ¦‘íºâºwš¾9e–½can“unfold“functional“parameter“ëM(+)“ºand“iden˜tit˜y“ëM0“ºin˜toŽ¡‘íºâëMfoldrº,–Tgiving“a“new“function“ëMfoldrSpecº:Ž¦‘ûç¤ëMsum–¹–xs“=“foldrSpec“xsŽ¡¡‘ûç¤foldrSpec–¹–[]‘Y„=“0Ž¡‘ûç¤foldrSpec–¹–(x:xs)‘	s,=“x“+“foldr“(+)“0“xsŽ¦‘íºâºAnd–noš¾9w,‘E%folding“the“b•AÇo“dy–of“ëMfoldrSpec“ºgiv˜es“what“w˜e“reallyŽ¡‘íºâw•¾9an“t:Ž¦‘ûç¤ëMsum–¹–xs“=“foldrSpec“xsŽ¡¡‘ûç¤foldrSpec–¹–[]‘Y„=“0Ž¡‘ûç¤foldrSpec–¹–(x:xs)‘	s,=“x“+“foldrSpec“xsŽ¦‘íºâºThe–h5kš¾9ey“to“success“here“is“the“ease“with“whic˜h“that“lastŽ¡‘íºâfold–4wš¾9as“done.‘xÈIn“general,‘;Îfolding“is“a“tric˜ky“business,‘;ÎwithŽŽŽ ý€’õºâno–4`guaranš¾9tee“of“termination.‘y“Ho˜w˜ev˜er,‘|"b˜y“restricting“theŽ¤
’õºâfunctions–s‘wš¾9e“deal“with,‘‹ w˜e“can“guaran˜tee“to“mak˜e“the“foldŽ¡’õºâstep–¶ˆterminating,‘ÞÔand“trivial“to“carry“out.‘The“restrictionŽ¡’õºâis–ÒPthat“the“function“mš¾9ust“pass“along“all“parameters“whic˜hŽ¡’õºâw•¾9e›¹w“an“t˜to˜sp•AÇecialise˜in˜the˜same˜p“osition˜in˜recursiv¾9e˜callsŽ¡’õºâas–ythey“appAÇeared“in“the“argumen¾9ts.‘+ßF‘ÿ:«or“example,‘Âin“ëMfoldrº,Ž¡’õºâbAÇoth–TëMa“ºand“ëMf“ºsatisfy“this.ŽŸ
’õºâIn–³fact,‘Ÿ:wš¾9e“only“w˜an˜t“to“substitute“in“functional“parameters.Ž¡’õºâSo–Tthe“transformation“of“ëMsum“ºis“really:Ž©ÐO’ç¤ëMsum–¹–xs“=“foldrSpec“0“xsŽ¡¡’ç¤foldrSpec–¹–a“[]‘Y„=“aŽ¡’ç¤foldrSpec–¹–a“(x:xs)‘	s,=“x“+“foldrSpec“a“xsŽ¦’õºâºA‘ºlittle–ûterminology‘ÿ:«.‘ƨThe“function“or“recursiv¾9e“group“of“func-Ž¡’õºâtions–¯3-“for“example,‘àëMfoldr“º-“for“whic¾9h“functional“parametersŽ¡’õºâare–Ý·bAÇeing“remo•¾9v“ed–Ý·is“called“the“ëNtarget‘LÂgroupº.‘	æAnd“a“func-Ž¡’õºâtion–Tcon¾9taining“a“call“to“a“target“group“is“called“a“ëNsourceº.ŽŸ
’õºâThe–Oxrestriction“on“v‘ÿ|ralid“targets“seems“to“bAÇe“this:‘·the“func-Ž¡’õºâtion–Ímš¾9ust“pass“along“all“functional“parameters“unc˜hanged“inŽ¡’õºâall–~recursivš¾9e“calls.‘´ïGeneralising“this“to“deal“with“m˜utuallyŽ¡’õºârecursiv¾9e–ÃRtargets“requires“the“notion“of“a“ëNconstan´Ct‘Uargu-Ž¡’õºâmen´Ct‘Œßsetº.‘¨Calling–ga“recursiv¾9e“group“in“general“causes“callsŽ¡’õºâwithin–'the“group,‘œand“a“constanš¾9t“argumen˜t“set“gathers“to-Ž¡’õºâgether–&margumenš¾9ts“whic˜h“are“guaran˜teed“to“ha˜v˜e“the“sameŽ¡’õºâv‘ÿ|ralue–Tfor“evš¾9ery“sub-call.‘pF‘ÿ:«or“example,“giv˜enŽ¦’ç¤ëMf–¹–x“y“z‘	s,=“f“y“y“z“+“g“z“xŽ¡’ç¤g–¹–a“b‘æX=“f“a“b“a“+“g“a“bŽ¦’õºâºa–æÔlittle“thoughš¾9t“sho˜ws“ëMfº's“third“argumen˜t“and“ëMgº's“rst“argu-Ž¡’õºâmenš¾9t–•sare“alw˜a˜ys“the“same,‘µ{giving“a“constan˜t“argumen˜t“setŽ¡’õºâwritten–gëM{f.3,‘¹–g.1}º.‘–A‘fögroup“can“ha•¾9v“e–gmore“than“one“set,Ž¡’õºâas–Tthe“folloš¾9wing“trivial“example“sho˜ws:Ž¦’ç¤ëMf–¹–x“y‘	s,=“g“x“yŽ¡’ç¤g–¹–a“b‘	s,=“f“a“bŽ¦’õºâºConstan•¾9t›mïargumen“t˜sets˜can˜bAÇe˜computed˜using˜a˜simpleŽ¡’õºâabstract–Ë>in¾9terpretation“describšAÇed“b˜elo¾9w.‘¾What“is“imp˜ortan¾9tŽ¡’õºâhere– Iis“that“for“a“recursiv¾9e“target“group“to“bšAÇe“sp˜ecialisable,Ž¡’õºâall–ñbfunctional“parameters“in“the“group“mš¾9ust“bAÇe“constan˜t“ar-Ž¡’õºâgumenš¾9ts.‘ýCertain–µ‹other“constrain˜ts“also“apply–ÿ:«.‘ýW“e‘µ‹returnŽ¡’õºâto–Tthese“later.ŽŸ
’õºâThe–Tfolloš¾9wing“example“breaks“our“nice“sc˜heme:Ž¦’ç¤ëMmap–¹–f“[]‘Y„=“[]Ž¡’ç¤map–¹–f“(x:xs)‘	s,=“f“x“:“map“f“xsŽ¡¡’ç¤addN–¹–n“xs“=“map“(+“n)“xsŽ¦’õºâºF‘ÿ:«olding–Tand“unfolding“as“abAÇo•¾9v“e‘Tgiv“esŽ¦’ç¤ëMaddN–¹–n“xs“=“mapSpec“xsŽ¡¡’ç¤mapSpec–¹–[]‘Y„=“[]Ž¡’ç¤mapSpec–¹–(x:xs)‘	s,=“(x+n)“:“mapSpec“xsŽ¦’õºâºwhic¾9h–Û†is“clearly“wrong“bAÇecause“ëMn“ºis“undened“in“ëMmapSpecº.Ž¡’õºâWhat–?jwš¾9e“need“to“do“is“pass“along“all“free“lam˜b•AÇda-b“oundŽ¡’õºâv›ÿ|rariables–Ѹin“the“spAÇecialising“v˜alue“ëM(+‘¹–n)“ºas“new“parameters,Ž¡’õºâin–Ta“stš¾9yle“reminiscen˜t“of“lam˜bAÇda-lifting:ŽŽŽŽŽŸ’åä22ŽŽŒ‹8— •ºâ ý? £ ý€‘ûç¤ëMaddN–¹–n“xs“=“mapSpec“n“xsŽ¤
¡‘ûç¤mapSpec–¹–n“[]‘Y„=“[]Ž¡‘ûç¤mapSpec–¹–n“(x:xs)‘	s,=“(x+n)“:“mapSpec“n“xsŽ©å‘íºâºNevš¾9ertheless–PØthis“still“allo˜ws“us“to“get“our“knic˜k˜ers“in“a“t˜wist.Ž¡‘íºâIn–d%the“folloš¾9wing“(admittedly“con˜triv˜ed)“example,‘·Ùw˜e“ma˜yŽ¡‘íºâselect–Teither“ëMinc“ºor“ëMg“ºas“a“source“to“transform“rst:Ž¦‘ûç¤ëMapply–¹–f“x‘	s,=“f“xŽ¡‘ûç¤g–¹–a“b‘Y„=“apply“a“bŽ¡¡‘ûç¤inc–¹–y‘Y„=“g“(+“1)“yŽ¦‘íºâºDoing–Tg“rst“giv¾9es:Ž¦‘ûç¤ëMapplySpec–¹–x‘	s,=“a“xŽ¡‘ûç¤g–¹–a“b‘%Ì°=“applySpec“bŽ¡¡‘ûç¤inc–¹–y‘%Ì°=“g“(+“1)“yŽ¦‘íºâºNo•¾9w›mÅw“e˜need˜to˜in“tro•AÇduce˜free˜v‘ÿ|rariables˜of˜the˜sp“ecialisingŽ¡‘íºâv‘ÿ|ralue–TëMa“ºas“a“new“parameter“to“ëMapplySpecº:Ž¦‘ûç¤ëMapplySpec–¹–a“x‘	s,=“a“xŽ¡‘ûç¤g–¹–a“b‘/?Ü=“applySpec“a“bŽ¡¡‘ûç¤inc–¹–y‘/?Ü=“g“(+“1)“yŽ¦‘íºâºWhereupšAÇon–uit“should“b˜e“eminenš¾9tly“clear“that“w˜e'v˜e“ac˜hiev˜edŽ¡‘íºâexactly–Ànothing!‘…µOur“mistakš¾9e“w˜as“to“select“a“source“forŽ¡‘íºâwhic¾9h–çúthe“spAÇecialising“v›ÿ|ralue“had“function-v˜alued“free“v˜ari-Ž¡‘íºâables,‘˜
since–}åpassing“them“as“new“parameters“to“ëMapplySpecŽ¡‘íºâºmeans–œõëMapplySpec“ºis“still“a“higher-order“function.‘ôPThe“moralŽ¡‘íºâis–bTclear:‘¶qonly“transform“sources“for“whicš¾9h“the“free“lam˜bAÇda-Ž¡‘íºâbšAÇound–Òrv‘ÿ|rariables“of“the“sp˜ecialising“v‘ÿ|ralue“are“not“higher-Ž¡‘íºâorder.‘ÅA‘¿šsecond–¿Æobš¾9vious“constrain˜t“on“source“calls“is“thatŽ¡‘íºâthe–¿call“should“bAÇe“sucien¾9tly“applied“for“all“function-v‘ÿ|raluedŽ¡‘íºâparameters–Tto“bAÇe“visible.Ž©
‘íºâIn–5ïwhat“follo•¾9ws,‘bžw“e–5ïassume“that“naming“issues“are“dealt“withŽ¡‘íºâcorrectly‘ÿ:«.‘T=In–'îparticular,‘,”the“free“v‘ÿ|rariables“in“an“spAÇecialisingŽ¡‘íºâv‘ÿ|ralue–Îneed“to“bšAÇe“renamed“b˜efore“they“can“b˜e“safely“insertedŽ¡‘íºâas–Tnew“parameters“of“the“spAÇecialised“target.Ž¦‘íºâThe–²4algorithm“bšAÇelo¾9w“requires“the“program“to“b˜e“stratiedŽ¡‘íºâinš¾9to–øminimal“m˜utually“recursiv˜e“groups,‘;áand“topAÇologicallyŽ¡‘íºâsorted.‘%
W‘ÿ:«e–2adopt“the“usual“con•¾9v“en“tion–2that“the“programŽ¡‘íºâis–bIwritten“top-to-bAÇottom,‘u†with“anš¾9y“giv˜en“function“referringŽ¡‘íºâonly–‘oto“its“oš¾9wn“group,‘«Ðif“recursiv˜e,‘«Ðand“groups“abAÇo˜v˜e“it.‘ðyTheŽ¡‘íºârošAÇot–Texpression“is“righ¾9t“at“the“b˜ottom.Ž¦‘íºâSpAÇecialisation–(of“target“groups“ma¾9y“result“in“some“groupsŽ¡‘íºâbšAÇecoming–•Ðunreac¾9hable“from“ëMmainº.‘ãThese“groups“should“b˜eŽ¡‘íºâremo•¾9v“ed.‘í4A‘°more–°@dicult“problem“is“ho¾9w“to“insert“a“newŽ¡‘íºâgroup,‘ûÍresulting–š‚from“spAÇecialisation“of“an“existing“group,Ž¡‘íºâinš¾9to––the“program“so“as“to“main˜tain“depAÇendancy‘ÿ:«.‘ÿ7It“turnsŽ¡‘íºâout– ðthat“t•¾9w“o› ðdieren“t˜bAÇeha“viours˜are˜pAÇossible.‘?EIn˜the˜usualŽ¡‘íºâcase,–Tthe“new“group“\splits"“a•¾9w“a“y–Tfrom“the“source“group:ŽŸå‘ûç¤ëMletrec‘æXmap–¹–f“[]‘Y„=“[]Ž¡‘+'€map–¹–f“(x:xs)‘	s,=“f“x“:“map“f“xsŽ¡‘ûç¤in‘¹–letŽ¡‘+'€square–¹–x‘Y„=“x“*“xŽ¡‘ûç¤in‘¹–letŽ¡‘+'€squareList–¹–xs“=“map“square“xsŽ¡‘ûç¤in‘¹–...ŽŽŽ ý€’õºâºSince–L®the“spAÇecialised“target“ëMmapSpec“ºrefers“to“ëMsquareº,‘š…w¾9eŽ¤
’õºâmš¾9ust–‡place“it“after“ëMsquareº.‘sKT‘ÿ:«aking“this“argumen˜t“to“itsŽ¡’õºâconclusion–üEshoš¾9ws“w˜e“should“place“an˜y“\splitting"“group“im-Ž¡’õºâmediately–TbAÇefore“the“source“group:Ž©ÐO’ç¤ëMlet‘!square–¹–x‘%Ì°=“x“*“xŽ¡’ç¤in‘¹–letrecŽ¡’3'€mapSpec–¹–[]‘Y„=“[]Ž¡’3'€mapSpec–¹–(x:xs)‘	s,=“square“x“:Ž¡’ˆ4mapSpec‘¹–xsŽ¡’ç¤in‘¹–letŽ¡’3'€squarelist–¹–xs‘,Â=“mapSpec“xsŽ¡’ç¤in‘¹–...Ž¦’õºâºSources–Tgiving“rise“to“\joining"“spAÇecialisations“are“un¾9usual:Ž¦’ç¤ëMletrec‘æXmap–¹–f“[]‘Y„=“[]Ž¡’3'€map–¹–f“(x:xs)‘	s,=“f“x“:“map“f“xsŽ¡’ç¤in‘¹–letrecŽ¡’3'€squareList‘¹–xsŽ¡’ATB=–¹–map“(head.squareList.unit)“xsŽ¡’ç¤in‘¹–...Ž¦’õºâºHere,›~the–X8denitions“of“ëM(.)º,˜ëMhead“ºand“ëMunit“ºare“unimpAÇortan¾9t.Ž¡’õºâBecause–ºthe“spAÇecialising“v‘ÿ|ralue“ëM(head.squareList.unit)Ž¡’õºâºrefers–z¶to“the“source“group“from“whic¾9h“it“originates,‘”the“re-Ž¡’õºâsulting–âáspAÇecialisation“of“ëMmap“ºwill“also“refer“to“ëMsquareListº,Ž¡’õºâand–âKthat“in“turn“means“the“spšAÇecialisation“should“b˜e“mergedŽ¡’õºâin¾9to–Tthe“source“group:Ž¦’ç¤ëMletrecŽ¡’fsquareList–¹–xs‘,Â=“mapSpec“xsŽ¡’fmapSpec–¹–[]‘Y„=“[]Ž¡’fmapSpec–¹–(x:xs)‘	s,=“(head.squareList.unit)“x“:Ž¡’g òmapSpec‘¹–xsŽ¡’ç¤in‘¹–...Ž¦’õºâºSince–{·only“recursivš¾9e“source“groups“can“refer“to“themselv˜es,Ž¡’õºâsp•AÇecialisations›Bcorresp“onding˜to˜sources˜in˜non-recursiv¾9eŽ¡’õºâgroups–Tnevš¾9er“exhibit“this“\joining"“bAÇeha˜viour.ŽŸ5’õºâ¹5.3Ž’G·An‘LÎalgo¹™rithmŽŸm’õºâºThe–PùprošAÇcedure“b˜elo¾9w“is“rep˜eated“un¾9til“no“more“v‘ÿ|ralid“(source,Ž¡’õºâtarget)–Ò—pairs“can“bAÇe“found.‘T9As“shoš¾9wn“b˜y“Nelan“[NelŽ‘
žº],‘ètheŽ¡’õºâorder–)in“whicš¾9h“these“pairs“are“selected“mak˜es“no“dierence.Ž¡’õºâUn¾9used––Õtargets“should“bšAÇe“deleted,‘°"but“again“it“do˜esn't“mak¾9eŽ¡’õºâanš¾9y–Tdierence“when.‘pAs“a“running“example,“w˜e“tak˜e:Ž¦’ÿ.ëMletrecŽ¡’
ZÐmap1–¹–f“g“(x:y:xys)‘	s,=“f“x“:“g“y“:“map2“g“f“xysŽ¡’
ZÐmap1–¹–f“g“_‘/?Ü=“[]Ž¡¡’
ZÐmap2–¹–g“f“(x:y:xys)‘	s,=“g“x“:“f“y“:“map1“f“g“xysŽ¡’
ZÐmap2–¹–g“f“_‘/?Ü=“[]Ž¡’ÿ.in‘¹–letŽ¡’
ZÐaddmul–¹–p“q“xs‘!=“map1“(+“p)“(*“q)“xsŽŸÐO’‰º1.ŽŽŽ’:âFind–&´a“v›ÿ|ralid“target“group,‘kand“a“v˜alid“source“groupŽ¡’:âwhic¾9h–Trefers“to“the“target“group.ŽŸÌÍ’g¤ëMTarget–¹–group‘,Â=“{map1,“map2}Ž¡’g¤Source–¹–group‘,Â=“{addmul},“refers“to“map1ŽŽŽŽŽŸ’åäº23ŽŽŒ‹Rè •ºâ ý? £ ý€‘ø‰º2.ŽŽŽ‘:âIf–‡dthe“target“group“is“recursivš¾9e,‘£çcompute“its“constan˜tŽ¤
‘:âargumenš¾9t–½Ðsets“(see“section“5.4).‘ãIn“realit˜y‘ÿ:«,‘çîthis“com-Ž¡‘:âputation–É$has“to“bšAÇe“p˜erformed“at“step“(1).‘	7áIf“non-Ž¡‘:ârecursiv•¾9e,‘¿$man“ufacture–iûa“\fak¾9e"“singleton“set“listingŽ¡‘:âall–Thigher-order“parameters“as“constan¾9t.Ž©ª_‘g¤ëMConst–¹–arg“sets‘	s,=“{“{map1.1,“map2.2},Ž¡‘pç\{map1.2,–¹–map2.1}“}Ž¦‘ø‰º3.ŽŽŽ‘:âIn•¾9v“en“t–Aa“new“set“of“names“for“the“spAÇecialised“targetŽ¡‘:âgroup.Ž¦‘g¤ëMNew–¹–names‘	s,=“{map1Spec,“map2Spec}Ž¦‘ø‰º4.ŽŽŽ‘:âDetermine,‘çfrom–Ûlthe“constanš¾9t“argumen˜t“set,‘çwhic˜h“ar-Ž¡‘:âgumen¾9ts–¿Yin“the“source“call“site“are“the“spAÇecialising“v‘ÿ|ral-Ž¡‘:âues.‘²Extract–G8their“free“lam¾9b•AÇda-b“ound–G8v‘ÿ|rariables“andŽ¡‘:ârename.Ž¦‘g¤ëMOriginal:Ž¡‘!:specialising–¹–values“=“{(+“p),“(*“q)}Ž¡‘!:free–¹–variables‘Y„=“{p,“q}Ž¡¡‘g¤Renamed:Ž¡‘!:specialising–¹–values“=“{(+“pnew),“(*“qnew)}Ž¡‘!:free–¹–variables‘Y„=“{pnew,“qnew}Ž¦‘ø‰º5.ŽŽŽ‘:âRebuild–­½the“source“call“b¾9y“deleting“the“spAÇecialisationŽ¡‘:âv›ÿ|ralues,‘Åninserting–±tfree“v˜ariables“as“new“parameters,‘ÅnandŽ¡‘:âc¾9hanging–À+the“called“function“to“its“new“name,‘êáas“de-Ž¡‘:âtermined–Tin“step“(3).Ž¦‘g¤ëMRebuilt–¹–source“call‘	s,=“map1Spec“p“q“xsŽ¦‘ø‰º6.ŽŽŽ‘:âBuild–2vthe“spAÇecialised“target“group,‘_Östarting“with“a“cop¾9yŽ¡‘:âof–$šthe“original“target“group.‘JAF‘ÿ:«or“eacš¾9h“recursiv˜e“callŽ¡‘:âinside–Táthe“group,‘dÄmoAÇdify“that“call“in“a“similar“w•¾9a“y‘TátoŽ¡‘:âhoš¾9w–Tthe“source“call“w˜as“moAÇdied“in“step“(5).Ž¦‘:âëMRebuilt–¹–target“group:Ž¡¡‘g¤map1Spec–¹–pnew“qnew“(x:y:xys)Ž¡‘ ”f=–¹–(x“+“pnew)“:“(y“*“qnew)“:Ž¡‘gt0map2Spec–¹–pnew“qnew“restŽ¡‘g¤map1Spec–¹–pnew“qnew“_Ž¡‘ ”f=‘¹–[]Ž¡¡‘g¤map2Spec–¹–pnew“qnew“(x:y:xys)Ž¡‘ ”f=–¹–(x“*“qnew)“:“(y“+“pnew)“:Ž¡‘gt0map1Spec–¹–pnew“qnew“restŽ¡‘g¤map2Spec–¹–pnew“qnew“_Ž¡‘ ”f=‘¹–[]Ž¦‘ø‰º7.ŽŽŽ‘:âDetermine–Zgwhether“the“spAÇecialised“target“group“shouldŽ¡‘:âsplit–»or“join,‘¦b¾9y“nding“out“whether“the“spAÇecialisationŽ¡‘:âv‘ÿ|ralues–“fconš¾9tained“an˜y“reference“to“the“source“group.Ž¡‘:âAugmen¾9t–Tprogram“appropriately‘ÿ:«.Ž¦‘g¤ëMSpecialisation–¹–vals“{(+“p),“(*“q)}“don'tŽ¡‘g¤refer–¹–to“{addmul},“so“new“group“splits.ŽŸ­â‘íºâºA‘qùv‘ÿ|ralid–rnon-recursivš¾9e“target“group“m˜ust“consist“of“a“singleŽ¡‘íºâhigher–HØorder“function.‘¶ûA‘HÊv‘ÿ|ralid“recursiv¾9e“target“group“satis-Ž¡‘íºâes–Tall“the“follo¾9wing:ŽŽŽ ý€’äëPŽŽŽ’:âºAll–Ú–functions“in“the“group“ha•¾9v“e–Ú–at“least“one“functionalŽ¤
’:âparameter.Ž©8’äëPŽŽŽ’:âºEacš¾9h–¤lfunctional“parameter“in“the“group“is“a“mem˜bAÇerŽ¡’:âof–s“exactly“one“of“the“group's“constanš¾9t“argumen˜t“sets.Ž¡’:âThis–|implies“that“all“inš¾9tra-group“calls“m˜ust“bAÇe“su-Ž¡’:âcienš¾9tly–Tapplied“to“expAÇose“all“functional“argumen˜ts.Ž¦’äëPŽŽŽ’:âºEac•¾9h›¦âconstan“t˜argumen“t˜set˜m“ust˜men“tion˜exactly˜oneŽ¡’:âargumenš¾9t–¤Çfor“eac˜h“function“in“the“group.‘ÊÊThis“disal-Ž¡’:âloš¾9ws–'Úcertain“con˜triv˜ed“pathological“cases“whic˜h“w˜ouldŽ¡’:âotherwise–Tseriously“complicate“the“algorithm.Ž¤šW’õºâA–Tv‘ÿ|ralid“source“call“site“satises“the“follo¾9wing:Ž¡’äëPŽŽŽ’:âºThe–Tsite“is“a“call“to“a“v‘ÿ|ralid“target“group.Ž¦’äëPŽŽŽ’:âºThe–Bpapplication“mš¾9ust“ha˜v˜e“sucien˜t“argumen˜ts“to“sup-Ž¤
’:âply–Tall“higher“order“(spAÇecialisable)“argumen¾9ts.Ž¦’äëPŽŽŽ’:âºF‘ÿ:«or–Û7eacš¾9h“spAÇecialisable“argumen˜t,‘Œ¯none“of“the“freeŽ¡’:âlamš¾9b•AÇda-b“ound–&v‘ÿ|rariables“ma˜y“bAÇe,‘jNor“con˜tain,‘jNa“func-Ž¡’:âtion‘Tspace.Ž©šW’õºâAlthough–/it“lošAÇoks“easy“on“pap˜er,‘uqimplemen¾9ting“this“algo-Ž¡’õºârithm–s3is“tricš¾9ky–ÿ:«.‘6T“aking–s3in˜to“accoun˜t“the“mec˜hanisms“forŽ¡’õºâdetecting–ëbconstanš¾9t“argumen˜ts“and“main˜taining“t˜ypAÇe“anno-Ž¡’õºâtations,‘Íthe–èèHaskš¾9ell“implemen˜tation“approac˜hes“1500“linesŽ¡’õºâof‘TcoAÇde.ŽŸ*£’õºâ¹5.4Ž’G·Computing–LÎconstant“a¹™rgument“setsŽŸm’õºâºA‘õ¦simple–õ®abstract“inš¾9terpretation“is“used.‘ãEac˜h“function“callŽ¡’õºâin–kÏthe“group“is“abstracted“to“expAÇose“the“parameters“it“passesŽ¡’õºâalong:Ž¦’ç¤ëMf–¹–x“y“z‘	s,=“f“y“y“z“+“g“z“xŽ¡’ç¤g–¹–a“b‘æX=“f“a“b“a“+“g“a“bŽ¦’õºâºPhrased–Tabstractly‘ÿ:«,“this“bAÇecomes:Ž¦’ç¤ëMf:–¹–calls“f“[#2,“#2,“#3]Ž¡’fcalls–¹–g“[#3,“#1]Ž¡¡’ç¤g:–¹–calls“f“[#1,“#2,“#1]Ž¡’fcalls–¹–g“[#1,“#2]Ž¦’õºâºNo•¾9w›è;w“e˜iterate˜to˜a˜xed˜pAÇoin“t,‘ñ@gathering˜a˜complete˜set˜ofŽ¡’õºâthe–‡opAÇossible“v‘ÿ|ralues“of“eacš¾9h“argumen˜t.‘í$There“is“a“list“for“eac˜hŽ¡’õºâfunction,‘£ƒand–‡eacš¾9h“list“con˜tains“a“set“of“pAÇossible“v‘ÿ|ralues“forŽ¡’õºâeac•¾9h›Targumen“t.‘pInitially‘ÿ:«,˜eac“h˜argumen“t˜can˜only˜bAÇe˜itself:Ž¦’ç¤ëMF0–¹–=“[“{f.1},“{f.2},“{f.3}“]Ž¡’ç¤G0–¹–=“[“{g.1},“{g.2}“]Ž¦’õºâºA•¾9t›å¹eac“h˜iteration,‘ï?new˜appro“ximations˜are˜computed˜b“y˜us-Ž¡’õºâing–EÉthe“abstract“v¾9ersions“of“functions“to“lošAÇok“up“p˜ossibleŽ¡’õºâargumenš¾9t–\sets“in“the“existing“appro˜ximation.‘ð¥Also,‘m¿the“ex-Ž¡’õºâisting–Tappro¾9ximation“is“merged“in“wholesale:Ž¦’ç¤ëMF1–¹–=“F0“U“[“{f.2},“{f.2},“{f.3}“]Ž¡’)´TU–¹–[“{g.1},“{g.2},“{g.1}“]Ž¡’f=–¹–[“{f.1,“f.2,“g.1},“{f.2,“g.2},“{f.3,“g.1}“]Ž¡¡’ç¤G1–¹–=“G0“U“[“{f.3},“{f.1}“]ŽŽŽŽŽŸ’åäº24ŽŽŒ‹i •ºâ ý? £ ý€‘!´TëMU–¹–[“{g.1},“{g.2}“]Ž¤
‘
f=–¹–[“{f.3,“g.1},“{f.1,“g.2}“]Ž¡¡‘ûç¤F2–¹–=“F1“U“[“{f.2,“g.2},“{f.2,“g.2},“{f.3,“g.1}“]Ž¡‘+'€[–¹–{f.3,“g.1},“{f.1,“g.2},“{f.3,“g.1}“]Ž¡‘
f=–¹–[“{f.1,“f.2,“f.3,“g.1,“g.2},Ž¡‘ú¾{f.1,–¹–f.2,“g.2},“{f.3,“g.1}“]Ž¡¡‘ûç¤G2–¹–=“G1“U“[“{f.3,“g.1},“{f.1,“f.2,“g.1}“]Ž¡‘!´TU–¹–[“{f.3,“g.1},“{f.1,“g.2}“]Ž¡‘
f=–¹–[“{f.3,“g.1},“{f.1,“f.2,“g.1,“g.2}“]Ž©Y‘íºâºEv•¾9en“tually–g<this“prošAÇcess“stabilises,‘{¶giving“the“follo¾9wing“p˜os-Ž¡‘íºâsible–Targumen¾9t“v‘ÿ|ralues:Ž¦‘ûç¤ëMf.1›	s,could–¹–have“value˜f.1,“f.2,“f.3,“g.1,“g.2Ž¡‘ûç¤f.2›	s,could–¹–have“value˜f.1,“f.2,“f.3,“g.1,“g.2Ž¡‘ûç¤f.3›	s,could–¹–have“value˜f.3,“g.1Ž¡‘ûç¤g.1›	s,could–¹–have“value˜f.3,“g.1Ž¡‘ûç¤g.2›	s,could–¹–have“value˜f.1,“f.2,“f.3,“g.1,“g.2Ž¦‘íºâºSo–E3wš¾9e“ha˜v˜e“t˜w˜o“candidate“constan˜t“argumen˜t“sets:Ž¡‘íºâëM{f.1,–¹–f.2,“f.3,“g.1,“g.2}–‚­ºand“ëM{f.3,‘¹–g.1}º.‘d{W‘ÿ:«e“rejectŽ¡‘íºâthe–`rst“bšAÇecause“it“do˜es“not“menš¾9tion“eac˜h“function“exactlyŽ¡‘íºâonce.‘Deducing–ë€that“ëM{f.1,–¹–f.2,“f.3,“g.1,“g.2}–뀺is“a“con-Ž¡‘íºâstan•¾9t›É™argumen“t˜set˜is˜correct,‘Ø¿but˜only˜under˜the˜conditionsŽ¡‘íºâthat,›Êñfor–¸Xthe“initial“call“in¾9to“the“group,˜ëMf.1–¹–==“f.2“==“f.3º,Ž¡‘íºâif–^UëMf“ºw¾9as“called,‘p•or“ëMg.1–¹–==“g.2–^Uºfor“an“initial“call“to“ëMgº.‘÷sThisŽ¡‘íºâlea•¾9v“es–—ëM{f.3,‘¹–g.1}“ºas“the“sole“constanš¾9t“argumen˜t“set“for“thisŽ¡‘íºârecursiv¾9e‘Tgroup.ŽŸ
‘íºâA‘#¥glaring–#â
aš¾9w“is“the“inabilit˜y“to“abstract“function“calls“whic˜hŽ¡‘íºâdo–anš¾9ything“more“than“pass“parameters“unc˜hanged.‘ZIn“thisŽ¡‘íºâcase,‘ë¢a–á5spAÇecial“v‘ÿ|ralue“ëMUnknown“ºis“used“to“denote“that“w¾9e“can-Ž¡‘íºânot–­bAÇe“sure“what“the“v‘ÿ|ralue“of“this“argumen¾9t“is.‘ù±F‘ÿ:«or“exampleŽ¦‘ûç¤ëMf–¹–x“y“=“f“x“(y+1)“+“f“y“xŽ¦‘íºâºabstracts‘TtoŽ¦‘ûç¤ëMf:–¹–calls“f“[#1,“Unknown]Ž¡‘
fcalls–¹–f“[#2,“#1]Ž¦‘íºâºDuring–çxpAÇoinš¾9ting,‘EÊëMUnknown“ºannihilates“an˜y“other“v‘ÿ|ralues“in“aŽ¡‘íºâset.‘ÐF‘ÿ:«or–;Éexample,‘Efa“set“ëM{f.1,–¹–g.2,“Unknown}–;ɺis“equiv‘ÿ|ralen¾9tŽ¡‘íºâsimply–to“ëM{Unknown}º.‘îžëMUnknown“ºrepresenš¾9ts“an“argumen˜t“ofŽ¡‘íºâuncertain–\Êorigin,‘n¨so“wš¾9e“disallo˜w“an˜y“constan˜t“argumen˜t“setŽ¡‘íºâcon¾9taining‘Tit.ŽŸ¥‘íºâ¹5.5Ž‘G·Preserving–LÎt¹™ypFfe“annotationsŽŸm‘íºâºSince–gAnna“wš¾9orks“with“t˜ypAÇe“annotated“Core“expressions,Ž¡‘íºâw¾9e–Åòneed“to“go“to“a“little“trouble“to“transform“the“annota-Ž¡‘íºâtions–-gtošAÇo.‘dªA¾9t“rst“glance,‘3lthis“lo˜oks“lik¾9e“a“simple“matter“ofŽ¡‘íºâmošAÇdifying–Fhfunction“t¾9yp˜es“p˜ertaining“to“sp˜ecialised“functions,Ž¡‘íºâbš¾9y–Éšdeleting“t˜ypšAÇes“of“sp˜ecialised“argumen¾9ts“and“inserting“theŽ¡‘íºât¾9ypšAÇes–’Jof“free“v‘ÿ|rariables“b˜eing“passed“as“extra“parameters.Ž¡‘íºâThis–.is“indeed“correct,‘M¤but“there's“more“to“it.‘	þRecall“theŽ¡‘íºâprevious–Tdenition“of“ëMfoldrº.‘pThe“t•¾9ypAÇec“hec“k“er‘Tinfers:Ž¦‘ûç¤ëMfoldr–¹–::“(a“->“b“->“b)“->“b“->“[a]“->“bŽ¦‘íºâºGiv¾9en–[)Lthe“usualŽ¡‘íºâHask¾9ell–!denition“of“ëM(++)›¹–::“[c]˜->˜[c]˜->˜[c]º,‘dŸw¾9e“canŽ¡‘íºâdeneŽŽŽ ý€’ç¤ëMconcat–¹–=“foldr“(++)“[]Ž¤ÐO’õºâºwhic¾9h–TspAÇecialises“to:Ž¡’ç¤ëMfoldrSpec–¹–a“[]‘Y„=“aŽ¤
’ç¤foldrSpec–¹–a“(x:xs)‘	s,=“x“++“foldrSpec“a“xsŽ¡¡’ç¤concat–¹–=“foldrSpec“[]ŽŸÐO’õºâºMerely–X†adding“and“deleting“argumenš¾9t“t˜ypAÇes“giv˜es“ëMfoldrSpecŽ¡’õºâºan–n`apparenš¾9t“t˜ypAÇe“ëMb–¹–->“[a]“->“bº,‘„¢whic˜h–n`is“toAÇo“gen-Ž¡’õºâeral.‘!W‘ÿ:«e–»äneed“to“unify“the“t¾9ypšAÇe“of“sp˜ecialising“v‘ÿ|ralueŽ¡’õºâëM(++)º,‘ÑëM[c]–¹–->“[c]“->“[c]–Þ½ºwith“the“t¾9ypAÇe“of“the“func-Ž¡’õºâtional–ã­parameter“it“replaces,›×BëMa–¹–->“b“->“bº,˜and‘ã­applyŽ¡’õºâthe–¡Eresulting“substitution“ëM{a–¹–->“[c],“b“->“[c]}–¡Eºto“theŽ¡’õºâannotations–ò”on“ëMfoldrSpecº.‘´0This“giv¾9es“ëMfoldrSpec‘¹–::Ž¡’õºâ[c]–¹–->“[[c]]“->“[c]º,–Tas“required.Ž©
’õºâSuc•¾9h›Œ+tric“k“ery˜should˜not˜come˜as˜a˜complete˜surprise.‘€öAf-Ž¡’õºâter–ŸÁall,‘Â\the“Milner-Hindley“t¾9ypAÇe“rules“for“an“application“ofŽ¡’õºâëMf–¹–::“(T1“->“T2)–-!ºto“ëMa–¹–::“T3–-!ºrequire“unication“of“ëMT1“ºwithŽ¡’õºâëMT3º.‘pThat's–Teectiv¾9ely“what“is“going“on“here.Ž¦’õºâThe–]Àneed“to“preservš¾9e“t˜ypAÇe“annotations“is“a“ma‘ƒŽjor“n˜uisanceŽ¡’õºâfrom–û°the“implemenš¾9tation“viewp•AÇoin˜t,‘5Gb“ecause–û°more“time“isŽ¡’õºâspAÇenš¾9t–gqin“xing“up“t˜ypAÇes“than“doing“the“transformationŽ¡’õºâpropAÇer.‘àŸW›ÿ:«ork–aâto“impro•¾9v“e–aâeciency“is“a“priorit¾9y˜.‘àŸThe“sc¾9hemeŽ¡’õºâdescrib•AÇed›hab“o•¾9v“e˜is˜a˜rst˜implemen“tation˜in˜whic“h˜correct-Ž¡’õºâness–Twš¾9as“more“impAÇortan˜t“than“eciency‘ÿ:«.Ž©5’õºâ¹5.6Ž’G·Monomo¹™rphisationŽŸm’õºâºBy–Ýcomparison“with“rstication,‘«\monomorphisation“is“sim-Ž¡’õºâple.›;÷Monomorphisation–Öis“a“t•¾9w“o-phase–ÖproAÇcess.˜The“rstŽ¡’õºâpass–Jfconducts“what“amounš¾9ts“to“a“depth-rst“searc˜h“fromŽ¡’õºâëMmain–d©ºto“disco•¾9v“er–d©all“required“instances.‘
nThe“second“passŽ¡’õºâclones–Á×coAÇde,‘,÷c¾9hanges“function“names“accordingly“and“re-Ž¡’õºâstores–TdepAÇendancy“order.Ž¦’õºâ¹5.6.1Ž’úíCollecting–LÎthe“instancesŽŸm’õºâºI‘õÓam–ö
indebted“to“Mark“Jones“for“suggesting“the“follo¾9wingŽ¡’õºâalgorithm.‘GYW‘ÿ:«e–x÷carry“a“set“ëMinstances“ºto“accum¾9ulate“theŽ¡’õºâev•¾9en“tual–g|result,‘¼and“a“stacš¾9k“ëMtoVisit“ºrecording“places“w˜eŽ¡’õºâneed–ÒLto“visit.‘Elemen¾9ts“of“ëMinstances“ºand“ëMtoVisit“ºare“pairsŽ¡’õºâof–”z(function“name,‘ôCt¾9ypšAÇe“expression)“sp˜ecifying“a“particu-Ž¡’õºâlar–C—instance“of“a“function.‘§8The“tš¾9ypAÇe“expressions“are“alw˜a˜ysŽ¡’õºâmonomorphic.ŽŸ
’õºâSince–B
ëMmain“ºmaš¾9y“bAÇe“of“an˜y“t˜ypAÇe,‘Í6w˜e“trivially“monomor-Ž¡’õºâphise–£zit“bš¾9y“substituting“an˜y“t˜ypAÇe“v‘ÿ|rariables“with“ëMIntº.‘ÆáThisŽ¡’õºâgiv¾9es–ªa“single“initial“v‘ÿ|ralue“for“ëMtoVisitº,‘!with“ëMinstances“ºini-Ž¡’õºâtially–H	bAÇeing“empt¾9y‘ÿ:«.‘´The“nal“v‘ÿ|ralue“of“ëMinstances“ºis“thenŽ¡’õºâëMsearch(instances,‘¹–toVisit)º,‘Twhere:ŽŸÐO’õºâëMsearch(instances,‘¹–toVisit)Ž¡’ç¤=–¹–if‘æX[toVisit“is“empty]Ž¡’
ZÐthen‘	s,instancesŽ¡’
ZÐelseŽ¡’
ZÐlet‘,Ânext–¹–=“head“toVisitŽ¡’
ZÐin–æXif“next–¹–`elem`“instancesŽ¡’F
Ø[We've–¹–already“been“here]Ž¡’
ZÐthen‘	s,search(instances,–¹–tail“toVisit)Ž¡’
ZÐelse‘	s,[Get–¹–the“function“specified“by“next.Ž¡’.mêFind–¹–out“what“instances“of“otherŽŽŽŽŽŸ’åäº25ŽŽŒ‹~ •ºâ ý? £ ý€‘&mêëMfunctions–¹–are“called.‘	s,Add“theseŽ¤
‘&mêinstances–¹–to“(tail“toVisit)“givingŽ¡‘&mêtoVisitAug,–¹–and“then“do]Ž¡‘&mêsearch({next}–¹–U“instances,“toVisitAug)Ž¤zÁ‘íºâºF‘ÿ:«or–Texample,“giv¾9enŽ¡‘ûç¤ëMid–¹–x‘	s,=“xŽ¤
‘ûç¤f–¹–x‘,Â=“id“xŽ¡‘ûç¤main‘	s,=–¹–id“42“+“ord“(f“'c')Ž¤zÁ‘íºâºthe–Talgorithm“runs“through“these“states:Ž¡‘
fëMinstances‘YÆ"toVisitŽ¤
‘íºâ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Ž¡‘íºâ{}‘zÙ<[(main,‘¹–Int)]Ž¡¡‘íºâ{(main,–¹–Int)}‘FßÊ[(id,‘,ÂInt“->“Int),Ž¡‘vÀà(f,‘æXChar–¹–->“Char)]Ž¡¡‘íºâ{(main,–¹–Int),‘FßÊ[(f,‘æXChar“->“Char)]Ž¡‘òtx(id,‘,ÂInt–¹–->“Int)}Ž¡¡‘íºâ{(main,–¹–Int),‘FßÊ[(id,‘,ÂChar“->“Char)]Ž¡‘òtx(id,‘,ÂInt–¹–->“Int),Ž¡‘òtx(f,‘æXChar–¹–->“Char)}Ž¡¡‘íºâ{(main,‘¹–Int),‘FßÊ[]Ž¡‘òtx(id,‘,ÂInt–¹–->“Int),Ž¡‘òtx(id,‘,ÂChar–¹–->“Char),Ž¡‘òtx(f,‘æXChar–¹–->“Char)}ŽŸzÁ‘íºâºThis–™givš¾9es“t˜w˜o“instances“for“ëMidº.‘ÜBecause“the“abstract“in˜ter-Ž¡‘íºâpretation–´Œof“t¾9ypšAÇes“maps“b˜oth“ëMInt“ºand“ëMChar“ºto“the“t•¾9w“o‘´Œp˜oin“tŽ¡‘íºâdomain,‘¥only–Ó.one“of“those“instances“is“needed“for“analysisŽ¡‘íºâpurpAÇoses.‘ú In–_9general,‘±²wš¾9e“can“exploit“the“fact“that“man˜yŽ¡‘íºâdieren•¾9t›@Rt“ypAÇes˜are˜assigned˜the˜same˜domain˜to˜reduce˜theŽ¡‘íºâprogram–•±expansion“caused“b¾9y“monomorphisation.‘†F‘ÿ:«ar“andŽ¡‘íºâa•¾9w“a“y–èŒthe“easiest“w•¾9a“y–èŒto“do“this“is“to“transform“the“t¾9ypAÇe“an-Ž¡‘íºânotations–ñnto“domain“annotations“bAÇefore“monomorphisation,Ž¡‘íºâusing–ùýthe“results“of“section“2.2.5.‘ST¾9ypAÇe“v‘ÿ|rariables“are“simplyŽ¡‘íºâreplaced–Tb¾9y“domain“v‘ÿ|rariables.ŽŸòë‘íºâ¹5.6.2Ž‘úíCloning‘LÎcoFfdeŽŸm‘íºâºThis–¨èis“fairly“trivial.‘×+Eac¾9h“function“is“duplicated“once“pAÇerŽ¡‘íºâinstance,‘ܶwith–´Öappropriate“new“names.‘úõThe“function“b•AÇo“d-Ž¡‘íºâies›#\ha•¾9v“e˜their˜call˜sites˜moAÇdied˜to˜refer˜to˜appropriatelyŽ¡‘íºânamed–_2instances“in“previous“groups,›qªand“this“one,˜if“recur-Ž¡‘íºâsivš¾9e.‘\Then–Ðthe“b•AÇo“dies–Ðha˜v˜e“the“t˜ypAÇe“v‘ÿ|rariables“in“their“anno-Ž¡‘íºâtations–çãsubstituted“appropriately“for“eacš¾9h“dieren˜t“instanceŽ¡‘íºârequired.‘¶eThe–ûen¾9tire“program“can“bšAÇe“pro˜cessed“in“a“singleŽ¡‘íºâtop-to-bAÇottom‘Tpass.Ž©
‘íºâThe–ŠËonly“slighš¾9tly“tric˜ky“problem“is“rebuilding“recursiv˜eŽ¡‘íºâgroups–”0so“as“to“mainš¾9tain“depAÇendancy–ÿ:«.‘™F“or‘”0non-recursiv˜eŽ¡‘íºâclones,›/this–Ã…is“easy‘ÿ:«,˜but“bAÇecause“of“the“existance“of“cer-Ž¡‘íºâtain›2Äcon•¾9triv“ed˜recursiv“e˜functions,‘: main“taining˜depAÇendancyŽ¡‘íºâin–ó«the“recursivš¾9e“case“can“bAÇe“complicated.‘·vW‘ÿ:«e“a˜v˜oid“theseŽ¡‘íºâproblems–"dbš¾9y“lumping“all“the“clones“arising“from“a“recursiv˜eŽ¡‘íºâfunction–ÿ‹group“in¾9to“a“single“ëMletrecº,‘:and“passing“the“pro-Ž¡‘íºâgram–Ta“third“time“though“the“depAÇendancy“analyser.Ž¦‘íºâDespite–8hthese“complications,‘,the“monomorphiser“is“ex-Ž¡‘íºâtremely–aÞquicš¾9k“and“doAÇes“not“pro˜v˜e“a“signican˜t“limitationŽ¡‘íºâon‘TpAÇerformance.ŽŽŽ ý€’õºâ¹6Ž’”DiscussionŽŸ†´’õºâºThis–ÙÎsection“draš¾9ws“together“the“detailed“tec˜hnical“threadsŽ¤
’õºâexpAÇounded–‡in“the“previous“three“sections,‘š“bš¾9y“presen˜tingŽ¡’õºâsome–äkpšAÇerformance“results,‘1and“lo˜oking“at“related“and“fur-Ž¡’õºâther–Èxwš¾9ork.‘5ÜBut“w˜e“bAÇegin“b˜y“lošAÇoking“at“some“p˜erformanceŽ¡’õºâissues.ŽŸtŠ’õºâ¹6.1Ž’G·Putting–LÎit“all“togetherŽŸm’õºâºThro¾9wing–°realistically“sized“programs“at“the“analyser“re-Ž¡’õºâvš¾9ealed–½psome“pAÇerformance“problems“whic˜h“w˜ere“traced“toŽ¡’õºâniceties–Xüin“the“inš¾9terface“bAÇet˜w˜een“the“abstract“in˜terpreter“andŽ¡’õºâthe–Tterm“rewriter.Ž©
’õºâP¾9erformance–òrproblems“appAÇear“when“the“term“rewriting“sys-Ž¡’õºâtem–u,is“fed“a“giganš¾9tic“term“to“simplify–ÿ:«.‘;ùUsually“,‘"suc˜h‘u,termsŽ¡’õºâreduce–-œto“something“quite“trivial.‘eHIt“is“impAÇortan¾9t“to“realiseŽ¡’õºâthat–}0the“abstract“in¾9terpreter“will“generate“absolutely“enor-Ž¡’õºâmous–úUterms,‘3–espAÇecially“from“source“text“whic¾9h“has“deeplyŽ¡’õºânested–BÊfunction“calls“or“deeply“nested“ëMcase“ºexpressions,‘læbAÇothŽ¡’õºâof–Ëwhic¾9h“are“quite“common.‘>÷F‘ÿ:«or“example,‘ùthe“bigger“pro-Ž¡’õºâgrams–2menš¾9tioned“in“section“6.2“generated“terms“whic˜h,‘_êwhenŽ¡’õºâprett•¾9y-prin“ted–#in“the“stš¾9yle“used“in“this“papAÇer,‘&„co˜v˜ered“liter-Ž¡’õºâally–Ttens“of“A4“pages.Ž¦’õºâAnalysis–²¾of“a“program“proAÇceeds“as“follo¾9ws.‘ô­First,‘Úthe“pro-Ž¡’õºâgram–L•is“passed“in“its“en•¾9tiret“y–L•through“the“abstract“in¾9ter-Ž¡’õºâpreter,‘0generating–Ä«a“correspAÇonding“collection“of“recursiv¾9eŽ¡’õºâequations–\õ(or“terms).‘óTThese“equations“are“h¾9ugely“redun-Ž¡’õºâdan¾9t–`Ðand“are“simplied“individually‘ÿ:«,‘³®without“reference“toŽ¡’õºâeacš¾9h–“nother.‘–¾Finally‘ÿ:«,‘òôthe“xpAÇoin˜ting“system“tra˜v˜els“alongŽ¡’õºâthe–_úgroups“of“equations,‘²£accumš¾9ulating“an“en˜vironmen˜t“ofŽ¡’õºâ\solv•¾9ed"›˜Ìequations.‘¦×A‘˜ªsolv“ed˜equation˜is˜self-con“tained:‘#_itŽ¡’õºâdoAÇes–2ònot“refer“to“the“abstract“inš¾9terpretation“of“an˜y“otherŽ¡’õºâfunction.‘ëÌSolving–ƒgnon-recursiv¾9e“equations“is“a“simple“matterŽ¡’õºâof–Ê\substituting“in“the“abstract“in¾9terpretations“of“other“func-Ž¡’õºâtions,›7and–Ösimplifying.‘,öF‘ÿ:«or“recursiv¾9e“functions,˜this“stage“isŽ¡’õºâfollo•¾9w“ed›Tb“y˜xpAÇoin“ting.Ž¦’õºâWhat–Ðreally“ruins“pšAÇerformance“is“not“xp˜oin¾9ting,‘C.but“theŽ¡’õºâinitial–úsimplication“of“terms“whic¾9h“emerge“from“the“ab-Ž¡’õºâstract–èeinš¾9terpreter.‘•¤This“problem“w˜as“largely“alleviated“b˜yŽ¡’õºâgiving–wªthe“abstract“inš¾9terpreter“a“little“more“in˜telligence,‘?inŽ¡’õºâthe–Tform“of:ŽŸît’äëPŽŽŽ’:âºThe›#žt¾9yp•AÇe-sp“ecic˜ëMAbsVal˜ºrewrites˜describ“ed˜in˜sec-Ž¡’:âtion‘T4.6.ŽŸBF’äëPŽŽŽ’:âºA‘ëknoš¾9wledge–€Iof“k˜ey“ëMContext“ºrewrite“rules.‘]PIn“par-Ž¡’:âticular,‘~9the–6rules“for“ëMcase“ºstatemen¾9ts“generate“largeŽ¡’:âexpressions›xin•¾9v“olving˜ëMCMeetº,–"ëMCJoinº,“ëMStop1˜ºand˜ëMStop2º.Ž¡’:âA‘Ôhandful–Ôyof“rules“emš¾9b•AÇo“dying–Ôysimple“facts“suc˜h“asŽ¡’:âëMCMeet–¹–[...“Stop2“...]“==“Stop2–Tºw¾9ere“added.ŽŸ¡#’:âBet•¾9w“een–Yêthem,‘gthe“sizes“of“terms“generated“w¾9ere“some-Ž¡’:âtimes–Ù‚cut“bš¾9y“t˜w˜o“orders“of“magnitude,‘Jand“pAÇerfor-Ž¡’:âmance–Twš¾9as“m˜uc˜h“impro˜v˜ed.ŽŸîu’õºâA‘m†second–m±pAÇerformance“problem“w¾9as“traced“to“the“initial“sim-Ž¡’õºâplication–M²of“terms“emerging“from“the“abstract“in¾9terpreter.Ž¡’õºâThese–=¬terms“are“simplied“without“reference“to“eac¾9h“other.Ž¡’õºâIt–ïÚturns“out“to“bšAÇe“b˜etter“to“simplify“a“term“only“whenŽ¡’õºâw•¾9e›ñxkno“w˜the˜solv“ed˜v‘ÿ|ralues˜of˜the˜other˜terms˜it˜refers˜to,Ž¡’õºâbAÇecause–V”knoš¾9wing“these“v‘ÿ|ralues“mak˜es“the“nal“term“m˜uc˜hŽ¡’õºâsmaller.‘Ñ€In–§eect,‘Ëpthis“is“ac•¾9hiev“ed–§simply“b¾9y“omitting“thisŽ¡’õºâsimplication–?Wpass“altogether.‘šzF‘ÿ:«or“at“least“one“input,‘IØanal-Ž¡’õºâysis–Ttime“wš¾9as“cut“b˜y“a“factor“of“v˜e.ŽŽŽŽŽŸ’åä26ŽŽŒ‹˜d •ºâ ý? £ þ	¦dŸ¸lΑíºâŸ´S4‰fföÌ̤ÿþ•ÌÍ ‹Ùš„’Ù˜ffŸ­32‘àŸÐŒÍ‰ffÍF§¡“Ÿ„
ff‘fg„
ff‘6˜ý„
ffŽ‘X¦GŸ„
ff‘fg„
ffŽ‘z3ñºF‘ÿ:«or–Ta“complete“run‘ZwŸ„
ff‘fg„
ffŽ’ýœIAnalysis‘Tonly‘˜VŸ„
ff‘fg„
ffŽ’W5áCompiling–Twith“ëMghc-0.10‘}Ÿ„
ff‘fg„
ffŽŽ¤fh‘Z¦G„ffr `ŽŽŸ™˜“¤„
ff‘fg„
ff‘33ŸüÿþºProgram‘H³¡„
ffŽ‘>2–Lines‘33Ÿ„
ff‘fg„
ffŽ‘kg&Time‘33Ÿ„
ffŽ’ÚClaim‘33Ÿ„
ffŽ’Ê|´Space‘33Ÿ„
ff‘fg„
ffŽ’ù‘ŸTime‘33Ÿ„
ffŽ’++SClaim‘33Ÿ„
ff‘fg„
ffŽ’[FwTime‘33Ÿ„
ffŽ’{%äanalysis–Ttime“as“%‘33Ÿ„
ff‘fg„
ffŽŽ¡‰ffÍF§Ÿÿþ“Ÿ„
ff‘fg„
ff‘6˜ý„
ffŽ‘X¦GŸ„
ff‘fg„
ffŽ’…¬úŸ„
ffŽ’º[Ÿ„
ffŽ’æÐÀŸ„
ff‘fg„
ffŽ’×sŸ„
ffŽ’H…˜Ÿ„
ff‘fg„
ffŽ’uŒKŸ„
ffŽ’ËF§Ÿ„
ff‘fg„
ffŽŽ¤
“¤„
ff‘fg„
ff‘33Ÿüÿþconcat‘0€¡„
ffŽ‘?ìëO<‘Tº10‘33Ÿ„
ff‘fg„
ffŽ‘iL©0.42‘Ts‘33Ÿ„
ffŽ’”†1.485‘TM‘33Ÿ„
ffŽ’É4´47.2‘Tk‘33Ÿ„
ff‘fg„
ffŽ’÷w"0.18‘Ts‘33Ÿ„
ffŽ’"±0.586‘TM‘33Ÿ„
ff‘fg„
ffŽ’Y+ú0.92‘Ts‘33Ÿ„
ffŽ’²Ò19‘T%‘33Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff‘33Ÿüÿþzip3‘ ô
¡„
ffŽ‘?ìëO<‘Tº10‘33Ÿ„
ff‘fg„
ffŽ‘iL©0.52‘Ts‘33Ÿ„
ffŽ’”†1.793‘TM‘33Ÿ„
ffŽ’É4´56.1‘Tk‘33Ÿ„
ff‘fg„
ffŽ’÷w"0.17‘Ts‘33Ÿ„
ffŽ’"±0.570‘TM‘33Ÿ„
ff‘fg„
ffŽ’Y+ú1.00‘Ts‘33Ÿ„
ffŽ’²Ò17‘T%‘33Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff‘33Ÿüÿþw¾9ang‘•Ó¡„
ffŽ‘E“385‘33Ÿ„
ff‘fg„
ffŽ‘d¬«23.62‘Ts‘33Ÿ„
ffŽ’æ‘85.396‘TM‘33Ÿ„
ffŽ’Ä”¶908.8‘Tk‘33Ÿ„
ff‘fg„
ffŽ’÷w"9.15‘Ts‘33Ÿ„
ffŽ’
15.861‘TM‘33Ÿ„
ff‘fg„
ffŽ’T‹ü43.61‘Ts‘33Ÿ„
ffŽ’²Ò21‘T%‘33Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff›33Ÿüÿþw•¾9a“v“e4main˜¡„
ffŽ‘E“619‘33Ÿ„
ff‘fg„
ffŽ‘d¬«43.40‘Ts‘33Ÿ„
ffŽ’‹F“116.207‘TM‘33Ÿ„
ffŽ’¿ô¸2897.7‘Tk‘33Ÿ„
ff‘fg„
ffŽ’ò×$21.62‘Ts‘33Ÿ„
ffŽ’
43.239‘TM‘33Ÿ„
ff‘fg„
ffŽ’Oëþ199.29‘Ts‘33Ÿ„
ffŽ’²Ò11‘T%‘33Ÿ„
ff‘fg„
ffŽŽ¡“¤„
ff‘fg„
ff‘33Ÿüÿþag2hs‘¼:¡„
ffŽ‘@ó1047‘33Ÿ„
ff‘fg„
ffŽ‘`­208.95‘Ts‘33Ÿ„
ffŽ’‹F“275.245‘TM‘33Ÿ„
ffŽ’¿ô¸9653.8‘Tk‘33Ÿ„
ff‘fg„
ffŽ’î7&126.42‘Ts‘33Ÿ„
ffŽ’q135.335‘TM‘33Ÿ„
ff‘fg„
ffŽ’Oëþ100.68‘Ts‘33Ÿ„
ffŽ’­hÔ126‘T%‘33Ÿ„
ff‘fg„
ffŽŽ¡“Ÿ„
ff‘fg„
ff‘6˜ý„
ffŽ‘X¦GŸ„
ff‘fg„
ffŽ’…¬úŸ„
ffŽ’º[Ÿ„
ffŽ’æÐÀŸ„
ff‘fg„
ffŽ’×sŸ„
ffŽ’H…˜Ÿ„
ff‘fg„
ffŽ’uŒKŸ„
ffŽ’ËF§Ÿ„
ff‘fg„
ffŽŽŸfh‰ffÍF§ŽŽŽŸEÌÌ’Ÿ¸/T‘ÿ:«able–T2:‘pSome“pAÇerformance“gures“for“ëNAnnaŽŽŸ
Ž’öff„’Ù˜ffŽŽ Œ@‰fföÌÌŽŽŽŽ öYœ þ%¦d‘íºâ¹6.2Ž‘G·Absolute–LÎpFferfo¹™rmance“resultsŽŸm‘íºâºFivš¾9e–ÿWtest“programs“w˜ere“used.‘ÚxThe“rst“t˜w˜o,‘9×ëMconcat“ºandŽ¤
‘íºâëMzip3º,‘ZŠare–utterly“trivial“and“w¾9ere“included“as“comparisonŽ¡‘íºâagainst–Ûìgures“presen¾9ted“in“[Sew93Ž‘/].‘p7ëMwang“ºand“ëMwave4mainŽ¡‘íºâºare–‡Htakš¾9en“from“Pieter“Hartel's“bAÇenc˜hmark“suite“[HL92Ž‘÷l].‘íTheŽ¡‘íºâbiggest›²›one,–ÙíëMag2hsº,“is˜preproAÇcessor˜for˜a˜dialect˜of˜Hask¾9ellŽ¡‘íºâaugmen¾9ted–ˆðwith“attribute“grammar“[Joh87Ž‘Ä9]“facilities,‘¥Öwrit-Ž¡‘íºâten–Ãbš¾9y“Da˜vid“Rushall.‘	%ŸThe“analyser“w˜as“compiled“withŽ¡‘íºâChalmers–ÙîHask¾9ell-B‘Ù»0.999.4,‘with“
ags“ëM-fpbu‘¹–-Oº,“and“runŽ¡‘íºâusing–èçan“eighš¾9t“megab˜yte“heap“for“all“except“ëMag2hsº,‘Ëwhic˜hŽ¡‘íºârequired–~¢a“sixteen“megab¾9yte“heap.‘XYA‘~‡generational“garbageŽ¡‘íºâcollector–W×wš¾9as“emplo˜y˜ed.‘ãøT‘ÿ:«ests“w˜ere“run“on“a“ligh˜tly“loadedŽ¡‘íºâSun–ˆ¨Sparc“10/31,‘¤Ëand“eacš¾9h“test“w˜as“pAÇerformed“at“least“threeŽ¡‘íºâtimes.‘pTimes–Tare“user“CPU“seconds.Ž©
‘íºâSimply–Ãmeasuring“o•¾9v“erall–Ãrun“times“is“not“particularly“help-Ž¡‘íºâful,‘mbAÇecause–[†wš¾9e“really“w˜an˜t“to“establish“ho˜w“expAÇensiv˜e“thisŽ¡‘íºâanalyser–Š¢wš¾9ould“bAÇe“if“emplo˜y˜ed“in“a“Hask˜ell“compiler.‘|ZItŽ¡‘íºâseems–v²reasonable“to“consider“the“\bšAÇorder"“b˜et•¾9w“een–v²the“fron¾9tŽ¡‘íºâend–”and“the“analyser“itself“as“the“pAÇoinš¾9t“where“the“t˜ypAÇe-Ž¡‘íºâc•¾9hec“k“er–ØÁprošAÇduces“a“t¾9yp˜e-annotated“Core“tree,–äÞsince,“at‘ØÁleastŽ¡‘íºâin–q±Glasgoš¾9w“Hask˜ell,‘ÈÈthe“compiler“proAÇduces“this“tree“an˜y-Ž¡‘íºâw•¾9a“y‘ÿ:«.‘€So›ƒw“e˜presen“t˜gures˜not˜only˜for˜a˜complete˜run,‘butŽ¡‘íºâalso–§for“the“analysis“phase“propAÇer.‘6The“latter“category“co¾9v-Ž¡‘íºâers›Ç_rstication,–Öömonomorphisation,“abstract˜in¾9terpretationŽ¡‘íºâand–¼xpAÇoinš¾9ting,‘DÛall“of“whic˜h“are“legitimate“analysis“expAÇenses.Ž¦‘íºâT‘ÿ:«o–assess“whether“or“not“wš¾9e“are“approac˜hing“the“righ˜t“ball-Ž¡‘íºâpark,‘C§wš¾9e–;timed“Glasgo˜w“Hask˜ell“0.10“compiling“the“programsŽ¡‘íºâin¾9to–®*C,“and“compared“those“times“with“the“analysis“phaseŽ¡‘íºâtime–á^of“Anna.‘The“compiler“options“w¾9ere“ëM-O2‘¹–-Cº.“CompilerŽ¡‘íºâsemispace–Œ¡sizes“wš¾9ere“3“megab˜ytes“for“the“small“t˜w˜o,‘ªsand“8Ž¡‘íºâmegabš¾9ytes–¸¡for“the“big“three:‘cthis“turned“out“to“bAÇe“plen˜t˜y‘ÿ:«.Ž¡‘íºâThe–¢times“repAÇorted“for“Glasgoš¾9w“Hask˜ell“are“for“the“compilerŽ¡‘íºâpropAÇer,–£(that›†œis,“that˜part˜of˜the˜compiler˜whic¾9h˜is˜itself˜writ-Ž¡‘íºâten–fin“Haskš¾9ell,‘ëand“whic˜h“translates“the“output“of“the“Y‘ÿ:«accŽ¡‘íºâparser–Tin¾9to“C.Ž¦‘íºâT‘ÿ:«able–¿À2“presenš¾9ts“the“gures.‘µThe“maxim˜um“residency“g-Ž¡‘íºâures–½wš¾9ere“obtained“using“a“cop˜ying“collector“with“heap“sizesŽ¡‘íºâset–¯only“just“big“enough.‘êðThis“quan•¾9tit“y–¯is“omitted“for“theŽ¡‘íºâanalysis-only–°gures“bAÇecause“of“the“diculties“of“decidingŽ¡‘íºâon–	Èho¾9w“to“divide“space“expšAÇenses“b˜et•¾9w“een–	Èthe“fron¾9t“end“andŽ¡‘íºâthe–Tanalysis“phase.Ž¦‘íºâF‘ÿ:«or–¯{the“big“three,›Ötimes“are,˜v¾9ery“roughly‘ÿ:«,˜divided“equallyŽ¡‘íºâbAÇet•¾9w“een–âÿthe“fron¾9t“end“and“analysis“phases.‘©ëMag2hs“ºhas“a“rel-Ž¡‘íºâativ¾9ely–؈large“analysis“time“in“comparison“to“its“size.‘f
ThisŽ¡‘íºâis–4bAÇecause“it“makš¾9es“considerable“use“of“lazy“pattern“matc˜h-Ž¡‘íºâing,‘FÆwhicš¾9h–	°translates“to“a“large“quan˜tit˜y“of“complex“CoreŽŽŽ þ%¦d’õºâexpressions.‘ÓìThese–R}in“turn“generate“some“large,‘¡ÇcomplexŽ¤
’õºâsets–(zof“equations“for“the“xpAÇoinš¾9ter“to“solv˜e.‘UâA‘(3tec˜hniqueŽ¡’õºâmenš¾9tioned–9ìin“section“6.4“migh˜t“help“here.‘Š9F‘ÿ:«or“the“largerŽ¡’õºâproblems,›—¢space–x4consumption“is“of“concern.‘èMuc¾9h,˜if“not“theŽ¡’õºâma‘ƒŽjoritš¾9y‘ÿ:«,‘©@of–‹«the“space“used“is“related“to“fron˜t-end“proAÇcess-Ž¡’õºâing,‘›+and–€fit“seems“likš¾9ely“that“the“analysis“itself“is“relativ˜elyŽ¡’õºâcš¾9heap–Þon“space.‘¶F‘ÿ:«urther“in˜v˜estigation“with“a“heap“prolerŽ¡’õºâis‘Tnecessary‘ÿ:«.Ž©
’õºâThe–±results“of“comparing“analysis“time“with“a“run“of“Glasgo¾9wŽ¡’õºâHaskš¾9ell–Ueon“the“same“program“are“in˜triguing.‘ÜvThe“tests“are“atŽ¡’õºâleast–øfair“in“the“sense“that“bAÇoth“Anna“and“the“Hask¾9ell“com-Ž¡’õºâpiler–Äare“written“in“Hask¾9ell,‘
{so“neither“has“an“unfair“adv‘ÿ|ran-Ž¡’õºâtage.‘ñàJust–•£bš¾9y“themselv˜es,‘¯-it“is“a“little“un˜usual“that“ëMghc“ºcom-Ž¡’õºâpiled–šÍëMag2hs“ºin“almost“half“the“time“it“toAÇok“for“ëMwave4mainº.Ž¡’õºâIt–’+maš¾9y“bAÇe“that“the“hea˜vy“use“of“n˜umeric“o˜v˜erloading“in“ëMwangŽ¡’õºâºand–ŠµëMwave4main“ºhas“slo•¾9w“ed›Šµdo“wn˜ëMghc˜ºas˜it˜will˜ha“v“e˜hadŽ¡’õºâto–îûgenerate“and“optimise“large“quan¾9tities“of“dictionary“han-Ž¡’õºâdling–bdcoAÇde.‘àËëMag2hsº,›†.b¾9y“comparison,˜is“mostly“string“handling:Ž¡’õºâthere–ÜÌis“little“o•¾9v“erloading–ÜÌin“it.‘rÙAnna“has“a“naiv¾9e“view“ofŽ¡’õºâthe–ÐKHaskš¾9ell“n˜um˜bAÇers“{“it“only“kno˜ws“abAÇout“ëMIntº,‘ÿso“it“willŽ¡’õºânot›)ôha•¾9v“e˜seen˜an“y˜suc“h˜n“umeric˜o“v“erloading.‘ZQIn˜order˜toŽ¡’õºâmakš¾9e–¨Anna“accept“these“t˜w˜o“programs,‘Ëw˜e“had“to“strip“outŽ¡’õºâthe–‘äextensivš¾9e“t˜ypAÇe“signatures“whic˜h“had“bAÇeen“placed“thereŽ¡’õºâexpressely–vxto“eliminate“nš¾9umeric“o˜v˜erloading.‘?ÝThese“factorsŽ¡’õºâma•¾9y›8·w“ell˜ha“v“e˜conspired˜to˜giv“e˜Anna˜a˜remark‘ÿ|rably˜go•AÇo“d˜rel-Ž¡’õºâativ•¾9e›Š#sho“wing˜for˜ëMwang˜ºand˜ëMwave4mainº,‘§Walthough˜it˜is˜hardŽ¡’õºâto–ÂèbAÇelievš¾9e“they“accoun˜t“for“all“the“dierence“bAÇet˜w˜een“11%Ž¡’õºâ(ëMwave4mainº)–Tand“126%“(ëMag2hsº).Ž¦’õºâBecause–½ëMwang“ºand“ëMwave4main“ºare“mac¾9hine-generatedŽ¡’õºâHask¾9ell,‘LJthe–ALexpressions“in“them“are“reasonably“simple“andŽ¡’õºâsmall.‘†·By–8Ácomparison,‘Aœthe“desugared“v¾9ersion“of“ëMag2hs“ºcon-Ž¡’õºâtained–ušsome“v¾9ery“large“expressions“and“some“quite“compli-Ž¡’õºâcated–-±structured“t•¾9ypšAÇes.‘e†W‘ÿ:«atc“hing–-±the“b˜eha¾9viour“of“AnnaŽ¡’õºâon–Þ³this“example,‘é it“is“clear“that“the“ma‘ƒŽjorit¾9y“of“the“analysisŽ¡’õºâtime–Jïis“spšAÇen¾9t“xp˜oin¾9ting“a“single“large“group“of“ab˜out“t•¾9w“en“t“yŽ¡’õºâfunctions–µÀwhicš¾9h“arose“from“the“extensiv˜e“use“of“lazy“patternŽ¡’õºâmatc¾9hing.‘~ÀIt–6seems“plausible“that“this“particular“group“didŽ¡’õºânot–œãcause“anš¾9y“similar“dicult˜y“to“ëMghcº,‘¾Çand“it“ma˜y“also“bAÇeŽ¡’õºâpšAÇossible–x£that“ëMghcº's“desugarer“did“a“b˜etter“job“than“Anna'sŽ¡’õºâin–qCtranslating“the“pattern“matc•¾9hing.‘0<Nev“ertheless,‘ˆ>the‘qCdis-Ž¡’õºâparitš¾9y–çin“relativ˜e“analysis/compile“costs“bAÇet˜w˜een“ëMag2hs“ºandŽ¡’õºâthe–òÔother“t•¾9w“o–òÔbig“examples“is“a“wš¾9arning“that“w˜e“should“notŽ¡’õºâread–¡\toAÇo“m•¾9uc“h›¡\in“to˜these˜measuremen“ts˜bAÇey“ond˜the˜pAÇerhapsŽ¡’õºâheartening–ò]conclusion“that“wš¾9e“are“indeed“approac˜hing“theŽ¡’õºârigh¾9t–Tballpark“for“analyser“pAÇerformance.ŽŽŽŽŽŽŸ’åä27ŽŽŒ‹´† •ºâ ý? £ ý€‘íºâ¹6.3Ž‘G·Related‘LÎw•¹™o“rkŽŸm‘íºâºMycroft's–òoriginal“wš¾9ork“[Myc80Ž‘¸|]“on“applying“abstract“in˜ter-Ž¤
‘íºâpretation–ûÍto“the“analysis“of“functional“programs“spark¾9ed“oŽ¡‘íºâin•¾9tense›[éw“ork˜on˜forw“ard˜analyses.‘Þ¢A‘[¹forw“ard˜strictness˜anal-Ž¡‘íºâysis–kktells“us“the“denedness“of“a“function“application“giv¾9enŽ¡‘íºâthe–±¿denedness“of“the“argumen¾9ts.‘û>Landmark“papAÇers“includeŽ¡‘íºâthe–*Burn-Hankin-Abramsky“wš¾9ork“[BHA85Ž‘¬b]“whic˜h“put“higherŽ¡‘íºâorder–„analysis“on“a“rm“theoretical“foAÇoting,‘TPand“W‘ÿ:«adler'sŽ¡‘íºâpapAÇer–ÌÓ[W‘ÿ:«ad87Ž‘¿˜]“whicš¾9h“sho˜w˜ed“ho˜w“one“migh˜t“deal“sensiblyŽ¡‘íºâwith–.sum-of-prošAÇducts“t•¾9yp˜es.‘èýImplemen“tors–.made“m•¾9uc“h‘.ofŽ¡‘íºânding–¤xpAÇoinš¾9ts“using“the“F‘ÿ:«ron˜tiers“algorithm,‘º¼massaging“itŽ¡‘íºâextensiv¾9ely–mèto“deal“with“higher“order“functions“[HH91Ž‘>],‘esum-Ž¡‘íºâof-pro•AÇducts›~#t¾9yp“es˜[Sew91Ž‘/]˜and˜p“olymorphism˜[Sew93Ž‘/].‘VÜDe-Ž¡‘íºâspite–ѽthis“and“other“tric•¾9k“ery–ѽ[HH92Ž‘>]“[Sew92Ž‘/],‘ßBfron¾9tiers“failedŽ¡‘íºâto–Âdeliv¾9er“usable“pAÇerformance“for“high-denition“strictnessŽ¡‘íºâanalysis–päfor“an¾9ything“other“than“trivial“inputs,‘‘Èand“there“areŽ¡‘íºâgo•AÇo“d–¬õtheoretical“reasons“for“bAÇelieving“the“situation“cannotŽ¡‘íºâbAÇe‘Timpro•¾9v“ed.Ž©
‘íºâStarting–{at“around“the“same“time,‘™íanother“scš¾9hoAÇol“of“though˜tŽ¡‘íºâw•¾9as›þÐdev“eloping˜bac“kw“ards,–Qor˜pro‘ƒŽjection,“analyses.‘ïA‘þÊbac¾9k-Ž¡‘íºâwš¾9ards–·analysis“sho˜ws“ho˜w“the“seman˜tic“quan˜tit˜y“in“questionŽ¡‘íºâ-–Jphere,‘W·demand“for“ev‘ÿ|raluation“-“propagates“from“a“functionŽ¡‘íºâapplication–@to“the“individual“argumen¾9ts.‘Õ\Hughes“[Hug90Ž‘ó']“ar-Ž¡‘íºâgues–¼Ûthat“bac•¾9kw“ards–¼Ûanalyses“are“inherenš¾9tly“more“ecien˜tŽ¡‘íºâthan–U[forwš¾9ard“ones,‘e]bAÇecause“the“function“spaces“with“whic˜hŽ¡‘íºâthe–¯Àanalyses“deal“are“smaller“in“the“bac•¾9kw“ards‘¯Àcase.‘ú”Pro‘ƒŽjec-Ž¡‘íºâtion–êãanalysis“deals“easily“with“sum-of-prošAÇducts“t¾9yp˜es,‘ GandŽ¡‘íºâcaptures–ÔZcertain“propAÇerties,›Dsuc¾9h“as“head-strictness,˜thatŽ¡‘íºâseem–žto“elude“forw¾9ard“analyses.‘¶ˆA‘ãgo•AÇo“d–žreference“for“pro-Ž¡‘íºâjection–Þanalysis“is“[WH87Ž‘±].‘v¯Later“wš¾9ork“sho˜w˜ed“ho˜w“to“doŽ¡‘íºâmak¾9e–+únon-
at“pro‘ƒŽjection“analysis“pAÇolymorphic“[HugŽ‘³+],‘q¤andŽ¡‘íºâa–Úñsuccessful“non-
at,‘WpAÇolymorphic“pro‘ƒŽjection“analyser“w¾9asŽ¡‘íºâbuilt–Tinš¾9to“Glasgo˜w“Hask˜ell“[KHL91Ž‘(Ô].Ž¦‘íºâDespite–ãÔthese“successes,‘tpro‘ƒŽjection“analyses“ha•¾9v“e–ãÔa“funda-Ž¡‘íºâmen•¾9tal›	#inabilit“y˜to˜deal˜with˜higher˜order˜functions.‘÷ÞF‘ÿ:«ol-Ž¡‘íºâloš¾9wing–Ëœthe“lead“of“W‘ÿ:«ra˜y“[W‘ÿ:«ra85Ž‘:C],‘ù.Hughes“dened“a“mixedŽ¡‘íºâanalysis–ô|whicš¾9h“w˜as“forw˜ards“for“the“higher“order“bits“andŽ¡‘íºâbac•¾9kw“ards–SŠfor“evš¾9erything“else“[Hug87Ž‘ó'].‘×Doing“this“giv˜es“anŽ¡‘íºâanalysis–r+whic¾9h“deals“with“higher-orderness“whilst“retainingŽ¡‘íºâthe–‡äinherenš¾9t“eciency“of“bac˜kw˜ard“analysis.‘íKRecen˜tly‘ÿ:«,‘¤.otherŽ¡‘íºâw•¾9ork“ers›ÌQha“v“e˜b•AÇegun˜to˜explore˜the˜relationship˜b“et•¾9w“een˜for-Ž¡‘íºâwš¾9ard–ÒÉand“bac˜kw˜ard“analysis“[Bur90Ž‘Žã]“[HL90Ž‘÷l]“[D˜W90Ž‘N].‘TÐTheŽ¡‘íºâanalysis–³ÁdescribšAÇed“in“this“pap˜er“is“a“mo˜dication“of“Hughes'Ž¡‘íºâoriginal–Tmixed“analysis.Ž¦‘íºâMean•¾9while,‘=pAÇeople›xha“v“e˜b•AÇeen˜lo“oking˜at˜other˜w•¾9a“ys˜of˜solv-Ž¡‘íºâing–vÝrecursiv¾9e“domain“equations.‘AThere“has“bAÇeen“a“discern-Ž¡‘íºâable–Jƒshift“to•¾9w“ards–Jƒterm“orienš¾9ted“approac˜hes.‘»üF‘ÿ:«erguson“andŽ¡‘íºâHughes–ö#dev¾9elopAÇed“\concrete“data“structures"“(CDSs)“[ëN?Ž‘sº]Ž¡‘íºâbased–7…on“Curien's“wš¾9ork“on“sequen˜tial“algorithms“[Cur86Ž‘¯õ].Ž¡‘íºâCDSs–‚Îdeal“with“higher-orderness“b¾9y“regarding“a“higher“or-Ž¡‘íºâder–#%function“as“conš¾9taining“a“CDS‘#!in˜terpreter“for“eac˜h“func-Ž¡‘íºâtional–®0parameter.‘çThis“is“really“a“disguised“w•¾9a“y–®0of“substi-Ž¡‘íºâtuting–‡in“functional“parameters“bšAÇefore“xp˜oin¾9ting.‘ìÿWhetherŽ¡‘íºâor–not“CDSs“can“delivš¾9er“a“viable“xpAÇoin˜ting“mec˜hanism“re-Ž¡‘íºâmains–þto“bAÇe“seen.‘îmEarly“implemenš¾9tations“hin˜ted“at“spaceŽ¡‘íºâproblems,‘€but–®Dthese“maš¾9y“no˜w“ha˜v˜e“bAÇeen“solv˜ed“[Hug93Ž‘ó'].Ž¡‘íºâCDSs–/·can“also“bAÇe“view¾9ed“as“a“higher-order“generalisationŽ¡‘íºâof–ÁÁthe“minimal“function“graph“sc¾9heme“originally“describAÇedŽ¡‘íºâb¾9y–E§Neil“Jones“[JM86Ž‘zú].‘­jMinimal“function“graphs“are“usedŽ¡‘íºâin–=Äthe“Semanš¾9tique“analyser“[KHL91Ž‘(Ô]“built“in˜to“Glasgo˜wŽ¡‘íºâHask¾9ell‘T[PHHP93Ž‘#µø].Ž¦‘íºâThe–ü“term“rewriting“based“xpšAÇoin¾9ter“describ˜ed“here“w¾9as,ŽŽŽ ý€’õºâin–œÅpart,‘¾¡inspired“b¾9y“Charles“Consel's“strictness“analyser“inŽ¤
’õºâthe–G¿Y‘ÿ:«ale“Hask¾9ell“compiler“[Gro92Ž‘ÀP].‘³±Consel's“papAÇer“[Con91Ž‘±¼],Ž¡’õºâwhicš¾9h–Îseems“to“ha˜v˜e“passed“b˜y“almost“unnoticed,‘µdescribAÇedŽ¡’õºâa–7#successful,›–if“simple,˜strictness“analyser“solving“xpAÇoin¾9tŽ¡’õºâequations–•Ybš¾9y“term“rewriting.‘œIn“view“of“ho˜w“w˜ell“this“andŽ¡’õºâConsel's–}ásystem“wš¾9ork,‘œ,it“is“pAÇerhaps“a“pit˜y“that“P˜eyton“JonesŽ¡’õºâet–;al“made“disparaging“remarks“abšAÇout“term-based“xp˜oin¾9t-Ž¡’õºâing–Tin“their“seminal“fron¾9tiers“papAÇer“[PC87Ž‘9].ŽŸ5’õºâ¹6.4Ž’G·F•¹™urther‘LÎw“o“rkŽŸm’õºâºAnna's–N¾pAÇerformance“is“encouraging.‘È­Nev¾9ertheless,‘there'sŽ¡’õºâstill–ê¿a“long“w•¾9a“y–ê¿to“go“bAÇefore“ev‘ÿ|raluation“transformer“infor-Ž¡’õºâmation–BÙcan“bšAÇe“generated“automatically“in“pro˜duction“com-Ž¡’õºâpilers.‘pThree›Ta•¾9v“en“ues˜of˜dev“elopmen“t˜need˜to˜b•AÇe˜p“ersued.ŽŸÐO’äëPŽŽŽ’:âëNEnhancemenš´Ct–jeof“applicabilit˜y‘ÿÌ.‘È]ºAnna's–most“w¾9orry-Ž¡’:âing–®alimitation“is“her“inabilit¾9y“to“deal“with“higher“orderŽ¡’:âfunctions–Ûwhic¾9h“cannot“bšAÇe“rstied.‘ôA‘½p˜ossible“partialŽ¡’:âsolution–ÉMis“to“iterate“these“(or,›Ø‚more“precisely‘ÿ:«,˜just“theŽ¡’:ânastš¾9y–Âwbits)“as“man˜y“times“as“is“necessary“to“guaran-Ž¡’:âtee–GÔa“xpAÇoinš¾9t.‘×ðThe“w˜ork“of“Nielson“and“Nielson“[NN92Ž‘>]Ž¡’:âgivš¾9es–7ethe“magic“n˜um˜bAÇer“of“iterations“needed.‘ÒvF‘ÿ:«or“man˜yŽ¡’:âcommon–’'forms,›ñ[this“n•¾9um“bAÇer–’'is“reasonably“lo¾9w,˜andŽ¡’:âit–Zseems“reasonable“to“expAÇect“this“approac¾9h“to“yieldŽ¡’:âw•¾9orth“while‘Tresults.Ž©
™š’:âIt–·eis“also“necessary“to“remo•¾9v“e–·esome“of“the“excessiv¾9e“re-Ž¡’:âstrictions–Jion“user-dened“data“t¾9ypAÇes“discussed“in“sec-Ž¡’:âtion–\ô2.2.6.‘óQThis“došAÇes“not“app˜ear“to“b˜e“particularlyŽ¡’:âdicult.‘òKubiak–\Šet“al“[KHL91Ž‘(Ô]“managed“this“quiteŽ¡’:âsuccessfully‘ÿ:«.ŽŸ34’äëPŽŽŽ’:âëNEnhancemen´Ct–gof“pK¼erformance.‘÷ÙºThe–§Žrenemen¾9ts“ofŽ¡’:âsection–=Œ6.1“ha•¾9v“e–=Œdone“a“lot“to“impro•¾9v“e–=Œthe“system'sŽ¡’:âpAÇerformance.‘¡Nevš¾9ertheless,‘Œ˜some–A‹programs“w˜e“triedŽ¡’:ârecen¾9tly–›Ö-“in“excess“of“a“thousand“lines“-“run“moreŽ¡’:âsloš¾9wly–îÀthan“one“w˜ould“lik˜e.‘¨µIn˜v˜estigations“are“bAÇeingŽ¡’:âmade.Ž¦’:âFixpAÇoin¾9ting–L½large“groups“of“functions“could“conciev-Ž¡’:âably–ðbAÇe“accelerated“b¾9y“reducing“the“group“to“a“\mini-Ž¡’:âmal–Tform"“rst.‘pF‘ÿ:«or“example,“giv¾9enŽ©ÌÍ’g¤ëMa–¹–=“...“a“...“b“...Ž¡’g¤b–¹–=“...“c“...Ž¡’g¤c–¹–=“...“c“...“d“...Ž¡’g¤d–¹–=“...“a“...Ž¦’:âºwš¾9e–`®can“remo˜v˜e“ëMb“ºand“ëMd“ºb˜y“substituting“them“in˜to“ëMa“ºandŽ¡’:âëMc–åºrespAÇectivš¾9ely‘ÿ:«.‘ This“halv˜es“the“n˜um˜bAÇer“of“functions“inŽ¡’:âthe–ÿ2group“bšAÇeing“xp˜oin¾9ted.‘ÚOnce“the“solutions“to“ëMaŽ¡’:âºand–ÆlëMc“ºha•¾9v“e–ÆlbAÇeen“generated,‘Ö4w¾9e“obtain“v‘ÿ|ralues“for“ëMb“ºandŽ¡’:âëMd–Tºbš¾9y“straigh˜tforw˜ard“bac˜k-substitution.ŽŸ
™š’:âNote–Gthat“this“tecš¾9hnique“ma˜y“bAÇe“used“in“an˜y“situa-Ž¡’:âtion›¥¿in•¾9v“olving˜xpAÇoin“ting˜m“utually˜recursiv“e˜groups˜ofŽ¡’:âequations.‘µÆThe–Æidea“stems“from“an“analogy“with“theŽ¡’:âGauss-Jordan–„¨methoAÇd“for“solving“sim¾9ultaneous“linearŽ¡’:âequations.‘zíIn–4Óthis“case,‘<³a“recursiv¾9e“group“can“only“bAÇeŽ¡’:âreduced–Ito“the“pAÇoinš¾9t“where“ev˜ery“equation“in“the“groupŽ¡’:ârefers–öœdirectly“to“itself“{“no“further.‘ÀHAfter“that,‘.îx-Ž¡’:âpAÇoinš¾9ting–x	is“una˜v˜oidable.‘DWhether“or“not“this“rendersŽ¡’:âa–ŸspšAÇeedup“dep˜ends“on“the“relativ¾9e“costs“of“substitution,Ž¡’:âbacš¾9k–Tsubstitution“and“xpAÇoin˜ting.ŽŽŽŽŽŸ’åä28ŽŽŒ‹ÜÑ •ºâ ý? £ ý€‘ûäëPŽŽŽ‘:âëNDealing–¦with“moK¼dulesº.‘	5MoAÇdules–ÈZare“an“unmiti-Ž¤
‘:âgated–†Çnš¾9uisance“for“man˜y“kinds“of“high“pAÇo˜w˜ered“seman-Ž¡‘:âtic–xManalyses“and“optimisations.‘E\In“particular,‘ÑmoAÇd-Ž¡‘:âules–Ñcause“big“diculties“for“an¾9y“kind“of“what“JohnŽ¡‘:âY›ÿ:«oung–(termed“\collecting“in¾9terpretations"“[Y˜ou89Ž‘-Ò].‘TÂAŽ¡‘:âcollecting–‘Tinš¾9terpretation“is“essen˜tially“a“global“anal-Ž¡‘:âysis.‘	vøMan¾9y–Þ,compile“time“optimisations“are“limitedŽ¡‘:âb¾9y–$the“moAÇdule“structure.‘IøF‘ÿ:«or“example,‘hMsome“of“theŽ¡‘:âmore–Äirecenš¾9t“sc˜hemes“for“compiling“o˜v˜erloading“ef-Ž¡‘:âcien¾9tly–[Jon93Ž‘Ä9]“[Aug93Ž‘ó']“require“global“analysis“forŽ¡‘:âfull–Ê=applicabilitš¾9y‘ÿ:«.‘	;,The“pAÇoin˜t“of“all“this“is“that“theŽ¡‘:âmonomorphisation–+œand“rstication“transformationsŽ¡‘:âused–Tin“Anna“also“require“a“global“view.ŽŸÛk‘:âThere–”"is“an“urgen¾9t“need“to“devise“sophisticated“com-Ž¡‘:âpilation–×wsystems“whicš¾9h“main˜tain“enough“in˜termoAÇduleŽ¡‘:âcommš¾9unication–?™to“mak˜e“global“analyses“pAÇossible.‘›?De-Ž¡‘:âv•¾9elopmen“t–»fof“sucš¾9h“a“framew˜ork“w˜ould“bAÇenet“not“onlyŽ¡‘:âstrictness–oªanalysis,‘†@but“man¾9y“aspAÇects“of“compile“timeŽ¡‘:âoptimisation.‘©¨Sucš¾9h–™¼a“compiler“migh˜t“w˜ork“b˜y“dump-Ž¡‘:âing–^øa“lot“of“information“inš¾9to“a“moAÇdule's“in˜terface“le,Ž¡‘:âenough–A‚to“do“whatevš¾9er“analyses“w˜e“need.‘ úThis“w˜ouldŽ¡‘:âreally–©„just“bAÇe“an“extension“of“the“sc¾9hemes“used“al-Ž¡‘:âready–a
in“the“Chalmers“and“Glasgoš¾9w“compilers,‘sûwhic˜hŽ¡‘:âdump–ù{function“aritš¾9y“and“rudimen˜tary“strictness“infor-Ž¡‘:âmation–¯inš¾9to“in˜terface“les.‘µThe“question“is“not“re-Ž¡‘:âally–@ whether“wš¾9e“could“construct“suc˜h“a“system,‘ŠÓbutŽ¡‘:âwhether–ˆ¯the“quan•¾9tit“y–ˆ¯of“information“dumpAÇed“in¾9to“in-Ž¡‘:âterface–3úles“could“bAÇe“limited“sucien¾9tly“to“render“theŽ¡‘:âsc¾9heme‘Tpractical.Ž©™µ‘íºâ¹Ackno¹™wledgementsŽŸ†´‘íºâºThanks–9Íto“Bill“Mitc¾9hell“for“advice“on“building“term“rewrit-Ž¡‘íºâing–
‚systems,‘¬and“to“Barney“Hilkš¾9en“for“an“in˜v‘ÿ|raluable“insigh˜tŽ¡‘íºâregarding–separate“compilation“systems.‘ê Mark“Jones“pro-Ž¡‘íºâvided–ñmanš¾9y“in˜teresting“commen˜ts“abAÇout“monomorphisationŽ¡‘íºâand–Ozrstication,‘^and“outlined“the“instance-collecting“algo-Ž¡‘íºârithm–߯of“Section“5.6.1.‘
ŽGeorey“Burn“and“Denis“Ho•¾9w“e‘߯w“ereŽ¡‘íºâsucien•¾9tly›8Öbra“v“e˜to˜expAÇerimen“t˜with˜the˜implemen“tation,Ž¡‘íºâand–Tproš¾9vided“useful“feedbac˜k.ŽŸ
‘íºâDenis›Û³Ho•¾9w“e˜read˜an˜early˜draft˜in˜min“ute˜detail.‘	:His˜exten-Ž¡‘íºâsivš¾9e–³|and“sometimes“am˜usingŸü-=Õ2ŽŽ‘Þ#ºcommen˜ts“pro˜v˜ed“v˜ery“helpfulŽ¡‘íºâin–Tmaking“the“presen¾9tation“clearer.Ž¦‘íºâ¹ReferencesŽŸÅ‘íºâº[Aug87]ŽŽ‘fL.‘|Augustsson.‘ŠëRCompiling–J´Lš‡azy“F‘ÿJªunctional“L˜an-Ž¡‘fguages,‘l’Part‘f€IIº.‘h€PhD‘/¶thesis,‘6WChalmers‘/¼T‘ÿ:«eknisk‘ÿ|raŽ¡‘fH–û`ogsk¾9ola,›TG“otebAÇorg,˜Sw¾9eden,˜1987.Ž©¶Ö‘íºâ[Aug93]ŽŽ‘fLennart–¤êAugustsson.‘bImplemenš¾9ting“hask˜ell“o˜v˜er-Ž¡‘floading.‘-ðIn‘ÍëRPr•‡o“c“e“e“dings–AEof“the“F‘ÿJªunctional“Pr‡o-Ž¡‘fgr•‡amming›•`L“anguages˜and˜Computer˜AÃŽr“chite“ctur“eŽ¡‘fConfer•‡enc“e,›N<Cop“enhagen,˜Denmarkº,–TJune“1993.Ž¦‘íºâ[Bar91]ŽŽ‘fG.–³úBaraki.‘íuA‘³Žnote“on“abstract“in¾9terpretationŽ¡‘fof–äQpAÇolymorphic“functions.‘	}„In“R.J.M.“Hughes,Ž¡‘feditor,‘÷íëRPr•‡o“c“e“e“dings–ôÑof“the“fth“AÃŽCM‘ô§c•‡onfer“enc“eŽ¡‘fon–6¨F‘ÿJªunctional“Lš‡anguages“and“Computer“AÃŽr˜chi-Ž¡‘fte•‡ctur“eº,‘„Fn•¾9um“bAÇer–:ã523“in“Lecture“Notes“in“Com-Ž¡‘fputer–{–Science,›•&pages“367{378,˜Cam¾9bridge,˜Mas-Ž¡‘fsac•¾9h“usetts,–T26{30“August“1991.“Springer-V‘ÿ:«erlag.Ž‘íºâŸâ‰ff_ÿ Ÿ×‘
r}Ÿüûr°2ŽŽ‘Y±See–±Èthe“other“fo7otnote.ŽŽŽ ý€’õºâº[BHA85]ŽŽ’#fG.L.–0Burn,›ܧC.L.“Hankin,˜and“S.“Abramsky‘ÿ:«.Ž¤
’#fThe–‘àtheory“of“strictness“analysis“for“higher-orderŽ¡’#ffunctions.‘MŒIn‘~QëRPr•‡o“c“e“e“dings–™õof“the“Workshop“onŽ¡’#fPr•‡o“gr“ams–È÷as“Data“Obje‡ctsº,–¼Fpages‘šâ42{62,“DIKU,Ž¡’#fCopšAÇenhagen,–ÚøDenmark,“17{19–ØOctob˜er“1985.Ž¡’#fSpringer-V‘ÿ:«erlag–TLNCS“217.Ž©ÕV’õºâ[Bur87]ŽŽ’#fG.L.‘ìüBurn.‘ØëRAÃŽbstr•‡act›))Interpr“etation˜and˜the˜Par-Ž¡’#falxälel–þìEvaluation“of“F‘ÿJªunctional“L‡anguagesº.‘VÉPhDŽ¡’#fthesis,–ÏImpAÇerial›7PCollege,“Univ•¾9ersit“y˜of˜London,Ž¡’#fMarc¾9h‘T1987.Ž¦’õºâ[Bur90]ŽŽ’#fG.L.–}ÃBurn.‘QA‘}¨relationship“bAÇet•¾9w“een–}Ãabstract“in-Ž¡’#fterpretation–k{and“pro‘ƒŽjection“analysis.‘òIn“ëR17th‘²)AÃŽn-Ž¡’#fnual–F×AÃŽCM‘FÕSympš‡osium“on“the“Principles“of“Pr˜o-Ž¡’#fgr•‡amming‘ŽkL“anguagesº,–l¢pages›[,151{156,“San˜F‘ÿ:«ran-Ž¡’#fcisco,–T17{19“Janš¾9uary“1990.“A˜CM.Ž¦’õºâ[Bur91]ŽŽ’#fG.L.‘yoBurn.‘°ëRLš‡azy–¾úF‘ÿJªunctional“L˜anguages:‘øbAÃŽbstr˜actŽ¡’#fInterpr‡etation–“<and“Compilationº.‘ÎResearc¾9h‘IÔMono-Ž¡’#fgraphs–in“P¾9arallel“and“Distributed“Computing.Ž¡’#fPitman–ÝÈin“assoAÇciation“with“MIT‘ݺPress,‘èå1991.‘¿CT‘ÿ:«oŽ¡’#fappAÇear.Ž¦’õºâ[CD91]ŽŽ’#fW‘ÿ:«ei-Ngan–¸Chin“and“John“Darlington.‘¸Remo¾9vingŽ¡’#fhigher-order–Pþexpressions“b¾9y“program“transforma-Ž¡’#ftion.‘Chin–
zis“at“NUS,“SingapAÇore“and“DarlingtonŽ¡’#fat–<|ImpAÇerial,›FFLondon.“P¾9ossibly“published,˜F‘ÿ:«ebru-Ž¡’#fary‘T1991.Ž¦’õºâ[Con91]ŽŽ’#fCharles–íÏConsel.‘”®F‘ÿ:«ast“strictness“analysis“viaŽ¡’#fsymš¾9b•AÇolic‘JUxp“oin˜t–JUiteration.‘²¤Unpublished.“Y‘ÿ:«aleŽ¡’#fUniv•¾9ersit“y‘ÿ:«,‘9Departmen“t–˜[of“Computer“Science,Ž¡’#fSeptem¾9bAÇer‘T1991.Ž¦’õºâ[Cur86]ŽŽ’#fP‘ÿ:«.-L.‘Z˜Curien.‘è8ëRCate•‡goric“al‘ãCombinators,‘ÍSe“quen-Ž¡’#ftial–—ùAšÃŽlgorithms“A˜nd“F‘ÿJªunctional“Pr•‡o“gr“ammingº.Ž¡’#fResearc¾9h–\¼Notes“in“Theoretical“Computer“Sci-Ž¡’#fence–—›series.“Pitman“Publishing“Limited,‘°ÀLondon,Ž¡’#f1986.Ž¦’õºâ[D¾9W90]ŽŽ’#fKei–¬UDa¾9vis“and“Philip“W‘ÿ:«adler.‘n¨Strictness“analysisŽ¡’#fin–¢Ü4d.‘_7In“ëRIn›åpr•‡o“c“e“e“dings˜of˜the˜1990˜Glasgow˜AyrŽ¡’#fFP–N<Workshop“(??)º,‘T1990.Ž¦’õºâ[Gro92]ŽŽ’#fThe–JÝY‘ÿ:«ale“Haskš¾9ell“Group.‘¹WThe“y˜ale“hask˜ell“usersŽ¡’#fman•¾9ual,›Tv“ersion˜y2.0-bAÇeta,˜August˜1992.Ž¦’õºâ[HH91]ŽŽ’#fSebastian–²Hunš¾9t“and“Chris“Hankin.‘#ØFixed“pAÇoin˜tsŽ¡’#fand–çæfronš¾9tiers:‘Á“a“new“p•AÇersp“ectiv˜e.‘	ˆ/ëRJournal‘úüofŽ¡’#fF‘ÿJªunctional‘ò-Pr•‡o“gr“ammingº,›Å01(1):91–±&{“120,˜Jan¾9uaryŽ¡’#f1991.Ž¦’õºâ[HH92]ŽŽ’#fSebastian–¸7Hunš¾9t“and“Chris“Hankin.‘‚Appro˜ximateŽ¡’#fxed–ž¾pAÇoinš¾9ts“in“abstract“in˜terpretation.‘XIn“ëRF‘ÿJªourthŽ¡’#fEur•‡op“e“an›n{Symp“osium˜on˜Pr“o“gr“amming,‘v‹R“ennes,Ž¡’#fF‘ÿJªr•‡anc“eº,–T1992.‘ÎLNCS“582.Ž¦’õºâ[HL90]ŽŽ’#fR.J.M.–5íHughes“and“J.“Launc•¾9h“bury–ÿ:«.‘zóT“o•¾9w“ards‘5íre-Ž¡’#flating–ß±forwš¾9ards“and“bac˜kw˜ards“analyses.‘Â`In“ëRPr‡o-Ž¡’#fc•‡e“e“dings–Vof“the“Thir‡d“AÃŽnnual“Glasgow“WorkshopŽ¡’#fon–YßF‘ÿJªunctional“Pr•‡o“gr“ammingº,–%(pages‘!ý145{155,“Ul-Ž¡’#flap•AÇo“ol,–TScotland,“13{15“August“1990.Ž¦’õºâ[HL92]ŽŽ’#fPieter–WˆH.“Hartel“and“KošAÇen“G.“Langendo˜en.Ž¡’#fBenc•¾9hmarking›‰implemen“tations˜of˜lazy˜func-Ž¡’#ftional–z£languages.‘G´T‘ÿ:«ecš¾9hnical“repAÇort,‘“öDepartmen˜tŽ¡’#fof–FhComputer“Systems,‘’­F‘ÿ:«acult¾9y“of“MathematicsŽ¡’#fand–ÇComputer“Science,‘…£Univ•¾9ersit“y–Çof“Amster-Ž¡’#fdam,–TDecem¾9bAÇer“1992.ŽŽŽŽŽŸ’åä29ŽŽŒ‹þ •ºâ ý? £ ý€‘íºâº[HP90]ŽŽ‘fJohn–SL.“Hennessy“and“Daš¾9vid“A.“P˜atterson.‘ÝõëRCom-Ž¤
‘fputer›}šAÃŽr•‡chite“ctur“e:‘ž¿A‘}Quantitative˜Appr“o“achº.Ž¡‘fMorgan–36Kaufmann“Publishers,–:®Inc.,“San‘36Mateo,Ž¡‘fCA,‘T1990.Ž©34‘íºâ[Hug]ŽŽ‘fJohn–3hHughes.‘©ŠPro‘ƒŽjections“for“pAÇolymorphic“strict-Ž¡‘fness–Q(analysis.‘ÌIn“ëRIn–…7Springer“V‘ÿJªerlag“LNCS‘…)389º.Ž¡‘fY‘ÿ:«ear–Tand“conference“not“established.Ž¦‘íºâ[Hug87]ŽŽ‘fJohn›–žHughes.‘›Bac•¾9kw“ards˜analysis˜of˜functionalŽ¡‘fprograms.‘tT‘ÿ:«ec¾9hnical–>RepAÇort“CSC/87/R3,‘SøUni-Ž¡‘fv•¾9ersit“y–ƒ\of“Glasgo•¾9w,‘ÞÝDepartmen“t–ƒ\of“ComputingŽ¡‘fScience,–TMarc¾9h“1987.Ž¦‘íºâ[Hug90]ŽŽ‘fJohn–ÞHughes.‘	jþCompile-time“analysis“of“func-Ž¡‘ftional–programs.‘
¾In“Da¾9vid“A.“T‘ÿ:«urner,‘Úedi-Ž¡‘ftor,‘KFëRR•‡ese“ar“ch–f$T›ÿJªopics“in“F˜unctional“Pr•‡o“gr“ammingº.Ž¡‘fAddison-W›ÿ:«esley–AûPublishing“Compan¾9y˜,‘	#1990.Ž¡‘fF›ÿ:«rom–Јthe“1987“Y˜ear“of“Programming,‘ÞKUniv•¾9ersit“yŽ¡‘fof–TT›ÿ:«exas,“Austin,“T˜exas.Ž¦‘íºâ[Hug93]ŽŽ‘fJohn–7ÃHughes.‘€kPriv‘ÿ|rate“comm¾9unication“regardingŽ¡‘fcdss,‘T1993.Ž¦‘íºâ[JM86]ŽŽ‘fNeil–šD.“Jones“and“Alan“Mycroft.‘PÇData“
o¾9w“anal-Ž¡‘fysis–Ïof“applicativ¾9e“programs“using“minimal“func-Ž¡‘ftion–ô•graphs:‘Abridged“v¾9ersion.‘ämIn“ëRUnknown,‘6)butŽ¡‘fdenitely–N<in“an“AÃŽCM“pr•‡o“c“e“e“dingsº,‘T1986.Ž¦‘íºâ[Joh85]ŽŽ‘fT.–7Johnsson.‘ÒULam¾9bAÇda“lifting:‘ú6T‘ÿ:«ransform-Ž¡‘fing–ÇNprograms“to“recursiv¾9e“equations.‘	'In“J.-P‘ÿ:«.Ž¡‘fJouannaud,–8editor,“ëRPr•‡o“c“e“e“dings–à"of“the“Confer-Ž¡‘fencš‡e–öÌon“F‘ÿJªunctional“Pr˜o˜gr˜amming“L˜anguages“andŽ¡‘fComputer‘§íAÃŽr•‡chite“ctur“eº,–ëpages‘„190{203,“Nancy‘ÿ:«,Ž¡‘fF‘ÿ:«rance,–TSeptem¾9bAÇer“1985.Ž¦‘íºâ[Joh87]ŽŽ‘fT.–üJohnsson.‘	ÄdA¾9ttribute“grammars“as“a“func-Ž¡‘ftional–V#programming“paradigm.‘ÚïIn“G.“Kahn,‘fVed-Ž¡‘fitor,‘ø$ëRPr•‡o“c“e“e“dings–,µof“the“F‘ÿJªunctional“Pr•‡o“gr“ammingŽ¡‘fLš‡anguages–Óœand“Computer“AÃŽr˜chite˜ctur˜e“Confer-Ž¡‘fenc‡eº,‘Ïpages–½ˆ154{173.“Springer-V‘ÿ:«erlag“LNCS‘½q274,Ž¡‘fSeptem¾9bAÇer‘T1987.Ž¦‘íºâ[Jon93]ŽŽ‘fMark–0¡Jones.‘fP¾9artial“ev‘ÿ|raluation“for“dictionary-Ž¡‘ffree›_o•¾9v“erloading.‘÷Unpublished˜draft.˜Y‘ÿ:«ale˜Uni-Ž¡‘fv•¾9ersit“y‘ÿ:«,›gDepartmen“t–V³of“Computer“Science,˜AprilŽ¡‘f1993.Ž¦‘íºâ[KHL91]ŽŽ‘fR.–' Kubiak,›W+J.“Hughes,˜and“J.“Launc•¾9h“bury‘ÿ:«.‘–VA‘'cpro-Ž¡‘ftot•¾9ypAÇe›$®implemen“tation˜of˜pro‘ƒŽjection-based˜rst-Ž¡‘forder–¥¼pAÇolymorphic“strictness“analysis.‘cçIn“R.“Hel-Ž¡‘fdal,–×@editor,“ëRDr•‡aft›ÜÌPr“o“c“e“e“dings˜of˜F‘ÿJªourth˜AÃŽnnualŽ¡‘fGlasgow–)Workshop“on“F‘ÿJªunctional“Pr•‡o“gr“ammingº,Ž¡‘fpages–T322{343,“Sky¾9e,“August“13{15“1991.Ž¦‘íºâ[Min92]ŽŽ‘fSa•¾9v‘ÿ|ra›•Min“tc“hev.‘I A‘•}parallel˜stg-mac“hine.‘I Master'sŽ¡‘fthesis,›Ü6Departmen¾9t–<of“Computer“Science,˜Uni-Ž¡‘fv•¾9ersit“y–Tof“Mancš¾9hester,“UK,“Septem˜bAÇer“1992.Ž¦‘íºâ[Myc80]ŽŽ‘fA.–ºMycroft.‘ Theory“and“practice“of“transform-Ž¡‘fing–:
call-bš¾9y-need“in˜to“call-b˜y-v‘ÿ|ralue.‘‡4In“ëR4th‘oøInter-Ž¡‘fnational–ïüSympš‡osium“on“Pr˜o˜gr˜ammingº,‘ÃGpages‘®Ã269Ž¡‘f{281,–luP¾9aris,“April–'Õ1980.“Springer-V‘ÿ:«erlag“LNCSŽ¡‘f83.Ž¦‘íºâ[Nel]ŽŽ‘fGeorge–+FC.“Nelan.–[4Firstication.“Date‘+Funkno¾9wn,Ž¡‘fbut–`…m¾9ust“bAÇe“1992“or“after.“Based“on“Nelan's“PhDŽ¡‘fthesis.–TArizona“State“Univ•¾9ersit“y‘ÿ:«.ŽŽŽ ý€’õºâ[NN92]ŽŽ’#fF.–ÌíNielson“and“H.R.“Nielson.‘<íFiniteness“condi-Ž¤
’#ftions–Fýfor“xed“pAÇoinš¾9t“iteration.‘­ÌT‘ÿ:«ec˜hnical“repAÇort,Ž¡’#fComputer–§ìScience“Departmen•¾9t,‘Ì‘Aarh“us‘§ìUniv“er-Ž¡’#fsit¾9y›ÿ:«,–TDenmark,“F˜ebruary“1992.Ž©34’õºâ[P¾9ar92]ŽŽ’#fWill–®žPš¾9artain.‘ÓAThe“ëMnofib“ºbAÇenc˜hmark“suiteŽ¡’#fof–Òühask¾9ell“programs.‘DÀIn“ëRFifth–ÓAÃŽnnual“Glas-Ž¡’#fgow–{rWorkshop“on“F‘ÿJªunctional“Pr•‡o“gr“amming,‘¥›Ayrº,Ž¡’#f1992.Ž¦’õºâ[PC87]ŽŽ’#fSimon–à!Pš¾9eyton“Jones“and“Chris“Clac˜k.‘v&FindingŽ¡’#fxpAÇoinš¾9ts–/Èin“abstract“in˜terpretation.‘£¡In“S.“Abram-Ž¡’#fsky–ùÌand“C.L.“Hankin,–ÿNeditors,“ëRAÃŽbstr•‡act‘4ðInterpr“e-Ž¡’#ftation–8Iof“De•‡clar“ative‘8IL“anguagesº,‘8Computers‘ýqandŽ¡’#fTheir–ø'Applications,›0Ûc¾9hapter“11,˜pages“246{265.Ž¡’#fEllis›THorw¾9o•AÇo“d,˜1987.Ž¦’õºâ[P¾9ey87]ŽŽ’#fS.L.–rDP¾9eyton“Jones.‘ëRThe–¸eImplementation“of“F‘ÿJªunc-Ž¡’#ftional›d¨Pr•‡o“gr“amming˜L“anguagesº.‘{wPren¾9tice-Hall‘$In-Ž¡’#fternational–!Series“in“Computer“Science.“Pren¾9tice-Ž¡’#fHall–TIn¾9ternational“(UK)“Ltd,“London,“1987.Ž¦’õºâ[PHHP93]ŽŽ’#fS.L.–¯EP¾9eyton“Jones,›ïCordelia“V‘¯+Hall,˜Kevin“Ham-Ž¡’#fmond,‘´÷and–aÖWill“Pš¾9artain.‘ø¯The“glasgo˜w“hask˜ellŽ¡’#fcompiler:‘Úša–‘§tecš¾9hnical“o˜v˜erview.‘C+In“ëRPr•‡o“c“e“e“dings‘Õ<ofŽ¡’#fthe–þDUK‘þ0Join“F›ÿJªr‡amework“for“Information“T˜e‡chol-Ž¡’#fo•‡gy,‘N<Ke“eleº,‘T1993.Ž¦’õºâ[PJ92]ŽŽ’#fS.L.–‡‡Pš¾9eyton“Jones.‘2©Implemen˜ting“lazy“functionalŽ¡’#flanguages–c£on“stoAÇcš¾9k“hardw˜are:‘¹
the“spineless“tag-Ž¡’#fless‘ÕJG-Mac¾9hine.‘±këRJournal–cof“F‘ÿJªunctional“Pr•‡o“gr“am-Ž¡’#fmingº,–T2(2):127{202,“April“1992.Ž¦’õºâ[Sew91]ŽŽ’#fJulian›ÖnSew•¾9ard.‘³GT‘ÿ:«o“w“ards˜a˜strictness˜analyser˜forŽ¡’#fhaskš¾9ell:‘›#Putting–Ô­theory“in˜to“practice.‘TMaster'sŽ¡’#fthesis,›#’Univ•¾9ersit“y– ¹of“Manc•¾9hester,˜Departmen“t‘ ¹ofŽ¡’#fComputer–œScience,‘´E1991.‘T
Av‘ÿ|railable“as“Univ•¾9ersit“yŽ¡’#fof–TMancš¾9hester“T‘ÿ:«ec˜hnical“RepAÇort“UMCS-92-2-2.Ž¦’õºâ[Sew92]ŽŽ’#fJulian›¦àSew•¾9ard.‘eÂP“olymorphic,‘¼÷higher˜order˜strict-Ž¡’#fness–|ianalysis“using“fron¾9tiers.‘ ŠUnpublished“papAÇer,Ž¡’#f1992.Ž¦’õºâ[Sew93]ŽŽ’#fJulian›ÔSew•¾9ard.‘R#P“olymorphic˜strictness˜analysisŽ¡’#fusing–Ø‚fron¾9tiers.‘	ZRIn“ëRPr•‡o“c“e“e“dings–ì×of“the“Symp‡o-Ž¡’#fsium–Ûon“Partial“Evaluation“and“Semantics“b•‡ase“dŽ¡’#fPr•‡o“gr“am‘táManipulation,–¾ŠPEPM93,“Cop‡enhagen,Ž¡’#fDenmarkº,–TJune“1993.Ž¦’õºâ[W‘ÿ:«ad87]ŽŽ’#fP–ÿ:«.L.›dªW“adler.‘:Strictness˜analysis˜on˜non-
at˜do-Ž¡’#fmains–ï(bš¾9y“abstract“in˜terpretation“o˜v˜er“nite“do-Ž¡’#fmains).‘ÏàIn–¨US.“Abramsky“and“C.L.“Hankin,‘Íedi-Ž¡’#ftors,‘-ðëRAÃŽbstr•‡act›`SInterpr“etation˜of˜De“clar“ative˜L“an-Ž¡’#fguagesº,–z“c¾9hapter›ÿí12,“pages˜266{275.˜Ellis˜Hor-Ž¡’#fwš¾9o•AÇo“d‘sÓLtd.,–ËsChic˜hester,“W‘ÿ:«est‘sÓSussex,“England,Ž¡’#f1987.Ž¦’õºâ[W‘ÿ:«ad92]ŽŽ’#fPhilip–cW‘ÿ:«adler.‘ü-The“essence“of“functional“pro-Ž¡’#fgramming.‘=;In‘x×ëRPr•‡o“c“e“e“dings–”íof“the“19th“AÃŽnnualŽ¡’#fSympš‡osium–Öqon“Principles“of“Pr˜o˜gr˜amming“L˜an-Ž¡’#fguages,–N<Santa“F‘ÿJªe,“New“Mexic‡oº,‘T1992.Ž¦’õºâ[WH87]ŽŽ’#fP–ÿ:«.›")W“adler˜and˜R.˜J.˜M.˜Hughes.‘@Pro‘ƒŽjections˜forŽ¡’#fstrictness–)@analysis.‘U,In“G.“Kahn,–.;editor,“ëRPr•‡o“c“e“e“d-Ž¡’#fings–=3of“the“F‘ÿJªunctional“Pr•‡o“gr“amming‘=3L“anguagesŽ¡’#fand–r~Computer“AÃŽr•‡chite“ctur“e‘r~Confer“enc“eº,‘ÿpagesŽ¡’#f385{407.–N`Springer-V‘ÿ:«erlag“LNCS‘NQ274,‘\£Septem¾9bAÇerŽ¡’#f1987.ŽŽŽŽŽŸ’åä30ŽŽŒ‹w •ºâ ý? £ ý€‘íºâº[W‘ÿ:«ra85]ŽŽ‘fS.–ëC.“W–ÿ:«ra¾9y“.‘~\A‘ªnew–ëstrictness“detection“algorithm.Ž¤
‘fIn‘'ìëRPr•‡o“c“e“e“dings–_Rof“the“Workshop“on“Implementa-Ž¡‘ftions–~öof“F‘ÿJªunctional“L•‡anguages,›¨jAsp“enas,˜Swe“den.Ž¡‘fAÃŽvailable–N<as“Chalmers“PMG“r•‡ep“ort‘N<17º,‘T1985.ŽŸ34‘íºâ[Y‘ÿ:«ou89]ŽŽ‘fJ.H.‘¬aY‘ÿ:«oung.‘n¼ëRThe–íÌTheš‡ory“and“Pr˜actic˜e“of“Seman-Ž¡‘ftic›Ä™Pr•‡o“gr“am˜AÃŽnalysis˜for˜Higher-Or“der˜F‘ÿJªunc-Ž¡‘ftional›%
Pr•‡o“gr“amming˜L“anguagesº.‘ÐÀPhD‘èwthesis,‘ñyDe-Ž¡‘fpartmenš¾9t–T™of“Computer“Science,‘djY‘ÿ:«ale“Univ˜ersit˜y‘ÿ:«,Ž¡‘fMa¾9y‘T1989.ŽŽŽŽŽŸ’åä31ŽŽŒø9.ƒ’À;蕺âåºâóR¼j‘¹		cmti9óP©±Ê		cmsy9óO5ùž"		cmmi9óNt‰:		cmbx9óMߤN		cmtt9ó7ßê<x
ó3
cmtt10ó*¹Aa¨cmr6ó(Kñ`y
ó3
cmr10óÂÖN ffcmbx12óX«Qffcmr12óo´‹Ç		cmr9óñkAH	
cmssbx10ó
!",š

cmsy10ó°Ü0ncmsy5óÙ“ Rcmr7ó†›Zcmr5ù;øßßßßßßß