÷ƒ’À;è 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«Q ff cmr12»Second–³/draft:›D>Octob�dCer“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ßê]“and“[�Sew93Ž‘/]),‘гand“put“m•¾9uc“h–¿Še ort“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–›“Int“->“Intº,˜comparisons‘{ÇëM(<)º,˜ëM(<=)º,Ž¡�‘íºâëM(==)º,–n¾ëM(/=)º,“ëM(>)–Eºand“ëM(>=)º,›n¾of“t�¾9yp�AÇe“ëMInt–¹–->“Int“->“Boolº,˜andŽ¡�‘íºâcon•¾9v“ersion–=ífunctions“ëMchr“ºand“ëMord“ºof“t�¾9yp�AÇe“ëMInt–¹–->“Char‘=íºandŽ¡�‘íºâëMChar–¹–->“Int–¦Íºresp�AÇectivš¾9ely‘ÿ:«.‘ÐÚA‘¦§v‘ÿ|ralid“program“m˜ust“supply“aŽ¡�‘íºâbinding–»for“ëMmainº,‘Íbut“unlikš¾9e“a“Hask˜ell“program,‘Íthis“ma˜y“b�AÇeŽ¡�‘íºâof–Tanš¾9y“t˜yp�AÇe.ަ�‘íºâDespite–iÉthis“meagre“collection“of“primitivš¾9es,‘¾æAnna“kno˜wsŽ¡�‘íºâab�AÇ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“imp�AÇor-ŽŽŽ�� ý€�’õºâtanš¾9t–Ü»features“of“Hask˜ell“are“missing,‘è the“subset“allo˜ws“Annaޤ �’õºâto–:Cb�AÇe“fed“real-wš¾9orld“programs“of“considerable“complexit˜y‘ÿ:«,Ž¡�’õºâalb�AÇeit–Tafter“some“considerable“massaging.Ž© ��’õºâProbably–g)the“b�AÇ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“prop�AÇer,‘)ÿand“theŽ¡�’õºâsupp�AÇorting–uÏframewš¾9ork.‘=àThe“in˜terface“b�AÇet˜w˜een“the“t˜w˜o“isŽ¡�’õºâreasonably–ÃVclean,‘Ó¼so“c�¾9hanging“the“nature“of“the“analysis“canŽ¡�’õºâb�AÇe–Íudone“without“m•¾9uc“h›Íuuphea“v‘ÿ|ral.‘DÓThis˜section˜fo�AÇcusses˜onŽ¡�’õºâthe–Tsupp�AÇorting“framew�¾9ork.ަ�’õºâBecause–×'wš¾9e“w˜an˜t“to“exercise“the“analyses“on“functional“pro-Ž¡�’õºâgrams–T'of“realistic“size,‘zÊthe“supp�AÇ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“exp�AÇ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“prop�AÇer“are“Core-to-Ž¡�’ :âCore‘Ttransformations.Ž©34����’äëPŽŽŽ’ :âºA‘MÌdep�AÇ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“dep�AÇendancy“order.ަ����’äëPŽŽŽ’ :âºA‘Ízcrude–ÍŒbut“e ectivš¾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–“ìb�AÇ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“b�AÇ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“mo�AÇdi ed“Johnsson-st˜yleŽ¡�’ :âlam•¾9b�AÇda-lifter›‰[�Joh85Ž‘Ä9],‘¥!follo“w“ed˜b“y˜another˜dep�AÇendancyŽ¡�’ :âanalysis‘Tpass.ަ����’äëPŽŽŽ’ :âºThe– Ûprogram“is“noš¾9w“t˜yp�AÇ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“no�AÇde“in“the“CoreŽ¡�’ :âtree–;has“a“tš¾9yp�AÇe“expression“attac˜hed.‘hAlthough“a“com-Ž¡�’ :âplete–mannotation“is“rather“exp�AÇ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“sp�AÇecialisationŽ¡�’ :âor–z rsti cation)“noš¾9w“follo˜ws.‘(âThe“presen˜t“naiv˜e“im-Ž¡�’ :âplemen�¾9tation,›|xdescrib�AÇ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“b�AÇe“remo•¾9v“ed.‘Ñ>This–Q™transformation“isŽ¡�’ :âcomplicated–¹ybš¾9y“the“need“to“main˜tain“t˜yp�AÇ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“dep�AÇendancy“analyser“is“subsequen�¾9tly“re-Ž¡�‘:âquired.Ž©Ù�‘íºâMost–†£compilers“wš¾9ould“w˜an˜t“to“mangle“the“output“of“theŽ¡�‘íºâdesugarer–5rin“quite“di erenš¾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š¾9b�AÇ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“b�AÇ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“b�AÇ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“b�AÇecause“the“demand“propagated“acrossŽ¡�‘:âa–ÿ/higher-order“function“largely“dep�AÇ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“e ort“w�¾9as“un-Ž¡�‘íºânecessarily‘ÿ:«,‘%_b�AÇecause–"*the“Glasgoš¾9w“Hask˜ell“team“ha˜v˜e“sp�AÇeci -Ž¡�‘íºâcally–þdesigned“their“compiler“as“a“basis“for“exp�AÇerimenš¾9ts“lik˜eŽ¡�‘íºâthis,‘º5and–f v‘ÿ|ralianš¾9tly“supp�AÇorted“those“bra˜v˜e“enough“to“tak˜eŽ¡�‘íºâthem–¡´up“[�PHHP93Ž‘#µø].‘Á�In“retrosp�AÇ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“b�AÇegun,‘þ‹in“the“summer“ofŽ¡�‘:â1991,‘ÖGlasgoš¾9w's–¼compiler“(v˜ersion“0.02)“w˜as“in“still“inŽ¡�‘:âthe–Tpro�AÇ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“imp�AÇ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“pro�AÇduces“a“ëNCore––Åsyn�´Ctax“treeº,‘ *inŽ¡�‘íºâwhic•¾9h›Rev“ery˜no�AÇde˜is˜decorated˜with˜its˜t“yp�AÇe.‘Ò¥This˜is˜fed˜toŽ¡�‘íºâthe–oëNabstract‘¢bin�´Cterpreter“ºprop�AÇer,‘Bµwhic�¾9h“translates“to“anŽ¡�‘íºâabstract›9=form:‘dBëNrecursiv�´Ce–Üádomain“equationsº.‘ˆ,The˜ëN x-Ž¡�‘íºâp�K¼oin�´Cter–›€ºsolvš¾9es“these“equations“b˜y“iterating“to“their“greatestŽŽŽ�� ý€�’õºâ xed–nép�AÇ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Ž¡�’ :âb�AÇ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“p�AÇos-Ž¡�’ :âsible.‘ÑÊW‘ÿ:«e–ürlater“inš¾9tro�AÇduce“a“Hask˜ell“t˜yp�AÇe“ëMContext“ºtoŽ¡�’ :âmo�AÇdel‘Tcon�¾9texts.ŽŸ34����’äëPŽŽŽ’ :âëNAbstract‘CFv‘ÿh‰alues–Õzºamounš¾9t“to“some“tric˜k˜ery“w˜e“will“in-Ž¡�’ :âtro�AÇduce–øÙto“deal“with“higher“order“functions.‘òAn“alter-Ž¡�’ :ânativ•¾9e›ýname,‘['whic“h˜is˜again˜a“v“oided˜where˜p�AÇossible,Ž¡�’ :âis–"’ëNforw�´Card‘œ v‘ÿh‰alueº.‘D*The“corresp�AÇonding“Haskš¾9ell“t˜yp�AÇe“isŽ¡�’ :âëMAbsValº.ަ�’õºâThis–?¿pap�AÇer“is“primarily“concerned“with“disco•¾9v“ering‘?¿ho“wŽ¡�’õºâsource–Ý(language“functions“b�AÇ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“p�AÇer“Core“function.‘×GCon�¾9texts“and“abstract“v˜aluesŽ¡�’õºâin•¾9tert“wine,‘Öfso–¯Éthe“ëMContext“ºand“ëMAbsVal“ºtš¾9yp�AÇ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�¾9yp�AÇed.Ž¡�’õºâEac•¾9h›£Bcon“text˜is˜a˜mem“b�AÇer˜of˜a˜particular˜ëNcon�´Ctext‘ udomainº,Ž¡�’õºâand–nSmost“op�AÇerations“on“con�¾9texts“are“only“meaningful“if“theirŽ¡�’õºâop�AÇerands–ÿ8are“dra�¾9wn“from“particular“domains.‘Abstract“v‘ÿ|ral-Ž¡�’õºâues–zÌare“also“strongly“t�¾9yp�AÇed.‘L×Although“the“domains“for“ab-Ž¡�’õºâstract–uv‘ÿ|ralues“are,›[¼strictly“sp�AÇeaking,˜di erenš¾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“b�AÇe“man˜y“di eren˜t“t˜yp�AÇ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“b�AÇest“view˜ed“as“a“generalisation“of“theŽ¡�’õºâev‘ÿ|raluation–âétransformers“inš¾9tro�AÇduced“b˜y“Burn“[�Bur87Ž‘Žã].‘ ¢TheseŽ¡�’õºâare–Tinš¾9tro�AÇduced“b˜y“example.ަ��’õºâ¹2.2.1Ž’úíBase‘LÎt�¹™yp�FfesŽŸ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�¹™yp�FfesŽŸ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“comp�AÇonenš¾9ts“of“the“pair“separately‘ÿ:«,‘øso“there“m˜ust“b�AÇ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“p�AÇ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Ž¡�‘íºâcomp�AÇonen•¾9ts.‘ ÕSo›à„w“e˜really˜need˜a˜ fth˜p�AÇoin“t˜represen“ting˜anŽ¡�‘íºâev‘ÿ|raluator–õˆwhicš¾9h“do�AÇes“nothing“at“all.‘×The“o˜v˜erall“in˜terpreta-Ž¡�‘íºâtion–Tis“ëMLift–¹–(2“x“2)º.ŽŸ ��‘íºâAš¾9t–Fóthis“p�AÇoin˜t“it“is“con˜v˜enien˜t“to“in˜tro�AÇduce“a“notation“forŽ¡�‘íºâpšAÇoin�¾9ts–çåto“b˜e“used“throughout“this“pap˜er.‘ KThe“b˜ottom“p˜oin�¾9tŽ¡�‘íºâof–¶the“ab�AÇ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– \do�AÇes“this“generalise“to“arbitrary“non-recursiv˜e“struc-Ž¡�‘íºâtured›%t•¾9yp�AÇ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–ÇŽb�AÇ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“imp�AÇosed“for“the“pur-Ž¡�‘íºâp�AÇ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“mapp�AÇ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�¾9yp�AÇe“ëM(Grok–¹–Int“(Foo“Int“Int)Ž¡�‘íºâ(Grok–¹–Int“Int“Int))–i®ºhas“a“91“p�AÇ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-Ž¡�‘íºâp�AÇonenš¾9ts–ãýis“equal“to“the“n˜um˜b�AÇer“of“t˜yp�AÇe“v‘ÿ|rariables,‘§and“en-Ž¡�‘íºâtirely–®unrelated“to“the“n•¾9um“b�AÇer–®of“parameters“of“an�¾9y“partic-Ž¡�‘íºâular–g[constructor.‘…A‘gFcon�¾9text“ëMU[1,0,0]“ºapplied“to“an“ob‘ƒŽjectŽ¡�‘íºâof–µt�¾9yp�AÇ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“b�AÇ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�¾9yp�AÇe–Tv‘ÿ|rariable,“ëMaº,“in“the“declaration.ŽŸ5��‘íºâ¹2.2.3Ž‘ úíRecursive–LÎstructured“t�¹™yp�FfesŽŸ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“happ�AÇens,‘Ïthe“form�¾9ulation“used“in“Anna“is“a“trivialŽŽŽ�� ý€�’õºâv‘ÿ|rariation–JÕof“the“rule“for“non-recursivš¾9e“t˜yp�AÇ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š¾9yp�AÇ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“p�AÇ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˜yp�AÇe“of“ëMn“ºparameters“has“ev‘ÿ|raluators“ofŽ¡�’õºâthe–þ form“ëM{_,›¹–U_“ºand“ëMUU[x1˜...˜xn]}º.‘­The“ëMUU[x1˜...˜xn]Ž¡�’õºâºp�AÇoinš¾9ts–O›denote“ev‘ÿ|raluating“the“en˜tire“structure,‘^,and“then“ap-Ž¡�’õºâplying–«Hev‘ÿ|raluator“ëMx1“ºto“eac�¾9h“ob‘ƒŽject“corresp�AÇonding“to“the“ rstŽ¡�’õºâparameter,‘WëMx2–¬ºto“ob‘ƒŽjects“corresp�AÇ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“p�AÇoin˜ts“in˜toŽ¡�’õºâthree–ž#sections“is“crucial“to“the“w�¾9orking“of“the“term“rewritingŽ¡�’õºâsystem–œbused“to“detect“ xp�AÇoinš¾9ts.‘ôSimilarly‘ÿ:«,‘´“the“non-recursiv˜eŽ¡�’õºâp�AÇoin•¾9ts›¼ãma“y˜b�AÇe˜partitioned˜in“to˜t“w“o:‘ð7ëM{_˜ºand˜ëMU[x1–¹–...“xn]}º.Ž© ��’õºâThe–ºguiding“principle,›#>originally“stated“b�¾9y“W‘ÿ:«adler,˜is“toŽ¡�’õºâmo�AÇdel–“tthe“recursivš¾9e“t˜yp�AÇes“b˜y“letting“the“sub-ev‘ÿ|raluatorsŽ¡�’õºâin–')ëMUU[...]“ºv‘ÿ|ralues“b�AÇe“represen•¾9tativ“e–')of“the“least“de nedŽ¡�’õºâelemenš¾9t–óèof“that“t˜yp�AÇe“in“the“structure.‘¸,Imagine“w˜eŽ¡�’õºâha•¾9v“e–©Õa“list“of“tš¾9yp�AÇ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“b�AÇe“applied“(thatŽ¡�’õºâis,‘mwithout–³danger“of“non-termination)“to“the“list.‘õzNo�¾9wŽ¡�’õºâsupp�AÇose–Âwš¾9e“obtain“another“list“for“whic˜h“ëMUU[U[1,0]]“ºis“theŽ¡�’õºâstrongest–ßsafe“ev‘ÿ|raluator,‘MÄand“app�AÇ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“b�AÇ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“b�AÇest“that“canŽ¡�’õºâb�AÇe–�applied“to“the“list“as“a“whole“is“ëMUU[U[0,0]]“º{“the“great-Ž¡�’õºâest›fÉlo•¾9w“er˜b�AÇ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“b�AÇe“more“precise:Ž¡�’õºâa–— list“is“cš¾9haracterised“b˜y“the“greatest“ev‘ÿ|raluator“that“canŽ¡�’õºâsafely–D•b�AÇ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š¾9yp�AÇes“of“an˜y“n˜um˜b�AÇer“of“parameters,Ž¡�’õºâwith–^�the“greatest-lo•¾9w“er-b�AÇound›^�c“haracterisation˜o�AÇccurring˜in-Ž¡�’õºâdep�AÇendenš¾9tly–Tfor“eac˜h“parameter.ަ�’õºâThis–(abstraction,›FËwhilst“simple,˜assumes“that“programs“treatŽ¡�’õºâall–ð elemenš¾9ts“of“the“same“t˜yp�AÇe“inside“a“structure“in“the“sameŽŽŽŽŽŸ�’çjã4ŽŽŒ‹[” •ºâ� ý? £���� ý€�‘íºâºw•¾9a“y–ÿ:«.‘ �F“or–åÜexample,‘ï[it“assumes“list“pro�AÇ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“b�AÇ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“p�AÇ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Ž¡�‘íºâb�AÇeloš¾9w,‘Âthe–­1analyser“giv˜es“a“m˜uc˜h“b�AÇetter“result“for“ëMsum1“ºthanŽ¡�‘íºâëMsum2º,–Tdespite“them“haš¾9ving“iden˜tical“strictness“prop�AÇ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Ž¡�‘íºâb�AÇ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Ž‘ úíMo�Ffdifying–LÎthe“notationŽŸm�‘íºâºThe›,Àab�AÇo•¾9v“e˜mapping˜assigns˜domain˜ëMLift‘¹–()˜ºto˜allŽ¡�‘íºâen•¾9umeration› ¹At“yp�AÇes,‘ b:for˜example˜the˜familiar˜t“yp�AÇeŽ¡�‘íºâëMdata–¹–Bool“=“False“|“Trueº.‘<Since“the“domain“has“91“p�AÇ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“co�AÇde“are“re-Ž¡�‘íºâquired.‘7aQuite–Èúwhat“to“do“abšAÇout“complex“t•¾9yp˜es,‘õãwhic“h‘Èúin-Ž¡�‘íºâduce–.Ãpro�AÇduct“domains,‘5or“non-trivial“instan�¾9tiations“of“lists,Ž¡�‘íºâis–Tnot“clear.ަ�‘íºâThis–½unsatisfactory“state“of“a airs“can“to“some“exten�¾9t“b�AÇeŽ¡�‘íºâalleviated–·bš¾9y“restricting“ourselv˜es“to“compiling“just“a“subsetŽŽŽ�� ý€�’õºâof–"Üall“the“p�AÇ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“b�AÇ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“p�AÇoten˜tial“parallelismŽ¡�’õºâma•¾9y›˜w“ell˜b�AÇe˜lost:‘!Ïsuc“h˜is˜the˜price˜for˜restricting˜the˜co�AÇdeŽ¡�’õºâexplosion–Tto“a“tolerable“magnitude.Ž© ��’õºâThe–FØcenš¾9tral“question,–p%then,“is–FØwhic˜h“v˜ersions“to“compile“co�AÇdeŽ¡�’õºâfor.‘NoOne–{Tp�AÇ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“p�AÇoin˜ts“apply“to“all“structured“t˜yp�AÇes,Ž¡�’õºâincluding–!Ôtuples“and“complex“instanš¾9tiations“of“t˜yp�AÇ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“b�AÇeen“suggested“thatŽ¡�’õºâa–#Ófourth“ev›ÿ|raluator“migh�¾9t“b�AÇe“pro tably“included:‘9nev˜aluationŽ¡�’õºâof–ýKthe“enš¾9tire“structure“of“a“recursiv˜e“t˜yp�AÇe,‘7Ibut“no“ev‘ÿ|ralua-Ž¡�’õºâtion–M of“the“comp�AÇonenš¾9ts.‘ÅSThis“mak˜es“no“sense,›[³of“course,˜inŽ¡�’õºâa–YTnon-recursivš¾9e“t˜yp�AÇ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�¾9tro�AÇduction“to“Conc“maps.‘Õ†My“MSc“dissertation“[�Sew91Ž‘/]Ž¡�’õºâindicates–#­ho�¾9w“Conc“maps“are“useful“in“matters“of“p�AÇolymor-Ž¡�’õºâphism,–Ta“theme“explored“further“in“[�Sew93Ž‘/].ަ�’õºâNoš¾9w,‘ê¹if–àthe“compiler“is“only“going“to“mak˜e“co�AÇde“for“a“few“ofŽ¡�’õºâall– äthe“p�AÇ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Ž¡�’õºâb�AÇ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“exp�AÇensivš¾9e“approac˜h.‘òBuilding“an“abstract“in˜terpre-Ž¡�’õºâtation–gXfor“the“el“cš¾9heap�AÇo“approac˜h“migh˜t“also“b�AÇe“rather“dif-Ž¡�’õºâ cult,‘;and–sthe“inš¾9terpreter“w˜ould“ha˜v˜e“to“b�AÇe“rewritten“ev˜eryŽ¡�’õºâtime–™®the“particular“subset“of“inš¾9teresting“ev‘ÿ|raluators“c˜hanged.ަ�’õºâA‘‘x nal–‘™inš¾9teresting“ca˜v˜eat“p�AÇertains“to“higher-order“functions.Ž¡�’õºâAs–6Üexplained“to•¾9w“ards–6Üthe“end“of“section“1.2,‘=it“lo�AÇ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)–ždescrib�AÇed“in“section“5“enhances“parallelism.Ž¡�’õºâWhat–& rsti cation“do�AÇes“is“to“disco•¾9v“er–&statically“some“of“theŽ¡�’õºâfunctional–Èparameters“passed“to“higher-order“functions,‘ÓäandŽ¡�’õºâsp�AÇecialise–;them“accordingly‘ÿ:«,‘Ltgenerating“ rst-order“replace-ŽŽŽŽŽŸ�’çjã6ŽŽŒ‹“§ •ºâ� ý? £���� ý€�‘íºâºmenš¾9ts.‘KøThese–Ï×can“then“b�AÇ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“ab�AÇout“ëMf“ºwhic˜hޤ �‘íºâtells–MÑus“prop�AÇerties“of“the“application“ëM(f–¹–x“y“z)–MѺif“wš¾9e“kno˜wŽ¡�‘íºâthe–¤eprop�AÇ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“prop�AÇ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“b�AÇecome“apparen˜t,‘å�AnnaŽ¡�‘íºâdo�AÇ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“corresp�AÇond“to“a“forwš¾9ards“ o˜w“of“information,Ž¡�‘íºâwhilst–Tconš¾9texts“corresp�AÇ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“b�AÇ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“b�AÇ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–º«lo�AÇ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“b�AÇ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“to�AÇok“the“w�¾9ork“of“Hughes“[�Hug87Ž‘ó']“to“gener-Ž¡�’õºâalise–O‰W‘ÿ:«raš¾9y's“results“to“the“p�AÇ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“lo�AÇok“ rst“at“under-Ž¡�’õºâlying–Tissues,“starting“o “with“some“new“concepts.ŽŸºç��’õºâ¹3.2Ž’ G·F�¹™unction‘LÎcontextsŽŸm�’õºâºDealing–-øwith“functions“prop�AÇerly“means“turning“them“in�¾9toŽ¡�’õºâ rst-class–Âlcitizens“for“the“purp�AÇ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“b�AÇ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ô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–›¬describ�AÇ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“ab�AÇ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Ž�’ß• pro�AÇ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˜comp�AÇonen“ts˜are˜b�AÇoth˜maps.‘ë=TheŽ¡�‘:â rst›v–comp�AÇ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“p�AÇ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–¯œb�AÇehaš¾9viour“sho˜wn“in“T›ÿ:«able“1.‘úˆHop�AÇ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“ab�AÇout“ëMid“ºis“that“it“simply“propagates“the“con˜text“onŽ¡�‘íºâits–4£result“to“the“conš¾9text“on“its“argumen˜t.‘z]So,‘“c)Ž¡�‘íºâºLet's–]Ãb�AÇ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–«(pro�AÇ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Ž¡�‘íºâlo�AÇ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“b�AÇ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�¾9yp�AÇe“isŽ¡�’õºâëMIntº.‘e¦All–ƒnon-function“tš¾9yp�AÇes“ha˜v˜e“a“corresp�AÇonding“abstractŽ¡�’õºâv‘ÿ|ralue,–õŸdenoted›í²ëM#º,“in˜a˜1-p�AÇoin•¾9t˜domain.‘:So˜w“e˜don't˜actuallyŽ¡�’õºâcare–Þ@what“the“abstract“v‘ÿ|ralue“of“ëMid“ºis“{“it“can“only“b�AÇ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“b�AÇ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�¾9yp�AÇe“ëMInt–¹–->“Intº.‘+ûClearly‘ÿ:«,‘†yëM(+)–oغsimply“prop-Ž¡�’õºâagates–5conš¾9text“on“the“o˜v˜erall“result“to“b�AÇ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“b�AÇ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˜yp�AÇ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�¾9yp�AÇe“ëM(Int–¹–->“Int)“->“Int“->“Intº.Ž¡�’õºâThis–ÔÈexample“is“easier“to“follo�¾9w“if“one“b�AÇ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–åîb�AÇe“the“same“as“the“abstract“v‘ÿ|ralue“of“the“second“pa-Ž¡�‘íºârameter–¬½to“ëMapplyº,‘Ò—and“this“v‘ÿ|ralue“(whicš¾9h“m˜ust“b�AÇ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“b�AÇ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“b�AÇoundŽ¡�‘íºâto– cthe“abstract“v‘ÿ|ralue“of“the“functional“parameter,‘'whic�¾9hŽ¡�‘íºâm�¾9ust–"b�AÇ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˜p�AÇossible.‘ŸÎFirstly‘ÿ:«,‘Lthe˜abstract˜v‘ÿ|ralueŽ¡�‘íºâof–+the“result“mš¾9ust“simply“b�AÇe“ëM#º,‘0~since“the“result“t˜yp�AÇ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“sp�AÇ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“b�AÇ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Îab�Ffout“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˜ab�AÇo•¾9v“e,‘Ê{isŽŽŽ�� ý€�’õºâto�AÇo–Ë indiscriminating.‘=—The“Hask�¾9ell“declaration“for“abstractޤ �’õºâv‘ÿ|ralues–Tlo�AÇ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�¾9yp�AÇe.‘ è�F‘ÿ:«or“ex-Ž¡�’õºâample,‘|þa–Üterm“of“t�¾9yp�AÇ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“imp�AÇortanš¾9t“to“realise“that“this“v‘ÿ|ralue“is“still“unitary‘ÿ:«,‘Tlik˜eŽ¡�’õºâëM#º,‘”Êbut–Hhas“the“added“adv‘ÿ|ran�¾9tage“that“it“can“b�AÇ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“tro�AÇ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˜exp�AÇect˜ëMxs˜ºto˜ha•¾9v“e˜b�AÇeenޤ �’õºâb�AÇ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,“supp�AÇosingޤÐO�’ç¤ëMxs–¹–=“[id,“id]“where“id“x“=“xŽ¡�’õºâºthe–Tabstract“v‘ÿ|ralue“of“ëMxs“ºwill“b�AÇe:Ž¡�’ç¤ëMARec–¹–[‘ s,Fval“(\c1“->“FncC“c1)Ž© �’ATB(\a1–¹–->“ANonRec“[])‘ s,]Ž¡�’õºâºThe–ìÅe ect“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“b�AÇ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Îab�Ffout“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˜b�AÇ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“p�AÇoin˜t“ëMU[x1–¹–...“xn]º.‘Similarly‘ÿ:«,–TëMStop2º,“ëMUp2Ž¡�‘íºâºand›$uëM(UpUp2–¹–[x1“...“xn])˜ºrepresen•¾9t˜the˜p�AÇ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“describ�AÇed“in“section“4.4.Ž© ��‘íºâëMFncC–(åºand›)!ëMFvalC“ºw�¾9ere˜also˜discussed˜in˜section˜3.2.‘Í´ëMCJoin˜ºandŽ¡�‘íºâëMCMeet–]=ºunsurprisingly“denote“the“least“upp�AÇ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-Ž¡�’õºâsp�AÇ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“b�AÇeing“in“do-Ž¡�’õºâmains›�½ëMLift–¹–(D1“x“...“x“Dn)˜ºand˜ëMLift2“(D1“x“...“x“Dn)Ž¡�’õºâºresp�AÇ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›one“and“only“w•¾9a“y–×>to“makš¾9e“them“w˜ell-formed“is“to“wrapŽ¡�’õºâthe–rappropriate“sp�AÇ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—app�AÇ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š¾9yp�AÇ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š¾9yp�AÇ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š¾9yp�AÇe“called“ëMtypeNameº,‘¿©param˜terised“b˜y“t˜yp�AÇeޤ �‘íºâv‘ÿ|rariables–Î@ëMv1“ºto“ëMvkº,‘Üxwith“constructors“ëMC1“ºto“ëMCnº.‘¿The“t�¾9yp�AÇ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“b�AÇe“either“one“of“the“t˜yp�AÇeŽ¡�‘íºâv‘ÿ|rariables,›i ëMv1–¹–...“vkº,˜or–XLa“direct“recursivš¾9e“call“to“the“t˜yp�AÇe:Ž¡�‘íºâëM(typeName–¹–v1“...“vk)º.ŽŸ ��‘íºâBecause–€ of“this“constrain•¾9t,‘š¹eac“h–€ constructor“argumen�¾9t“in“aŽ¡�‘íºâv‘ÿ|ralid–&ìde nition“can“b�AÇe“classi ed“either“as“a“recursiv�¾9e“call“ëMRecº,Ž¡�‘íºâor–Y�as“one“of“the“tš¾9yp�AÇe“v‘ÿ|rariables,‘jžëMVar‘¹–n“ºwhere“ëMn“ºis“a“n˜um˜b�AÇ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,“b�AÇ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“b�AÇeloš¾9w.‘ WNeither“are“mean˜t“toŽ¡�‘íºâb�AÇe–¿ implemenš¾9table.‘”Rather,‘éxthey“serv˜e“as“con˜v˜enien˜t“nota-Ž¡�‘íºâtional–êRdevices,‘‘and“are“b�AÇest“illustrated“b�¾9y“example.‘›jTheyŽ¡�‘íºâare–§Íb�AÇoth“meaningless“unless“the“particular“constructor“ap-Ž¡�‘íºâplication–Tthey“are“asso�AÇciated“with“is“stated.ŽŸ ��‘íºâëMargkind–…ºtells“us“what“part“of“a“data“tš¾9yp�AÇe“a“giv˜en“construc-Ž¡�‘íºâtor–×ìargumenš¾9t“corresp�AÇonds“to:‘ý¼either“a“certain“t˜yp�AÇe“v‘ÿ|rariable,Ž¡�‘íºâor–ý3a“recursivš¾9e“instance“of“the“t˜ypšAÇe.‘eF‘ÿ:«or“example,‘b˜earing“inŽ¡�‘íºâmind–~the“declaration“ab�AÇ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@exp�AÇ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–Tb�AÇ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“p�AÇolymorphic“nature.‘¦Note“that“ëMupdateŽ¡�’õºâºis›�Ïalw•¾9a“ys˜used˜with˜a˜constructor˜wrapp�AÇed˜round˜the˜ nalŽ¡�’õºâlist–ö¸argumenš¾9t.‘“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“lo�AÇ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“do�AÇ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˜opp�AÇ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›Tb�AÇeha“v“e˜something˜lik“e:ޤeh�‘ûç¤ëM(:)–¹–=“\x“xs“->“AMeet“[xs,“ARec“[x]]Ž¡�‘íºâºObservš¾9e–‹¦that“the“apparen˜tly“p�AÇ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“b�AÇ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“(b�AÇear“in“mind“that,‘Ëfor“a“domain“notŽ¡�‘íºâcon�¾9taining–“ófunction“spaces,‘³›this“is“the“same“as“the“b�AÇottomŽ¡�‘íºâp�AÇ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š¾9yp�AÇe,“b˜y“the“least“v‘ÿ|ralue“of“that“t˜yp�AÇe.ŽŸ ��‘íºâAs–K[an“example,‘×consider“an“ob‘ƒŽjectŽ¡�‘íºâof–‹þtš¾9yp�AÇe“ëM(AVLTree–¹–Int“Int“Int)º.‘€oCon˜texts–‹þfor“that“t˜yp�AÇeŽ¡�‘íºâare–®ædra�¾9wn“from“the“domain“ëMLift2–¹–(Lift“()“x“Lift“()“xŽ¡�‘íºâLift‘¹–())º.‘ #ÀW‘ÿ:«e–Äexp�AÇ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“corresp�AÇonding“to“t˜yp�AÇe“v‘ÿ|rariable“ëMi“ºin“theŽ¡�‘íºât�¾9yp�AÇe–TAde nition,›cüand“similarly“for“ëMaa“ºand“ëMbbº.‘Ù7So,˜at“this“in-Ž¡�‘íºâstanš¾9tiation,‘ Wthe–ƒabstract“v‘ÿ|ralue“b�AÇ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“yp�AÇes˜are˜dealt˜with˜in˜an˜exactly˜analogousŽ¡�‘íºâmanner.‘ÒJF‘ÿ:«or–6âexample,‘c`the“b�AÇeha�¾9viour“of“the“pairing“construc-Ž¡�‘íºâtor–Tat“t�¾9yp�AÇ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“ab�AÇout“nothing,‘ƒþy˜ouŽ¡�’õºâare–;!correct.‘�ØSince“all“these“examples“build“structures“with-Ž¡�’õºâout–¦ïem�¾9b�AÇedded“function“spaces,‘½the“result“v‘ÿ|ralues“are“unitary‘ÿ:«,Ž¡�’õºâand–Tma�¾9y“b�AÇ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“b�AÇ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“to�AÇ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Ž¡�’õºâb�AÇ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‘Üp�AÇ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“b�AÇ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“pro�AÇ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)Ž¡�‘íºâºb�AÇ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“p�AÇossible“to“gen-Ž¡�‘íºâerate–)]ëMZapWHNFº,“and“the“drop-select“op�AÇerator“only“drops“oneŽ¡�‘íºâp�AÇoinš¾9t,‘ö%instead–îYof“t˜w˜o.‘rThis“op�AÇ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ºresp�AÇ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“asso�AÇciated“with“ëMsw“ºof“ëMfswº,‘tØthe“abstractŽ¡�‘íºâv‘ÿ|ralue–Tasso�AÇ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“b�AÇ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ަ�’õºâmetho�AÇ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“pro�AÇ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“b�AÇ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ަ�’õºâºresp�AÇectiv�¾9ely‘ÿ:«.ŽŸ ��’õºâThe–ñ§folloš¾9wing“sc˜heme“is“o ered,‘øÉagain“without“justi cation.ަ�’õºâIf–TëMC“ºis“from“a“recursivš¾9e“t˜yp�AÇ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[]“],Ž© �‘G�Up1–¹–[U[],‘,Âc2]“]Ž¡�‘íºâ(a1:a2)–¹–::“[Int]‘Tºgiv�¾9esŽ¡�‘ûç¤ëMalpha–¹–=“CJoin“[“Up2,ަ�‘G�CMeet–¹–[“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“p�AÇoin˜t,‘äîit'sަ�‘íºânecessary–{¸to“inš¾9tro�AÇ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“b�AÇ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“lo�AÇ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“asso�AÇ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“describ�AÇed“in“section“3.5.3.Ž© ��’õºâThe–ôHnext“step“is“to“ gure“out“what“con�¾9text“can“b�AÇ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–‘¹–idަ�’)´T(x:xs)‘ s,->‘¹–idŽ¡�’õºâºThis–míëMcase“ºexpression“returns“a“function,‘„whic�¾9h“is“p�AÇerfectlyަ�’õºâlegitimate.‘ý:But–µ—the“o•¾9v“erall›µ—con“text˜on˜it,–ݨëMalphaº,“will˜b�AÇ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‘ÿ:«,˜b�AÇ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–ú5b�AÇ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“lo�AÇoks“lik˜e:Ž©«“�‘ûç¤ëMCaseUU–¹–(FncC“(FncC“.....“(FncC“alpha)“.....))Ž¡�‘ú¾_Ž¡�‘ú¾(CMeet–¹–[alpha1“...“alphan])Ž¡�‘ú¾(CMeet–¹–[alpha1“...“alphan])ަ�‘íºâºThe›Á²n•¾9um“b�AÇ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˜dep�AÇ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“supp�AÇ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“prop�AÇer.‘¿,W‘ÿ:«eŽ¡�‘íºâpause–ÀGbut“brie y“to“takš¾9e“respite“in“the“follo˜wing“example,Ž¡�‘íºâthen–Temš¾9bark“up�AÇ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“yp�AÇe˜is˜ëMIntº.‘OSo˜a˜con-Ž¡�‘íºâtext–« ëMalpha“ºplaced“on“the“result“m�¾9ust“b�AÇ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?ab�AÇ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š¾9tro�AÇ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,‘óEb�AÇ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–‡€b�AÇottom“v‘ÿ|ralue“when“needed.‘rôRecall“also“that“a“CoreŽ¡�’õºâexpression–·is“a“pair,‘Ééthe“ rst“part“of“whicš¾9h“is“the“t˜yp�AÇe“of“theŽ¡�’õºâexpression,–Tand“the“second“the“expression“prop�AÇ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-p�AÇoin�¾9t‘Tdomain.ަ�’ç¤ëMZ–¹–(tau,“ALit“n)“rho‘ s,=“ANonRec“[]ަ�’õºâºV‘ÿ:«ariables›Tha•¾9v“e˜their˜v‘ÿ|ralues˜lo�AÇ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š¾9b�AÇ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“comp�AÇ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“b�AÇ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“ºcomp�AÇ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“ºmo�AÇ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“metho�AÇd“of“sec-ޤ �‘íºâtion‘T3.5.3.ŽŸ ��‘íºâFinally‘ÿ:«,‘¾Pthe–¨�ëMAConstr“ºcase.‘ø.Although“sections“3.5.1“and“3.5.2Ž¡�‘íºâcompletely–r do�AÇ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–P�3.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›+Áb�AÇ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“e ect:ަ�‘ûç¤ë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Ž¡�‘íºâb�AÇ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“b�AÇeing“applied“to“ëM(\y.e).ޤ �’õºâºAssuming–@ßthat“ëMx“ºand“ëMy“ºare“not“the“same“v‘ÿ|rariable“(theŽ¡�’õºâlamš¾9b�AÇda-lifter–Ðassures“this),‘ÿIcon˜text“on“ëMx“ºin“ëM(\y.e)“ºcan“b�AÇ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“b�AÇ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“b�AÇ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“e orts“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“metho�AÇd“ofŽ¡�’õºâsection‘T3.5.4.Ž© ��’õºâAs–¸…b�AÇ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˜metho�AÇ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“p�AÇ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“b�AÇe“selected,‘ƒñw˜e“m˜ust“tak˜e“the“greatestŽ¡�’õºâlo•¾9w“er–è'b�AÇ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“asso�AÇ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-Ž¡�’õºâsp�AÇ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·Intro�FfductionŽŸm�‘íºâºF‘ÿ:«or–*eacš¾9h“Core“function,‘o=the“abstract“in˜terpreter“pro�AÇducesޤ �‘íºâan–¡EëMAbsVal“ºterm.‘õÀRecursivš¾9e“groups“of“terms“require“ xp�AÇ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“p�AÇoin˜t,Ž¡�‘íºâb�AÇ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˜p�AÇoin“t˜in˜the˜domains,‘V3and˜ xp�AÇoin“tingŽ¡�‘íºâyields–³/the“least“ xed“p�AÇ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“b�AÇecause“of“the“need“to“compare“ap-Ž¡�‘íºâproš¾9ximations–Xduring“ xp�AÇoin˜ting.‘é}F‘ÿ:«or“non-recursiv˜e“terms,Ž¡�‘íºâthere–ºóis,›Ístrictly“sp�AÇeaking,˜no“need“to“use“the“rewriter.‘þPNev-Ž¡�‘íºâertheless,‘‘b�AÇ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-Ž¡�‘íºâp�AÇ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“p�AÇ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“describ�AÇ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“lo�AÇcal“transformationsŽ¡�‘íºâto–v¥a“term.‘@bWhen“no“more“transformations“can“b�AÇe“applied,Ž¡�‘íºâthe–Mäterm“is“deemed“to“b�AÇ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�¾9tro�AÇduced“a“few“equalities,Ž¡�‘íºâwhicš¾9h,–Twhen“giv˜en“a“directionalit˜y‘ÿ:«,“b�AÇ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Ž¡�‘íºâro�AÇ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–Û¯e ort“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,Ž¡�’õºâb�AÇ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,˜b�AÇe“needed“to“arriv�¾9e“at“nor-Ž¡�’õºâmal–ÿçform.‘Ü)The“decision“can“therefore“b�AÇ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“b�AÇeŽ¡�’õºâfo�AÇolish–Boto“claim“that“this“is“alw•¾9a“ys–Boso,‘l�the“evidence“suggestedŽ¡�’õºâan–b innermost- rst“scš¾9heme“w˜ould“usually“b�AÇ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š¾9yp�AÇes“are“m˜utually“re-Ž¡�’õºâcursivš¾9e,‘ÖËthe–°term“rewriter“prop�AÇer“consists“of“t˜w˜o“functionsŽ¡�’õºâof–ÂGtš¾9yp�AÇe“ëMAbsVal–¹–->“AbsVal–ÂGºand“ëMContext–¹–->“Contextº,‘í„eac˜hŽ¡�’õºâof–qwhicš¾9h“p�AÇ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“b�AÇ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“p�AÇ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“b�AÇ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“ro�AÇot“sym˜b�AÇ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˜yp�AÇe“ëMTerm–¹–->“Maybe“Termº,‘Twhere:ޤÐO�’ç¤ëMdata–¹–Maybe“a“=“Nothing“|“Just“aŽ¡�’õºâºAs–•b�AÇecomes“clear“shortly‘ÿ:«,‘ "wš¾9e“need“to“kno˜w“whether“the“ap-ޤ �’õºâplication–q¡of“a“rewrite“rule“has“had“an�¾9y“e ect.‘1VW‘ÿ:«e“couldŽ¡�’õºâmak•¾9e›ì6eac“h˜rule˜ha“v“e˜t“yp�AÇe˜ëMTerm–¹–->“Term˜ºand˜compare˜theŽ¡�’õºâterm–­ bšAÇefore“and“after“application,‘öbut“this“seems“ab˜om-Ž¡�’õºâinably–.Œinecienš¾9t,‘tÚb�AÇecause“the“rule“itself“\kno˜ws"“when“itŽ¡�’õºâhas–¹`made“a“c•¾9hange.‘”Therefore,‘âcw“e–¹`enco�AÇ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“sharp�7er“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Ž¡�‘€p�7oin�Èãt–ø�of“Anna's“existance“in“the“Real“W‘ÿZªorld“outside“it-Ž¡�‘€self‘�!Ž¡ŽŽŽŽŸ�’åäº17ŽŽŒ‹²È •ºâ� ý? £���� ý€�‘íºâºrewrite–Мrules“relev‘ÿ|ranš¾9t“to“the“ro�AÇot“sym˜b�AÇ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“e ect,Ž¡�‘íºâin–÷whic�¾9h“case“the“next“rule“is“tried,‘/‚or“it“pro�AÇduces“a“newŽ¡�‘íºâterm–'eëMt2º.‘R¢Noš¾9w“ëMt2“ºma˜y“w˜ell“ha˜v˜e“a“di eren˜t“ro�AÇot“sym˜b�AÇ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“e ect“of“ëMschedule(t)“ºis“thš¾9us“to“k˜eep“applyingŽ¡�‘íºârewrite–¯„rules“to“the“ro�AÇ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“p�AÇoinš¾9t.‘Î�What“this“w˜ould“mean“is“thatŽ¡�‘íºâanš¾9y–8íp�AÇossible“rewrites“of“ëMt2“ºw˜ould“b�AÇe“dela˜y˜ed“un˜til“the“nextŽ¡�‘íºâsimpli cation–7Îpass,‘drather“than“b�AÇ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“lamb�Ffdas“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“b�AÇ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“o�AÇ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ëb�AÇ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˜b�AÇ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“ab�AÇ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“sp�AÇ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“lo�AÇ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“b�AÇe“a“big“w˜aste“of“time“ifŽ¡�’õºâëMf–×ãºis“in“that“form“already‘ÿ:«.‘õSo“there“is“a“sp�AÇ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�¾9ho�AÇ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“sp�AÇ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“b�AÇ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“b�AÇ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“b�AÇ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“di erence“is“thatŽ¡�’õºâa–�þëMCtxVar“ºcan“only“refer“to“ëMCtxLam“ºb�AÇound“v‘ÿ|rariables.‘�nTheseŽ¡�’õºât•¾9w“o›rÙen“vironmen“ts˜are˜henceforth˜referred˜to˜as˜ëMaenv˜ºandŽ¡�’õºâëMcenv‘Tºresp�AÇ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�¾9tro�AÇ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“b�AÇ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“ab�AÇ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“ab�AÇout“their“v‘ÿ|ralue.‘ÆÚWhen“a“nestedŽ¡�‘íºâëMCase–s ºexpression“is“encounš¾9tered,‘‹3lo�AÇok“up“its“switc˜h“v‘ÿ|ralue“inŽ¡�‘íºâëMselenvº.‘`¥If–,there“is“a“corresp�AÇonding“en�¾9try‘ÿ:«,‘1¿this“ëMCase“ºexpres-Ž¡�‘íºâsion–¿›mš¾9ust“b�AÇe“examining“a“con˜text“whic˜h“has“already“b�AÇeenŽ¡�‘íºâlo�AÇ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“ab�AÇout“ëMe“ºimmediately“allo�¾9ws“the“systemŽ¡�‘íºâto–‡(reduce“the“t•¾9w“o–‡(subterms“to“ëMw“ºand“ëMz“ºresp�AÇectiv�¾9ely‘ÿ:«.‘qìProp-Ž¡�‘íºâagation–ûìof“information“ab�AÇ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“happ�AÇ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˜b�AÇer“that“the“k˜eysŽ¡�‘íºâare–üarbitrary“expressions,‘5²rather“than“mere“v‘ÿ|rariables.‘ІAnŽ¡�‘íºâexp�AÇ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�¾9heap�AÇer“to“completelyŽ¡�‘íºâemptš¾9y–{°ëMselenv“ºat“ev˜ery“ëMCtxLamº.‘O„This“do�AÇesn't“lose“informa-Ž¡�‘íºâtion–kb�AÇecause“the“abstract“inš¾9terpreter“nev˜er“builds“con˜textŽ¡�‘íºâexpressions–÷ewhere“wš¾9e“need“to“main˜tain“selector“informationŽ¡�‘íºâacross–”’ëMCtxLam“ºb�AÇ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“p�AÇerfectly“w˜ork-Ž¡�‘íºâable,‘µDis–�@to�AÇo“wš¾9eak.‘ôiW‘ÿ:«e“need“a“more“general“w˜a˜y“to“propagateŽ¡�‘íºâso-called–ëá\ëMselenv“ºinformation"“around,‘!„as“can“b�AÇ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“lo�AÇ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“b�AÇ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“b�AÇ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,‘i�in“whic˜h“case“ëMsimp“ºacts“as“b�AÇefore.‘æ’But,‘i�forŽ¡�’õºâa–�luc�¾9ky“few,‘? ëMselenv“ºtells“us“a“little“ab�AÇ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“fo�AÇ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“fo�AÇotnotes.ŽŸ ��’õºâThis–LHall“sounds“rather“clumsy‘ÿ:«,‘Zbut“there“is“a“neat“solution.Ž¡�’õºâRecall– qsection“3.4“in�¾9tro�AÇ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èfo�AÇ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˜ºresp�AÇectiv�¾9ely‘ÿ:«.‘–“AllŽ¡�’õºâthat–’/remains“to“do“is“mo�AÇ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–‚Àp�AÇ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“p�AÇ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–\Ÿmo�AÇdifying“the“rule“so“that“one“of“the“initial“terms“isŽ¡�’õºâëM(DefUU‘¹–e)º,‘ÛHand–ÌÄb�AÇ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“b�AÇ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“b�AÇ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˜b�AÇe˜able˜to˜do˜just˜a˜little˜bitŽ¡�‘íºâb�AÇ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“exp�Ffonential“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“b�AÇ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“b�AÇ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“ro�AÇot“term“un�¾9til“no“moreŽ¡�‘íºâcan–Ëb�AÇ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“ro�AÇot“term.‘°öThere's“aŽ¡�‘íºâv�¾9ery›yZgo•AÇo“d˜c•¾9hance˜w“e˜can,‘˜�b�AÇ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“to�AÇ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–4do�AÇes“not“immediately“seek“out“anotherŽ¡�‘íºârewrite–àarule“for“the“ro�AÇ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“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“b�AÇetter.Ž¡�’õºâPresenš¾9ted–&with“a“term“already“comp�AÇ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-lo�AÇoking“functions,‘Düthe“abstract“in˜terpreterŽ¡�’õºâemits–wa“remark‘ÿ|rably“cumš¾9b�AÇersome“and“unin˜tuitiv˜e-lo�AÇ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˜p�AÇer-Ž¡�’õºâtaining–à¶to“the“argumen�¾9ts“and“result“of“a“ rst“order“functionŽ¡�’õºâare–H unitary‘ÿ:«,‘T·the“only“thing“one“can“ask“ab�AÇout“it“is“ho�¾9w“theŽ¡�’õºâconš¾9text–˜ùon“the“result“propagates“to“eac˜h“argumen˜t.‘òüSupp�AÇ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“do�AÇ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–wexp�AÇ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“ºwrapp�AÇ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˜lo�AÇ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“b�AÇ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“e ect,‘™fw˜eޤ �‘íºâa•¾9v“oided–9storing“those“trailing“argumenš¾9ts,‘�ïand“fak˜ed“themŽ¡�‘íºâinstead,›F using–<^ëMError“ºterms,˜b�AÇecause“wš¾9e“can“guaran˜tee“theyŽ¡�‘íºâwill–žònevš¾9er“b�AÇe“used.‘¹JF‘ÿ:«rom“this“it“follo˜ws“that“it“is“an“errorŽ¡�‘íºâfor–TëMError“ºto“app�AÇ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“p�AÇ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,˜b�AÇoth“termsŽ¡�’õºâreduce–'Zto“the“same“thing.‘R�Note“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-Ž¡�’õºâsp�AÇectiv�¾9ely‘ÿ:«.ŽŸ5��’õºâ¹4.8Ž’ G·No•¹™rmal›LÎfo“rms˜and˜termination˜p“rop�FfertiesŽ©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,‘Npro�AÇducingŽ¡�’õºâa– ªcorrectness“argumen�¾9t“is“a“formidable“task.‘ùrW‘ÿ:«e“hop�AÇe“toŽ¡�’õºâinclude–›¦one“in“a“later“v�¾9ersion“of“this“papšAÇer.‘¯fAlso“to“b˜eŽ¡�’õºâincluded–Ewill“b�AÇ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·Intro�Ffductionަ�’õºâºAlthough–¹· rst“order“functions“are“easily“handled“b�¾9y“term-Ž¡�’õºârewriting–­ based“ xp�AÇ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›\Í xp�AÇ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“ xp�AÇ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–¼exp�AÇ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“ºb�AÇe-Ž¡�‘íºâfore–š% xp�AÇoinš¾9ting“ëMfoldr,“ºso“that“w˜e“are,›»Yin“e ect,˜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“ xp�AÇoin�¾9t-Ž¡�‘íºâing–¶hpro�AÇcess“[�ëN?Ž‘sº].‘ÿ­By“con�¾9trast,‘­Anna“adopts“a“completelyŽ¡�‘íºâstraigh•¾9tforw“ard›päapproac“h:‘Ó‘transform˜the˜source˜program.Ž¡�‘íºâProgram–ñvtransformation“is“a“p�AÇopular“sub‘ƒŽject,‘(~and“v‘ÿ|rariousŽ¡�‘íºâpap•AÇers›—¶describ“e˜higher-order˜function˜remo•¾9v‘ÿ|ral˜(also˜kno“wnŽ¡�‘íºâas–М rsti cation“or“sp�AÇecialisation)“[�CD91Ž‘þä]‘¡8[�NelŽ‘ žº].‘ˆThe“sc�¾9hemeŽ¡�‘íºâpresen•¾9ted›Tb�AÇelo“w˜is˜based˜on˜w“ork˜b“y˜George˜Nelan˜[�NelŽ‘ žº].ަ�‘íºâNot–Àall“functional“parameters“can“b�AÇ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Ž¡�‘íºâb�AÇ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“b�AÇe“handled“b˜y“aŽ¡�‘íºâsecondary–=§mec�¾9hanism“outlined“in“section“6.4.‘•jIn“doing“thisŽ¡�‘íºâwš¾9e–±Yimplicitly“app�AÇeal“to“the“measuremen˜t-lead“approac˜h“toŽ¡�‘íºâdesign–Ô¼discussed“in“the“in�¾9tro�AÇduction.‘Z©W‘ÿ:«e“only“need“to“re-Ž¡�‘íºâmo•¾9v“e–PÛfunctional“parameters“for“recursiv�¾9e“functions,–_½but,“asŽ¡�‘íºâb�AÇecomes–’fclear,‘¬–this“means“ rstifying“non-recursiv�¾9e“functionsŽ¡�‘íºâto�AÇ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“app�AÇeared“in“the“argumen�¾9ts.‘+ßF‘ÿ:«or“example,‘Âin“ëMfoldrº,Ž¡�’õºâb�AÇ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–Ý·b�AÇ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“b�AÇ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–g more“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˜b�AÇ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“b�AÇ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“ab�AÇ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“b�AÇ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“sp�AÇecialising“v˜alue“ëM(+‘¹–n)“ºas“new“parameters,Ž¡�’õºâin–Ta“stš¾9yle“reminiscen˜t“of“lam˜b�AÇ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–u�it“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“sp�AÇ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˜b�AÇ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“b�AÇe“sucien�¾9tly“applied“for“all“function-v‘ÿ|raluedŽ¡�‘íºâparameters–Tto“b�AÇ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“sp�AÇecialisingŽ¡�‘íºâv‘ÿ|ralue–Î�need“to“bšAÇe“renamed“b˜efore“they“can“b˜e“safely“insertedŽ¡�‘íºâas–Tnew“parameters“of“the“sp�AÇ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“top�AÇologicallyŽ¡�‘íºâsorted.‘% W‘ÿ:«e–2adopt“the“usual“con•¾9v“en“tion–2that“the“programŽ¡�‘íºâis–bIwritten“top-to-b�AÇottom,‘u†with“anš¾9y“giv˜en“function“referringŽ¡�‘íºâonly–‘oto“its“oš¾9wn“group,‘«Ðif“recursiv˜e,‘«Ðand“groups“ab�AÇo˜v˜e“it.‘ðyTheŽ¡�‘íºârošAÇot–Texpression“is“righ�¾9t“at“the“b˜ottom.ަ�‘íºâSp�AÇ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“sp�AÇecialisation“of“an“existing“group,Ž¡�‘íºâinš¾9to– –the“program“so“as“to“main˜tain“dep�AÇendancy‘ÿ:«.‘ÿ7It“turnsŽ¡�‘íºâout– ðthat“t•¾9w“o› ðdi eren“t˜b�AÇeha“viours˜are˜p�AÇ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“sp�AÇ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–Tb�AÇ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"“sp�AÇ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“unimp�AÇortan�¾9t.Ž¡�’õºâBecause–ºthe“sp�AÇecialising“v‘ÿ|ralue“ëM(head.squareList.unit)Ž¡�’õºâºrefers–z¶to“the“source“group“from“whic�¾9h“it“originates,‘”the“re-Ž¡�’õºâsulting–âásp�AÇ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"“b�AÇ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“b�AÇe“found.‘T9As“shoš¾9wn“b˜y“Nelan“[�NelŽ‘ žº],‘ètheŽ¡�’õºâorder–)in“whicš¾9h“these“pairs“are“selected“mak˜es“no“di erence.Ž¡�’õºâUn�¾9used––Õtargets“should“bšAÇe“deleted,‘°"but“again“it“do˜esn't“mak�¾9eŽ¡�’õºâanš¾9y–Tdi erence“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“sp�AÇ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“sp�AÇ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“sp�AÇ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“sp�AÇ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Ämo�AÇdify“that“call“in“a“similar“w•¾9a“y‘TátoŽ¡�‘:âhoš¾9w–Tthe“source“call“w˜as“mo�AÇ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“sp�AÇecialised“target“group“shouldŽ¡�‘:âsplit–»or“join,‘¦b�¾9y“ nding“out“whether“the“sp�AÇ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˜b�AÇerŽ¡�’ :âof–s“exactly“one“of“the“group's“constanš¾9t“argumen˜t“sets.Ž¡�’ :âThis–|implies“that“all“inš¾9tra-group“calls“m˜ust“b�AÇe“su-Ž¡�’ :âcienš¾9tly–Tapplied“to“exp�AÇ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“(sp�AÇecialisable)“argumen�¾9ts.ަ����’äëPŽŽŽ’ :âºF‘ÿ:«or–Û7eacš¾9h“sp�AÇecialisable“argumen˜t,‘Œ¯none“of“the“freeŽ¡�’ :âlamš¾9b•AÇda-b“ound–&v‘ÿ|rariables“ma˜y“b�AÇ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˜yp�AÇe“anno-Ž¡�’õºâtations,‘Íthe–èèHaskš¾9ell“implemen˜tation“approac˜hes“1500“linesŽ¡�’õºâof‘Tco�AÇ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“exp�AÇ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“b�AÇ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˜p�AÇoin“t,‘ñ@gathering˜a˜complete˜set˜ofŽ¡�’õºâthe–‡op�AÇ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“p�AÇossible“v‘ÿ|ralues“forŽ¡�’õºâeac•¾9h›Targumen“t.‘pInitially‘ÿ:«,˜eac“h˜argumen“t˜can˜only˜b�AÇ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“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–Tsp�AÇ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˜yp�AÇes“giv˜es“ëMfoldrSpecŽ¡�’õºâºan–n`apparenš¾9t“t˜yp�AÇe“ëMb–¹–->“[a]“->“bº,‘„¢whic˜h–n`is“to�AÇ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�¾9yp�AÇ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�¾9yp�AÇe“rules“for“an“application“ofŽ¡�’õºâëMf–¹–::“(T1“->“T2)–-!ºto“ëMa–¹–::“T3–-!ºrequire“uni cation“of“ëMT1“ºwithŽ¡�’õºâëMT3º.‘pThat's–Te ectiv�¾9ely“what“is“going“on“here.ަ�’õºâThe–]Àneed“to“preservš¾9e“t˜yp�AÇe“annotations“is“a“ma‘ƒŽjor“n˜uisanceŽ¡�’õºâfrom–û°the“implemenš¾9tation“viewp•AÇoin˜t,‘5Gb“ecause–û°more“time“isŽ¡�’õºâsp�AÇenš¾9t–gqin“ xing“up“t˜yp�AÇes“than“doing“the“transformationŽ¡�’õºâprop�AÇ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“imp�AÇ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–Öpro�AÇ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–Á×co�AÇde,‘,÷c�¾9hanges“function“names“accordingly“and“re-Ž¡�’õºâstores–Tdep�AÇ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š¾9yp�AÇe“expressions“are“alw˜a˜ysŽ¡�’õºâmonomorphic.ŽŸ ��’õºâSince–B ëMmain“ºmaš¾9y“b�AÇe“of“an˜y“t˜yp�AÇe,‘Í6w˜e“trivially“monomor-Ž¡�’õºâphise–£zit“bš¾9y“substituting“an˜y“t˜yp�AÇe“v‘ÿ|rariables“with“ëMIntº.‘ÆáThisŽ¡�’õºâgiv�¾9es–ªa“single“initial“v‘ÿ|ralue“for“ëMtoVisitº,‘!with“ëMinstances“ºini-Ž¡�’õºâtially–H b�AÇ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Ž¡�‘íºâpurp�AÇoses.‘ú In–_9general,‘±²wš¾9e“can“exploit“the“fact“that“man˜yŽ¡�‘íºâdi eren•¾9t›@Rt“yp�AÇ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�¾9yp�AÇe“an-Ž¡�‘íºânotations–ñnto“domain“annotations“b�AÇefore“monomorphisation,Ž¡�‘íºâusing–ùýthe“results“of“section“2.2.5.‘ST�¾9yp�AÇe“v‘ÿ|rariables“are“simplyŽ¡�‘íºâreplaced–Tb�¾9y“domain“v‘ÿ|rariables.ŽŸòë��‘íºâ¹5.6.2Ž‘ úíCloning‘LÎco�FfdeŽŸm�‘íºâºThis–¨èis“fairly“trivial.‘×+Eac�¾9h“function“is“duplicated“once“p�AÇerŽ¡�‘íºâinstance,‘ܶwith–´Öappropriate“new“names.‘úõThe“function“b•AÇo“d-Ž¡�‘íºâies›#\ha•¾9v“e˜their˜call˜sites˜mo�AÇ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˜yp�AÇe“v‘ÿ|rariables“in“their“anno-Ž¡�‘íºâtations–çãsubstituted“appropriately“for“eacš¾9h“di eren˜t“instanceŽ¡�‘íºârequired.‘¶eThe–�ûen�¾9tire“program“can“bšAÇe“pro˜cessed“in“a“singleŽ¡�‘íºâtop-to-b�AÇottom‘Tpass.Ž© ��‘íºâThe–ŠËonly“slighš¾9tly“tric˜ky“problem“is“rebuilding“recursiv˜eŽ¡�‘íºâgroups–”0so“as“to“mainš¾9tain“dep�AÇendancy–ÿ:«.‘™F“or‘”0non-recursiv˜eŽ¡�‘íºâclones,›/this–Ã…is“easy‘ÿ:«,˜but“b�AÇecause“of“the“existance“of“cer-Ž¡�‘íºâtain›2Äcon•¾9triv“ed˜recursiv“e˜functions,‘: main“taining˜dep�AÇendancyŽ¡�‘íºâin–ó«the“recursivš¾9e“case“can“b�AÇ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“dep�AÇendancy“analyser.ަ�‘íºâDespite–8hthese“complications,‘,the“monomorphiser“is“ex-Ž¡�‘íºâtremely–aÞquicš¾9k“and“do�AÇes“not“pro˜v˜e“a“signi can˜t“limitationŽ¡�‘íºâon‘Tp�AÇerformance.ŽŽŽ�� ý€��’õºâ¹6Ž’”�DiscussionŽŸ†´�’õºâºThis–ÙÎsection“draš¾9ws“together“the“detailed“tec˜hnical“threadsޤ �’õºâexp�AÇ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“b�AÇ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“p�AÇerformance“problems“whic˜h“w˜ere“traced“toŽ¡�’õºâniceties–Xüin“the“inš¾9terface“b�AÇet˜w˜een“the“abstract“in˜terpreter“andŽ¡�’õºâthe–Tterm“rewriter.Ž© ��’õºâP�¾9erformance–òrproblems“app�AÇ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“imp�AÇortan�¾9t“to“realiseŽ¡�’õºâthat–}0the“abstract“in�¾9terpreter“will“generate“absolutely“enor-Ž¡�’õºâmous–úUterms,‘3–esp�AÇecially“from“source“text“whic�¾9h“has“deeplyŽ¡�’õºânested–BÊfunction“calls“or“deeply“nested“ëMcase“ºexpressions,‘læb�AÇothŽ¡�’õºâof–Ë�whic�¾9h“are“quite“common.‘>÷F‘ÿ:«or“example,‘ù the“bigger“pro-Ž¡�’õºâgrams–2�menš¾9tioned“in“section“6.2“generated“terms“whic˜h,‘_êwhenŽ¡�’õºâprett•¾9y-prin“ted–#in“the“stš¾9yle“used“in“this“pap�AÇer,‘&„co˜v˜ered“liter-Ž¡�’õºâally–Ttens“of“A4“pages.ަ�’õºâAnalysis–²¾of“a“program“pro�AÇceeds“as“follo�¾9ws.‘ô­First,‘Úthe“pro-Ž¡�’õºâgram–L•is“passed“in“its“en•¾9tiret“y–L•through“the“abstract“in�¾9ter-Ž¡�’õºâpreter,‘0�generating–Ä«a“corresp�AÇ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“ xp�AÇ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Ž¡�’õºâdo�AÇ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˜ xp�AÇ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,‘J�and“p�AÇerfor-Ž¡�’ :âmance–Twš¾9as“m˜uc˜h“impro˜v˜ed.ŽŸîu�’õºâA‘m†second–m±p�AÇ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,Ž¡�’õºâb�AÇecause–V”knoš¾9wing“these“v‘ÿ|ralues“mak˜es“the“ nal“term“m˜uc˜hŽ¡�’õºâsmaller.‘Ñ€In–§e ect,‘Ë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“p�AÇerformance“ gures“for“ëNAnnaŽŽŸ Ž’öff„’Ù˜ffŽŽ Œ@‰fföÌÌŽŽŽŽ öYœ���� þ%¦d��‘íºâ¹6.2Ž‘G·Absolute–LÎp�Fferfo�¹™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“b�AÇenc˜hmark“suite“[�HL92Ž‘÷l].‘íTheŽ¡�‘íºâbiggest›²›one,–ÙíëMag2hsº,“is˜prepro�AÇ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“p�AÇerformed“at“least“threeŽ¡�‘íºâtimes.‘pTimes–Tare“user“CPU“seconds.Ž© ��‘íºâSimply–Ãmeasuring“o•¾9v“erall–Ãrun“times“is“not“particularly“help-Ž¡�‘íºâful,‘mb�AÇecause–[†wš¾9e“really“w˜an˜t“to“establish“ho˜w“exp�AÇensiv˜e“thisŽ¡�‘íºâanalyser–Š¢wš¾9ould“b�AÇ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“p�AÇoinš¾9t“where“the“t˜yp�AÇ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“pro�AÇ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“prop�AÇer.‘6The“latter“category“co�¾9v-Ž¡�‘íºâers›Ç_ rsti cation,–Öömonomorphisation,“abstract˜in�¾9terpretationŽ¡�‘íºâand–¼ xp�AÇoinš¾9ting,‘DÛall“of“whic˜h“are“legitimate“analysis“exp�AÇ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:‘c this“turned“out“to“b�AÇe“plen˜t˜y‘ÿ:«.Ž¡�‘íºâThe–�¢times“rep�AÇorted“for“Glasgoš¾9w“Hask˜ell“are“for“the“compilerŽ¡�‘íºâprop�AÇ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“b�AÇ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Ž¡�‘íºâb�AÇ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–4b�AÇ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“ xp�AÇ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“pro�AÇ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“b�AÇ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“to�AÇok“for“ëMwave4mainº.Ž¡�’õºâIt–’+maš¾9y“b�AÇ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–bdco�AÇ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˜b�AÇers“{“it“only“kno˜ws“ab�AÇ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˜yp�AÇe“signatures“whic˜h“had“b�AÇ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–Âèb�AÇelievš¾9e“they“accoun˜t“for“all“the“di erence“b�AÇ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“b�AÇeŽ¡�’õºâpšAÇossible–x£that“ëMghcº's“desugarer“did“a“b˜etter“job“than“Anna'sŽ¡�’õºâin–qCtranslating“the“pattern“matc•¾9hing.‘0the‘qCdis-Ž¡�’õºâparitš¾9y–çin“relativ˜e“analysis/compile“costs“b�AÇet˜w˜een“ëMag2hs“ºandŽ¡�’õºâthe–òÔother“t•¾9w“o–òÔbig“examples“is“a“wš¾9arning“that“w˜e“should“notŽ¡�’õºâread–¡\to�AÇo“m•¾9uc“h›¡\in“to˜these˜measuremen“ts˜b�AÇey“ond˜the˜p�AÇerhapsŽ¡�’õºâheartening–ò]conclusion“that“wš¾9e“are“indeed“approac˜hing“theŽ¡�’õºârigh�¾9t–Tballpark“for“analyser“p�AÇ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“pap�AÇers“includeŽ¡�‘íºâthe–*Burn-Hankin-Abramsky“wš¾9ork“[�BHA85Ž‘¬b]“whic˜h“put“higherŽ¡�‘íºâorder–„analysis“on“a“ rm“theoretical“fo�AÇoting,‘TPand“W‘ÿ:«adler'sŽ¡�‘íºâpap�AÇ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–¤ xp�AÇ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“p�AÇ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“b�AÇelieving“the“situation“cannotŽ¡�‘íºâb�AÇe‘Timpro•¾9v“ed.Ž© ��‘íºâStarting–{at“around“the“same“time,‘™íanother“scš¾9ho�AÇ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]b�AÇ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“prop�AÇ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“p�AÇolymorphic“[�HugŽ‘³+],‘q¤andŽ¡�‘íºâa–Úñsuccessful“non- at,‘ Wp�AÇ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,‘=p�AÇeople›xha“v“e˜b•AÇeen˜lo“oking˜at˜other˜w•¾9a“ys˜of˜solv-Ž¡�‘íºâing–vÝrecursiv�¾9e“domain“equations.‘A There“has“b�AÇeen“a“discern-Ž¡�‘íºâable–Jƒshift“to•¾9w“ards–Jƒterm“orienš¾9ted“approac˜hes.‘»üF‘ÿ:«erguson“andŽ¡�‘íºâHughes–ö#dev�¾9elop�AÇ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“ xp�AÇoin˜ting“mec˜hanism“re-Ž¡�‘íºâmains–þto“b�AÇe“seen.‘îmEarly“implemenš¾9tations“hin˜ted“at“spaceŽ¡�‘íºâproblems,‘€but–®Dthese“maš¾9y“no˜w“ha˜v˜e“b�AÇeen“solv˜ed“[�Hug93Ž‘ó'].Ž¡�‘íºâCDSs–/·can“also“b�AÇe“view�¾9ed“as“a“higher-order“generalisationŽ¡�‘íºâof–ÁÁthe“minimal“function“graph“sc�¾9heme“originally“describ�AÇ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“pap�AÇer“[�Con91Ž‘±¼],Ž¡�’õºâwhicš¾9h–Îseems“to“ha˜v˜e“passed“b˜y“almost“unnoticed,‘µdescrib�AÇedŽ¡�’õºâa–7#successful,›–if“simple,˜strictness“analyser“solving“ xp�AÇoin�¾9tŽ¡�’õºâequations–•Ybš¾9y“term“rewriting.‘œIn“view“of“ho˜w“w˜ell“this“andŽ¡�’õºâConsel's–}ásystem“wš¾9ork,‘œ,it“is“p�AÇ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“pap�AÇer“[�PC87Ž‘9�].ŽŸ5��’õºâ¹6.4Ž’ G·F•¹™urther‘LÎw“o“rkŽŸm�’õºâºAnna's–N¾p�AÇerformance“is“encouraging.‘È­Nev�¾9ertheless,‘�there'sŽ¡�’õºâstill–ê¿a“long“w•¾9a“y–ê¿to“go“b�AÇ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“ xp�AÇoinš¾9t.‘×ðThe“w˜ork“of“Nielson“and“Nielson“[�NN92Ž‘>]Ž¡�’ :âgivš¾9es–7ethe“magic“n˜um˜b�AÇer“of“iterations“needed.‘ÒvF‘ÿ:«or“man˜yŽ¡�’ :âcommon–’'forms,›ñ[this“n•¾9um“b�AÇer–’'is“reasonably“lo�¾9w,˜andŽ¡�’ :âit–Zseems“reasonable“to“exp�AÇ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�¾9yp�AÇ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“p�K¼erformance.‘÷ÙºThe–§Žre nemen�¾9ts“ofŽ¡�’ :âsection–=Œ6.1“ha•¾9v“e–=Œdone“a“lot“to“impro•¾9v“e–=Œthe“system'sŽ¡�’ :âp�AÇ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“b�AÇeingŽ¡�’ :âmade.ަ�’ :âFixp�AÇoin�¾9ting–L½large“groups“of“functions“could“conciev-Ž¡�’ :âably–ðb�AÇ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– åºresp�AÇectivš¾9ely‘ÿ:«.‘ This“halv˜es“the“n˜um˜b�AÇer“of“functions“inŽ¡�’ :âthe–ÿ2group“bšAÇeing“ xp˜oin�¾9ted.‘Ú Once“the“solutions“to“ëMaŽ¡�’ :âºand–ÆlëMc“ºha•¾9v“e–Ælb�AÇ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“b�AÇe“used“in“an˜y“situa-Ž¡�’ :âtion›¥¿in•¾9v“olving˜ xp�AÇoin“ting˜m“utually˜recursiv“e˜groups˜ofŽ¡�’ :âequations.‘µÆThe–�Æidea“stems“from“an“analogy“with“theŽ¡�’ :âGauss-Jordan–„¨metho�AÇd“for“solving“sim�¾9ultaneous“linearŽ¡�’ :âequations.‘zíIn–4Óthis“case,‘<³a“recursiv�¾9e“group“can“only“b�AÇeŽ¡�’ :âreduced–Ito“the“p�AÇoinš¾9t“where“ev˜ery“equation“in“the“groupŽ¡�’ :ârefers–öœdirectly“to“itself“{“no“further.‘ÀHAfter“that,‘.î x-Ž¡�’ :âp�AÇoinš¾9ting–x is“una˜v˜oidable.‘D�Whether“or“not“this“rendersŽ¡�’ :âa–ŸspšAÇeedup“dep˜ends“on“the“relativ�¾9e“costs“of“substitution,Ž¡�’ :âbacš¾9k–Tsubstitution“and“ xp�AÇoin˜ting.ŽŽŽŽŽŸ�’åä28ŽŽŒ‹ÜÑ •ºâ� ý? £���� ý€����‘ûäëPŽŽŽ‘:âëNDealing–�¦with“mo�K¼dulesº.‘ 5�Mo�AÇdules–ÈZare“an“unmiti-ޤ �‘:âgated–†Çnš¾9uisance“for“man˜y“kinds“of“high“p�AÇo˜w˜ered“seman-Ž¡�‘:âtic–xManalyses“and“optimisations.‘E\In“particular,‘Ñ mo�AÇ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“mo�AÇ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“p�AÇ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˜termo�AÇduleŽ¡�‘:âcommš¾9unication–?™to“mak˜e“global“analyses“p�AÇossible.‘›?De-Ž¡�‘:âv•¾9elopmen“t–»fof“sucš¾9h“a“framew˜ork“w˜ould“b�AÇene t“not“onlyŽ¡�‘:âstrictness–oªanalysis,‘†@but“man�¾9y“asp�AÇects“of“compile“timeŽ¡�‘:âoptimisation.‘©¨Sucš¾9h–™¼a“compiler“migh˜t“w˜ork“b˜y“dump-Ž¡�‘:âing–^øa“lot“of“information“inš¾9to“a“mo�AÇdule's“in˜terface“ le,Ž¡�‘:âenough–A‚to“do“whatevš¾9er“analyses“w˜e“need.‘ úThis“w˜ouldŽ¡�‘:âreally–©„just“b�AÇ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“dump�AÇed“in�¾9to“in-Ž¡�‘:âterface–3ú les“could“b�AÇ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“ab�AÇout“monomorphisationŽ¡�‘íºâand–Oz rsti cation,‘^and“outlined“the“instance-collecting“algo-Ž¡�‘íºârithm–߯of“Section“5.6.1.‘ ŽGeo rey“Burn“and“Denis“Ho•¾9w“e‘߯w“ereŽ¡�‘íºâsucien•¾9tly›8Öbra“v“e˜to˜exp�AÇ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“oteb�AÇorg,˜Sw�¾9eden,˜1987.Ž©¶Ö���‘íºâ[Aug93]ŽŽ‘fLennart–¤êAugustsson.‘b�Implemenš¾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,›NRep�AÇ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