e gritique of tndrd wv
endrew F eppel rineton niversity revised version of gEEQTREWP xovemer IPD IWWP
estrt I hy s like wv
tndrd wv is n exellent lnguge for sn this setion s list the resons why s like proE mny kinds of progrmmingF st is sfeD efE grmming in wvD in deresing order of importneF ientD suitly strtD nd oniseF here ome fetures of the lnguge for whih wv is esE re mny spets of the lnguge tht work peilly known fll surprisingly fr down the listF wellF
roweverD nothing is perfetX tndrd wv hs fety few shortomingsF sn some ses there re gertin progrmming errors nnot lE ovious solutionsD nd in other ses further reserh is requiredF wys e deteted y ompilerD nd must e heply detetle t run timeY in no se n they e llowed to give rise to he wetEvnguge of the idinurgh vgp mhineE or implementtionEdependent efE theoremEproving system IP evolved into freeE fetsD whih re inexplile in terms of stnding progrmming environment U nd then the lnguge itselfF his is riterion to into tndrd wv PWD PTF efter further evolution whih s give the nme seurityF the lnguge is firly stle QIF gF eF F roreD IWUQF IQ his is ritique of the lnguge from two perE spetivesX the user9s nd the implementor9sF he yne of the most plesnt things out wv is tht rst prt of this pper desries why wv is plesE it is sfeX progrms nnot orrupt the runtime sysE nt lnguge to useD nd the seond shows how some tem so tht further exeution of the progrm is not of these lnguge fetures re interesting to ompileF fithful to the lnguge semntisFI xelson QP diE hen the third nd fourth prts of the pper point vides progrmming lnguges into three geneologiE out some of the nnoynes wv progrmmers nd l tegoriesX he fgv fmilyD inluding g nd implementors hve to del withF gCCD whih re not sfeY the elgol fmilyD inludE ing sl nd edD whih re lmost sfeY nd the
upported in prt y xp grnt ggEWHHPUVTF Ihnks to the wodulEQ mnul QP for this phrsing
I mthemtilly derived4 fmilyD inluding vispD modern lngugesD from ll three of the fmilies wvD mlltlkD nd gv D whih re sfe|exept mentioned oveD hve dynmi storge llotionF when visp progrmmers disle runtime type hekE futD in generlD only lnguges of the mthemtiE ing euse it9s too expensiveF @here reD of ourseD l4 tegory hve utomti grge olletionF sn lnguges suh s pyex nd gyfyv tht do the fgv nd elgol fmiliesD dynmi storge tht not fll into these tegoriesFA is no longer tive must e expliitly freed y the sn sfe lngugeD ll errors tht ould deE progrm if it is to e reEusedF st is prtilly imE ril4 the progrm @use ehvior not explinle possile @iFeFD no one knows howA to mke sfe in terms of the soure lngugeA re deteted either lnguge with expliit storge dellotionF his t ompile time or t run timeF P his mkes it is the min @though not the onlyA reson tht lnE muh esier to reson out progrm ehviorX if guges of the elgol fmily re not ompletely sfeF n expression uses the rst element of list lD we sn some g or sl progrms it is ovious n e ssured tht l is relly list nd not misE where to put the free or dispose sttementsF fut understood integerF purthermoreD lrge lss of when dt strutures get just it more ompliE storgeEllotion mistkes ommon to unsfe lnE tedD it9s hrder to predit when to dispose of guges re simply not possile in wvF thingsF rogrmmers often resort to expliit referE hen fllile humns ttempt to write lrge proE ene ountsD or even to speilEpurpose mrkEndE grms to do omplited thingsD sfety is very imE sweep grge olletors implemented new for eh portntF yf ourseD sfety is not the sme thing lss of reordF s freedom from ugsF fut t lest the ugs n he prolem eomes worse ross module e understood in the frmework of the lnguge seE oundriesF sf server4 module implements n E mntis @forml or informlAF here is no ehvior strtion using dynmi storgeD then the lient4 tht nnotD in prinipleD e predited from the proE module won9t know the formt of the reords to grm textF dispose of themF fut the server won9t know when sn n unsfe lngugeD progrm ugs tht orrupt the lient is nished with the strt ojetsF e the runtime system re usully the most diult to typil solution is to dd new opertors to the E dignose nd hve the most disstrous eetsF fut strt interfe for freeing of strt ojetsF his in sfe lngugeD even uggy progrms sty within quikly eomes tediousF the semnti model4 of the lngugeD whih mkes torge llotion ugs n orrupt the runtime progrm development muh esierF systemD or go undeteted until millions of proE grm sttements hve een exeuted fter the erE rorF hus they re prtiulrly nsty to dignoseF qrge olletion fe lnguges of the mthemtil4 fmilyD inE qrge olletion frees the progrmmer from lE luding tndrd wvD hve utomti grge olE ulting the lifetime of every ojet in order to delE letion nd void this kind of ug entirelyF lote itF ith utomti storge mngement it is possile to write progrms more oniselyD elegntlyD gompileEtime type heking nd strtlyY one n mnipulte vluesD insted rogrmmers mke mistkesF iven when they hve of ojets whose ddresses must e rememered so proved their lgorithms orret in some forml or they n e freedF informl senseD it9s diult to void ll errors when iven with grge olletorD the progrmmer trnslting into the onrete forml nottion of should void keeping unneessry pointers to useless progrmming lngugeF ine s m prtiulrly ojets lest the progrm use too muh speY oE slpdsh in my progrmmingD perhps s mke even sionlly it my e neessry to nlyze nd rewrite more mistkes thn the verge progrmmerF prts of the progrm to void keeping dt struE o s must nd my mistkes nd x themF eny tures live QURD hpter IPF fut this performne help tht the progrmming environment n give tuning is preferle to the orretness tuning4 neE me in nding mistkes is most welomeF es prE essry in lnguge with expliit disposeF til mtterD s hve found tht the vst mjority of ithout grge olletionD it is diult to mke my mistkes re found t ompileEtime y the wv sfe lnguge tht does interesting thingsF ell type hekerF hese mistkes re prtiulrly esy Psn wvD nything deteted t run time is onsidered to to xD euseX e n exeptionD4 not n errorY4 exeptions inlude suh events s rithmeti overowD rryEounds errorsD nd tkE gompiling something tkes less time thn omE ing the hed of n empty listF piling nd running itF
P yne ompiltion n nd mny ompileEtime @with ode genertionA efore ny tul prmeE errorsY it9s hrder to nd severl ugs with one ter is presentedF he sme rguments in fvor of run @or even one ompile nd severl runsA of ompileEtime type heking lso fvor the heking progrmF of funtors when they re prsedD independently of the rguments to whih they might e ppliedF gompileEtime errors re ught regrdless of sn lnguge with prmeterized modules nd the input dtY runEtime type errors my not e strt dt typesD it9s neessry to hek tht ught until the progrm is exerised on mny given strt type lwys refers to the sme onE inputsF rete representtion|ut t the sme timeD withE gompileEtime errors often ome with helpful out giving wy4 the representtionF sn ed nd explntionsY runEtime errors n e hrder to wodulEQ suh heking is possile euse omE dignoseF piltion4 @nd type hekingA of the prmeterized module ody is done for eh pplition to tul pinllyD ompileEtype types @espeilly the eleE prmetersF wv uses the shring speQ to require gnt type system of wvA help me to understnd tht two funtor prmeters must use the sme repE my progrm in onsistent wyD so tht perhps s resenttion for shred strt dt typeF mke fewer mistkes in the rst pleF por exmpleD suppose the signture @interfeA st is interesting to note tht most lnguges of the rer speies module to mp strings to unique mthemtil4 fmily hve hd runEtime type sysE tokensF here re ertinly dierent wys to impleE tems @in vispD hemeD mlltlkD evD etFAD while ment this signtureY nd even the sme implementE the elgolElike lnguges hve hd ompileEtime type tion might exist in multiple instnesD mintining hekingF erhps this is euse the mthemtiE dierent hsh tlesF xowD if prser module rse l4 lnguges hve grge olletorsY grge olE with signture ei produes prse trees ontinE letors require some runEtime type informtion to ing tokensD nd type heking module ypehek tre rehle ojetsY s long s the type inforE @with signture igriguA lso dels with tokensD mtion is in the runEtime dt there is tempttion they n e omined using premeterized modE to use itY or perhps no one knew how to do good ule gompilerX mthemtil4 ompileEtime typeEheking efore wv9s type system PV ws inventedF yf ourseD runE funtor gompiler@ struture X ei time type heking n e slowY ut the mthemtE struture X igrigu il4 lnguges hve not hd rw speed s primry shring Frsh a Frsh design onernF sn wvD the sene of runEtime A a F F F heking does mke for more eient implementE he dvntge of prmeterizing gompile is tht it tionY this will e disussed elowF n e pplied to dierent prsers or dierent typeE heking lgorithms lter onF fut the progrm will he module system e meningless unless the prtiulr rse modE ule we use relies on the sme rsh tle s the wv hs module system supporting strt dt ypehek module doesF end|even worse|if the typesD hiding of representtionsD nd typeEheked internl representtion of the unique tokens is suE interfesF wodules re very importnt in struturE iently dierentD then the progrm is not even sfe ing lrge softwre systemsF from mistking pointers from integersD etF wv9s wuh hs een written out the dvntges of module system my e unique in sfely omining modules nd strt dt typesF he lsses4 of ompiled prmeterized modules with strt dt yjetEyriented progrmming re kind of modE typesF uleD nd support strtion nielyY s re the modules4 of wodul nd edF st is not ontroE versil to sy tht modules with enfored interfes smmutle vlues nd representtionEhiding re n essentil feture of modern progrmming lngugeF sn funtionl lnguge one desries the reltionE wv9s module system is prtiulrly nieD in tht ships etween vluesD not ojetsF s will illustrte it llows one module to e prmeterized y the inE with silly exmpleF gonsider the sttements @in terfe of notherF edI nd wodulEQQP lso some progrmming lngugeAD support generi4 modules tht re prmeterized Qreneforth s will use spe to men the syntti onE in this wyF roweverD wv is unusul in tht its pE strut in wv signturesD nd speition in more generlD rmeterized modules|funtors|n e ompiled informl senseF
Q x Xa ICT RQF fut there re millions of progrmmers who y Xa PCS hve suiently omprehended the notion of ssignE xowD to reson out the reltionship etween x ment nd updtele dt strutures to write suE nd yD one might sk the following questionsX essful progrmsF yf ourseD the sme rgument ould e mde for ringing k the goto nd ss x the sme U s yc the TREkiloyte ddress speF fut it is true tht sf we modify xD does y hngec progrmming with updtes is proven tehnologyD nd progrmming entirely without them is still reE xeed we mke opy of U to implement zXaxc serhF4 xowD other lnguges hve omined funtionl hen we9re done with x how do we dispose of style with the pility to do updtes|hemeD the Uc for exmpleF fut the question isD how n these two sf these questions seem sillyD onsider the nlogous styles e omined without losing the enets of the se for this progrm frgmentX immutle vluesc yne updtes re permittedD the x Xa ons@DA silly4 questions posed in the previous setion egin y Xa ons@DA to hve omplited nswersF xowD is x the sme list ell s yc sf we modify wv solves this prolem y refully segregting r@xAD does y hngec hen should we mke the mutle nd the immutle typesF en integer opy of the ons ellc row do we dispose of itc vlues hs type intD nd mutle ell ontining he disposl question is dequtely hndled in n integer hs type int refY these types re not lnguges with grge olletionD of ourseF fut the smeF yne n feth the @immutleA vlue out the updte nd identity questions re notF st is of n int ref nd ind it to vrile of type intY very distrtingD when writing nd understnding one n store dierent @immutleA vlue in the progrmD to worry out shring of sustruturesD int refF eferene vlues re the only ones for sideEeetsD nd lisingF @en optimizing ompiler whih questions of shring nd identity re imporE is distrted y these prolems too3A tntF hese questions re ll silly for integers euse eferene ells n e omponents of dt struE we tret integers s vluesD not ojetsF sf we onE turesF por exmpleD tree shown elow is the type sidered integers s ojetsD perhps with omE of immutle trees with integer levesY elements of mnd to updte4 some of the its of n integer oE treeI re trees whose leves my e modied ut jetD then the omplexities listed ove would hve whose struture is immutleF yn the ontrryD the to e onsidered y nyone progrmming with inE leves of treeP re immutle ut the struture n tegersF e reErrnged @nd entirely new leves n e inE lues hve mny dvntges over ojetsF hrE sertedAX ing of the sustrutures of vlues never leds to prolems if the sustrutures n9t e modiedF yne doesn9t need to reson out equl versus idenE dttype tree til vlues|nd to ensure tht this is trueD wv a viep of int does not permit testing ddress equlity on imE | xyhi of tree B tree mutle typesF yne n perform indution over struture to prove useful things out vluesY for dttype treeI ojets one hs to do indution over their historiesD a viep of int ref whih omplites resoning out themF | xyhi of treeI B treeI dttype treeP wutle ojets a viep of int iven though vlues hve mny nie propertiesD the | xyhi of treeP ref B treeP ref notion of mutle ojets should not e disrdedF ynly n extremist would sy tht updtele ells wutle referene ellsD whih re refully idenE re lwys too hrd to use nd understndF he tied in dvne to the ompiler nd the humn extremists might yet e proved rightX it is ertinly reder of the progrmD hve turned out to e very true tht ny lgorithm on ojets n e simuE good ompromiseF hey llow vlueEsed resonE lted on vluesD nd reent work hs mde suh ing out nonEreferenesD nd the use of updtes lgorithms ever more redle nd understndle where neessryF
R olymorphi types overspeify it s intF o the length funtionD just s writtenD hs type list 3 int for ny D nd he impliit prmetri polymorphism of wv is n e pplied to lists of stringsD lists of relsD lists gret onvenieneF sn writing g or sl progrm of listsD nd so onF tht dels in linked lists of severl dierent types of ojetsD for exmpleD it is othersome to hve to opy lmost vertim the denitions of funE gomplete forml denition tions to rete listsD mp funtions over listsD reE verse listsD lulte lengths of listsD nd so onF sn he progrmming lnguge sl ws n dvne wvD s in vispD the sme mp funtion n operE in lnguge designD nd eme very populrD for te on list of nythingD nd similrly for lengthD severl resonsF st supported len nd useful reverseD nd onsF he length funtion is polyE ontrol strutures nd dt struturesF st is morphiX it hs the type int list 3 int nd smll enough lngugeD nd ws speied preisely the type string list 3 int nd mny others eE enough @in informl proseA IT tht people ould sidesF sn ojetEoriented lnguges with inheriE understnd wht sl progrms should doF tneD polymorphism n e hieved without muh fut sl still hs miguities nd inseurities4 diulty @depending on the lngugeAF fut in gD RTF ht isD the lnguge denition is miguous polymorphism n e omplished only y using out the mening of ertin onstruts @nd difE st to void the typeEhekerD nd in sl only ferent ompilers give dierent results on the sme y lumsy use of vrint reordsF progrmAY nd the lnguge is inseureX it is not sfe in the sense desried y roreF ype inferene wv is not only seureD it is lso unmiguously sn wv it is neverR neessry to delre types for denedF he henition of tndrd wv QI is vriles or for funtions nd their forml prmE omplete opertionl semntis for the entire lnE etersF he ompiler n infer types for these idenE gugeF yne n use the henition to lulte exE tiersD nd it heks tht the vriles re used tly whih progrms should e epted y omE onsistentlyF hus wv hieves the dvntges of pilerD nd wht their result will eF ompileEtime typeEheking with the oniseness of purthermoreD the henition @with ompnying undelred typesF ommentry QHA is redle|s forml semnti his is onvenieneD ut of ourse it doesn9t denitions goF his does not men tht the deE shorten progrms y n enormous ftorX in lnE nition is suitle s mnul for the progrmmerY guges with expliitly delred typesD the type deE there is too muh forml nottion nd not enough lrtions don9t overwhelm the progrmF e ig dE worked exmples for thtF fut the student of lnE vntge of type inferene is tht the ompiler infers guge designD or the serious ompilerEwriterD n the most generl @polymorphiA type for eh funE use the henition s referene to understnd the tionF hen the progrmmer doesn9t tend to premE mening of ny onstrut tht might e in doutF turely overEspeify the types of funtionsF his leds to portility etween implementtionsD por exmpleD onsider writing length funtion provility of progrms @in prinipleAD nd onE to ompute the numer of integers in listXS dene in the sfety nd seurity of wv progrmsF fun length @hedXXrestA a I C length@restA he henition hsD over timeD proved to e | length @nilA a H trtle enough to serve s the sis for useful feuse the progrmmer needn9t speify the type tehnil disussion mong its mny redersF iven of the list element hedD there is no tempttion to when there hve turned out to e holes in the heE nitionD they n e disussed nd repired with onE R wellD hrdly everY see the setion on yverlodingF dene nd greement over wht the hnges menF Se list in wv n e emptyD or nilD or n e ons4 ell ontining hed4 @rst elementA nd e forml denition is merely omplited goodE til4 @the rest of the listAF husD list is disE luk hrm unless it n e used to prove importnt joint union typeD or dttypeD of the following formX properties of the lngugeF he henition is mthE dttype 9 list a nil | XX of 9 B 9 list he onstrutors of this dttype re nil nd XX @proE emtilly trtle enough to proveD for exmpleD nouned ons4AF ell the elements of list must e of tht progrms tht typeEhek will exeute sfelyD4 the sme typeY if this type isD eFgFD then the list is lled tht there n e no dngling referenes4 @invlid n listF feuse keyords don9t hve qreek lettersD we pointersAD tht the type inferene lgorithm lwys write s 9F st is onvenient to mke XX inx nd rightE ssoitive y defultD so tht IXXPXXQXXnil is the list of the nds the most generl type for n expressionD nd rst three positive integersF mny other theorems tht inspire ondene in the
S semntis of the lngugeT QHF no opertors @suh s ontenteA tht n rete he proponents of forml speitions of proE new hrterEstring vlues t run time3 hen the grmming lnguges hve long limed tht semnE hrterEstring type would e of limited utilityY tis should e used s tool for lnguge designD not one might use it for printing intertive prompts just for writing down the semntis of existing lnE dened t ompile timeD nd so onF eny dt type gugesF he oniseness nd ompleteness of the in whih one n only pss round ompileEtime litE wv henition stemD in prtD from the relutne of erlsD is hrdly rstElssF4 the tndrd wv design ommittee to dmit feE fut this is extly the sitution for funtion tures into the lnguge for whih they didn9t unE pointers in g3 he only funtion vlues re those derstnd how to write provly sound semntisF reted t ompile timeY one nnot mke new4 funtions like fI nd fIH shown in the exmple righerEorder funtions oveF his is euse g does not llow nested funtions with lexil sopeF imilrlyD even though sn wvD s in heme nd other lnguges derived wodulEQ hs nested funtions nd lexil sopeD from the !ElulusD funtions re rstElss vlues only funtions t the outermost level of nesting n tht my e pssed s rgumentsD returned s reE e pssed s rgumentsF sultsD nd put into dt struturesF yn the other hndD sl llows nested funtions yf ourseD the g progrmming lnguge hs @with lexil sopeA to e pssed s rgumentsD ut rstElss4 funtionsD tooY ut there is n imporE not to e returned s results or stored in dt struE tnt dierene etween the funtionl vlues of wv turesF his restrition limits the utility of funE nd those of gF wv hs nested funtion denitions tion vluesF foth the g restrition nd the sE with lexil sopeY the inner funtions n refer to l restrition re motivted y the desire to void lol vriles nd forml prmeters of the outer the need for grge olletionX rstElss funtions funtionsF husD eh time n outer funtion is with nested sope nnot e implemented with invoked with dierent tul prmetersD new4 onventionl stk of tivtion reordsF fut when version of the inner funtion is uiltF e simple exE the system hs grge olletor lredyD rstE mpleX lss nested funtionl vlues don9t dd gret omE fun dd@xX intA a plexity to the implementtion of the lngugeF let fun f@yA a xCy erhps one must write some progrms with in f higherEorder funtions to relly ppreite their exE end pressivenessF roweverD s will present some exmples of their useX vl smllin a dd@IA vl igin a dd@IHA edution funtions on listsX ke inry opertor @like C or AD nd pply it to n entire vl twelve a smllin@igin@IAA sequene of vluesD thusX he fun keyword introdues funtion delrtionF XXX I he let de in exp end syntx introdues lol I P n delrtion de visile only in the expression expF @eppend the term I in order to ppropriE husD when dd is pplied to ID the funtion fI@yA a tely hndle the se where n a HFA his noE IC y is reted nd returned s resultF hen tion n e esily generlizedX given n operE dd IH is omputedD the funtion fIH@yA a IH C y tor opr nd n identity s for tht opertorD U is the resultF redue@oprY sA is the funtion tht pplies the smgineD for momentD progrmming lnguge opertor to n entire list of vluesF husD the in whih hrterEstring vlues n e stored in funtion sum tht totls the elements of list vrilesD pssed s rgumentsD returned s reE is just redue@CY HA nd produt is redue@Y IAF sultsY suppose there re hrterEstring literlsD sn wv one might writeX nd it9s possile to extrt the individul hrE ters from string vluesF fut suppose there re fun redue@oprDsA a Tome of the theorems mentioned hve tully een let fun f@nilA a s proved only for susets of tndrd wvF | f@XXrestA a opr@D f@restAA U his dd funtion n e written more onisely s in f fun dd x y a xCyXint where the type onstrint Xint is neessry euse of overE end lodingY see setion QF
T vl sum a redue@op CD HA it is importnt tht wv n e ompiled to run vl produt a redue@op BD IA eientlyF here re mny resons to elieve tht fun min@D XintA a if ` then else it nF wv hs ompileEtime type hekingD whih vl infinity a IHHHHHHHHH mens tht type tgs need not e rried round t vl minlist a redue@minDinfinityA run timeD nd opertors need not hek the types of vl fifteen a sum@IXXPXXQXXRXXSXXnilA their rguments t run timeF wv does not hve the dynmi method lookup4 required of mny ojetE he op keyword llows n inx opertor like B oriented lngugesF to e used s n ordinry identierF wv does do rryEounds hekingD whih is not present in g nd whih slows things down unless indow mngerX yne ould orgnize window sfely removed y good optimizing ompilerF wv interfe so tht n pplition running in does hek pointers for nil efore derefereningY ut window is represented y its keyord nd the wy this is inorported in ptternEmthing V mouseF o hnd the pplition hrters feture of the lngugeD these tests will e prt of typed into its windowD one lls its keyord the ordinry ontrol ow written y the progrmE funtionY to give it mouseEliksD one lls its merF @ nfortuntelyD sometimes the progrmmer mouse funtionF husX knows tht list n9t e nilD ut the hek must e done nywy exept y n impossily intelligent type windowpp a ompilerFA end wv heks for overow of rithE {keyordX stringEbunitD meti expressionsD ut on most omputers this is mouseX intBintEbunit} hndled y the hrdwre without the need to issue extr instrutionsF his sys tht windowpp is reord type fut n wv e s eient s gc o some extentD ontining two eldsD keyord nd mouseF this is still reserh question @one tht interests me keyord is funtion tht tkes string pE very muhAF st9s diult question to nswerD eE rmeter nd returns unit4 @whih is pleE use it requires tht the sme4 progrm e writE holder like void4 in gAD nd mouse tkes ten oth in g nd in tndrd wvF end wht does oordinteEpir s n rgumentF xowD the winE it men to sy tht progrm written in idiomti dow mnger n pss keypresses nd mouseE g is the sme4 s one written in idiomti wvc liks to the pplition y lling these funE yne might mke good ttempt t quntitE tionsF his hs n ojetEoriented4 vorY the tive mesurement y rewriting some g progrms in privte dt of the pplition @iFeFD self4 in idiomti wvD nd vie versD nd running the reE yy terminologyA is hidden in the free vriE sults with good4 ompilers on the sme hrdwreF les of the two funtionsF sn g it would e his is suiently unrewrding jo tht few peoE neessry to inlude n expliit self4 eld in ple hve done it on relisti4 progrmsF the windowpp reordD nd pss this s n exE yn the other hndD there re mny good heme tr rgument to keyord nd mouseF ompilersF hile heme does not run s eiently wost of the interesting uses of rstElss funtions s g on ll prolemsD heme nd gommon visp re omine the use of nested lexil sope @where inner suiently eient tht mny rel pplitions re funtions9 free vriles re ound in outer funE written in themF st should e possile to get wv to run t lest s eiently s hemeD sine the lnE tionsA with funtions returned s results or stored guges re similr in mny wys ut wv doesn9t reE in dt struturesF husD the very omintion tht is left out of g nd sl euse it is diult to quire the runEtime type heking tht heme doesF implement @it requires grge olletor for tiE sn ny seD there is t lest one resonly efE vtion reordsA is the most usefulF ient implementtion of wv TF his nd other implementtions W hve mny usersD for whom they iieny Weverl tndrd wv implementtions re villeX tndrd wv of xew terseyD from rineton niE en elegnt lnguge will hve few pplitions if versity nd e8 fell vortories @ontt pE progrms written in it lwys run too slowlyF o peldprinetonFeduA olyGwvD from estrt rrdwre vtdF @ontt Ven interesting nd useful windowing lirry hs een odhlFoFukA implemented in wv y qnsner nd eppyQT s very elegnt interfe to n serverF he exmple here does not oplog wvD from the niversity of ussex desrie their systemF @isldintegFuupD popdsFumssFeduA
U re dequtely eientY this might not e the se estritive type systemX wv9s type system is if they were too slow y n order of mgnitudeF less restritive thn tht of most sttillyE wv progrms @run under some ompilersA hve typed lnguges @exept thoseD like gD tht lE used muh more spe thn omprle g proE low evsion of the type systemAF sn return for grmsF his is serious prolemD ut reent reE oeying the type rulesD the progrmmer is reE serh RD hpter IP hs hinted t solutionsF et wrded with ompileEtime error messges inE presentD it ppers tht wv is eient enough to sted of runEtime ugsF use for wide vriety of pplitionsF g progrms re fster proly y no more thn ftor of twoD wuttion @nd lk thereofAX wv mkes it inE nd often less thn thtF por mny purposesD wv9s ovenient @ut not extremely soA to modify dvntges in sfetyD elegneD ese of storge mnE elds of dt struturesX suh elds must e gementD nd so on my outweigh this dierene in delred in dvneF his is just enough to performneF end progrms tht require ompliE enourge funtionl style of progrmming ted nd expensive storge mngement in g my @whih is goodA with n espe hth where run fster in n wv implementtion with good neessry @whih is lso goodAF grge olletor VF vk of ess to mhineX wv sueeds ll too well in strting wy from the mhineF hy some people don9t like wv his mkes it diult to implement those proE grms tht must do mhineElevel thingsD with en @nonymousA erly reviewer of this pper omE memory wordsD pgesD protetionsD signlsD etF plined out wv9s lk of dynmi typesD mutE st is possile to mke interfes to these things tion @nd lk thereofAD lk of ess to mhine @s in wvY ut it must still e dmitted tht in gAD restritive type systemD smll hnges usully typil wv system hs lrge runtime system require omplete reompiltionD izrre syntxD lk written in g to hndle the things tht ouldn9t of mrosD etF4 e implemented in wvF hese ritiisms merit some disussionF eompiltionX eprte ompiltion is essentil vk of dynmi typesX here re some things in progrmming environmentF sn sttillyE tht re esier to do in dynmillyEtyped typed lnguges suh s g or wodulD system lngugeF por exmpleD sutyping is esy to do like mke n reompile just those les tht in vispD sine listEofErel is utomtilly suE my need itY in dynmillyEtyped lnguges type of listEofE@relEorEstringAY nd wv doesn9t suh s vispD only les tully modied need hve sutyping mehnismF fut suh exmE reompiltion @in the sene of mro deniE ples re not very ompellingY n wv progrm tionsD of ourseAF might hve few more injetion nd projetion funtions thn visp progrmF smplementtions of tndrd wv hve not usuE e more interesting use of dynmi types is for lly hd very good seprte ompiltion sysE temsF his is prtly prolem with the lnE progrms tht wish to do typeEsfeD strutured gugeD s elorted in setion RD ut mostly inputGoutputD whih is prolemti in tnE drd wvF ithin the wv ommunityD the type prolem with the individul implementtionsF dynmi hs een proposed s solution to sn ny seD it ppers to e prolem tht this prolemPPX vlues of type dynmi would n e solved without modifying the lnguge rry full wvEstyle types s prt of their runE denitionF time representtionD nd ould e oered into fizrre syntxX visp syntx hs wonderful onE ordinry sttillyEtyped vlues with runtime sistenyD ut is n quired tsteF tndrd hekF wv syntx is mediore exmple of the elE idinurgh wv RFHD from the niversity of idinurgh gol shoolD in whih keywords re used insted @lfsdedFFukA of some of the prenthesesD nd in whih inx ex wvD from the eustrlin xtionl niversity opertors re used where it mkes sense to do @mndnusdFnuFozFuA soF ome of the ovious ugs4 in the grmE wirowvD from the niversity of meD weden mr re reported lter in this pperY ut in @olofdsFumuFseA generlD don9t we hve etter things to rgue out thn syntxc
V vk of mrosX his is lerly n dvntgeD not gompileEtime type heking disdvntgeF por the progrmmer to hve to gompilers for lnguges with runEtime type hekE lulte stringEtoEstring rewrite of the proE ingD suh s visp nd mlltlkD must work very grm efore ny semnti nlysis invites proE hrd to minimize the exeution ost of type hekE lems of the worst kindF here mros re used ingF en dvntge of wv @nd ll lnguges of the to ttin the eet of inEline expnsion of funE elgol nd fgv fmiliesA is tht ll type hekE tionsD they re doing something tht should e ing is done t ompile timeD nd does not slow the done y n optimizing ompilerF here mros exeution of the progrmF re used to ttin llEyEnmeD the eet n e otined y pssing suspension s n rE gumentY in wv this is written with the syntx epresenttion nlysis fn@Aab whih though dmittedly ugly is firly he types of vriles in wv re known suiently oniseD nd is etter thn tolerting the seE t ompile time to gurnteeD s in elgolElike lnE mnti hvo wrought y mrosF gugesD tht primitive opertors will never e pE plied to vlues of the wrong typeF roweverD eE use of wv9s prmetri polymorphismD there re P wv is fun to ompile other ontexts @suh s inside the ons funtionA in whih the types of @polymorphiA vriles re not ompletely knownF sn suh sesD the progrm lE ome of wv9s hrteristis enle ompilers to wys mnipultes vlues without inspeting their use interesting tehniques tht re pplile to few internl representtionF fut in order to mnipuE other lngugesF yn the other hndD mny spets lte them @pss them s rgumentsD store them in of the lnguge re est ttked y quite onvenE dt struturesD etFA it is neessry to know their tionl tehniquesF end there re fetures of wv sizeF he solution is to represent ll polymorphi tht might e onsidered n nnoyne @or hlE vriles y itEptterns of the sme size @eFgFD one lenge4A y ompiler writersY these re desried in wordAF hen polymorphism will workX t run timeD setion RF polymorphi vriles will e pssed from one ple to nother y mhine ode tht is olivious of its tul typeF his is extly the strtegy used in imE fety plementing vispX the ons funtion needs to know tht the size of every ojet is the smeD ut does gompilers for sfe lngugesD in whih every omE not need to know the internl representtion of the pilele progrm hs wellEdened resultD n perE ojets it is onsingF form ertin trnsformtions tht ompilers for his hs een interpreted to men tht every unsfe lnguges my notF por exmpleD if the vrileD every funtion losureD nd every rguE progrmmer nnot ess dt strutures exept ment of funtionD must e represented in extly through the oil4 opertorsD then the ompiler one wordF here the nturl representtion of is free to hoose ritrry representtions|even difE vlue does not t into one word @s with listD ferent representtions for the sme dt struture in otingEpoint numerD etFAD then pointer to dierent prts of the sme progrmF sn n unsfe hepElloted ojet is used instedF his is lngugeD the progrmmer n ess the underlyE soure of gret ineienyF ing it pttern of dt typeY this tends in prtie rmetri polymorphism is useful kind of E @nd y onventionA to fore the ompiler into preE strtionY strtion often leds to ineienyF ditle hoiesF wv progrmmers hve lwys hd to fe this enother exmple of the use of sfety is given trdeoD whih the lnguge hs resolved in fvor elow under the heding eurte ontrol depenE of strtionF fut perhps it is possile to py deneF4 issentillyD the input progrm is the repE for the strtion only where strtion is tuE resenttion of omputle progrmD nd the omE lly usedF piler my use extensionl equlity4 to sustitute vier veroy hs reently pointed out tht it ny other representtion of the sme funtionF yn is not neessry to represent every vrile in the other hndD in n unsfe lngugeD some spets one wordD just polymorphi vriles PIF he of the progrm n e represented only y n operE typeEheker n identify those ples where nonE tionl semntis speifying sequene of opertions polymorphi vlues re pssed to polymorphi vriE whose order nnot e rerrngedF lesD nd vie versF hen the ompiler n hoose
W speilized representtionsD just s lnguges of Xa pFxY the elgol fmily doD for nonpolymorphi vrilesF f@xAY henD to the extent tht n wv progrm uses nonE Xa pFxY polymorphi vriles @s sl progrm doesAD we might like to reple the sttement Xa pFxD it will e s eient s sl progrmF his whih involves fethD y Xa D whih might e ould e very signint svingsD s veroy9s meE registerEregister moveF roweverD if there is posE surements showF end it is kind of optimiztion siility tht q points to the sme reord s pD @iFeFD tht would e impossile in visp @euse the types is lisedAY or if f@xA might modify pFxD then this nnot e sfely nlyzed t ompile timeAF trnsformtion is invlidF st9s no esier to solve lising prolems in wv eprtion of stti nd dynmi seE thn in ny other lngugeF roweverD they don9t mntis need to e solved3 pethes from immutle ojets nnot possily e eted y ny store instruE sn n wv ompiler the stti semntis @type hekE tionsF end the vst mjority of ojets reted ingA nd dynmi semntis @evlutionA n e re immutle @over WW7 in vriety of rel pE evluted independently of eh otherD nd in either plitionsAF husD most fethes n e moved pst orderF sn ompilerD dynmi semntis determines stores nd proedure llsD nd ommon suexpresE the mhine ode to e genertedF sions involving fethes from immutle ojets n his my hve interesting onsequenes for the e elimintedF st is very plesnt to exploit this implementtion of seprte ompiltion filityF freedom in writing n optimizing ompilerF st should e possile to generte mhine ode for module in vuoY tht isD without knowing the types of the module9s free identiersF henD t link time wutle ells the module n e typeEhekedD sine the types sn wv the updtele prts of dt strutures @ref of free identiers then eome knownF ine ode ellsA re identied t ompile timeF his ould e genertion is muh more expensive thn type hekE useful to grge olletorF qenertionl grge ingD we might gin signint enet from this pE olletorsPRD RP segregte hepElloted reords prohF he lgorithms for in vuo seprte omE y geF feuse reords re initilized @to point piltion hve een worked out QVD nd re now to lredyEexisting reordsA when they re retedD eing implementedF newer reords usully point to older reordsF he e more mundne dvntge of the seprtion of only wy tht n older reord n point to newer stti nd dynmi semntis is tht simpleD unE reord is y n updte to the older reord fter the typed intermedite representtion n e usedY nd newer one hs een retedF qenertionl olletors the trnsltion of wv into this intermedite repE need to eiently identify ll those ells in n older resenttion need not py ttention to typesF his genertion tht hve een updted to point into somewht simplies ompilerF newer genertionF yf ourseD the representtion nlysis desried here re mny wys to keep trk of updted ove mkes the implementtion of dynmi seE ellsF e softwre pproh is to hve the ompiler mntis dependent on stti semntisF o omE generte ode fter eh ssignment sttement to piler tht uses linkEtime type hekingD or simpler keep list of ll ells updted RPF st9s not neE trnsltion to intermedite representtionD ould essry to put newlyElloted ells on this listD of not tke use representtion nlysisF ourseF o ll the ompiler needs to do is distinguish initilizing store instrutions from updting storesF smmutle reords his is esy to do in wvD s it is in visp nd ny other lnguge where reords re initilized s they e ommon prolem tht plgues optimizing ompilE re llotedF st is more diult in elgolElike lnE ers is lisingF st is often very diult to determine guges where reords re reted uninitilized nd when two pointers point to the sme thingY this inE re then stored into fterwrds to initilize themF hiits ertin kinds of optimizing trnsformtionsF en lternte pproh to updtes is to use the por exmple @in slAX virtulEmemory hrdwre of the omputer QWF fy Xa pFxY mking older genertions redEonlyD n updting qFx Xa Y store will use pge fultF his fult n e hnE Xa pFxY dled y mking the pge writeleD nd mrking ll orD similrlyD the ojets on tht pge s possily updtedF hen
IH future updtes to the sme ojetD or to nery oE mhineF he pttern uXXv ensures tht q is ons jetsD will not inur the ost of fultF ellF sn se @A it is lerly permissile to hoist the he pgeEsed tehnique will work est if there fethD sine the vlidity of the pointer q nnot e is lolity of referene mong the updtesF st would eted y the vlue of iF e estD for exmpleD to put ll the mutle ojets fut in exmple @A we nnot tell nything out lose to eh other on smll set of pgesD so tht the reltionship etween j nd pF he progrmmer fewer updting pge fults ourF his is possile if might know tht j is the length of the linked list the runtime system n guess whih ojets n e pD so tht the feth nnot e hoistedY or the vlue or will e updtedF portuntelyD in wv the ref ells of j ould e unrelted to whether p is nilD so the n e distinguished from immutle reordsD dt feth n e hoistedF wv provides more preise inE onstrutorsD nd losuresD s they re retedF he formtion to the ompiler thn g does out the ompiler n mrk ref ells s they re llotedD true ontrolEdependenes of fethesF or llote them in dierent re of memoryD nd sn summryD the sfety of the lnguge gives us the runtime system n rely on this mrkingF uh tool for resoning urtely out ontrol depenE tehnique is not possile in vispD sine ny oE deniesF jet n in priniple e updted @even though few ojets re tully updted in prtieAF st is interesting to ompre wv @whih llows xo pointer equlity progrmmers to exeute updting side eetsA with ointers in wv nnot e tested for identityF ht lzy funtionl lnguges suh s rskell IRD from isD exept for ref ellsD the progrm nnot deterE the grge olletor9s point of viewF ine genE mine if two similr ojets re loted t the sme ertionl grge olletors hte updtes to exE ddressF ine nonEreferene ojets nnot e upE isting ojetsD it would seem t rst glne tht dtedD the progrm nnot even perform the exE purely funtionl lnguge with no ssignment periment of modifying one ojet nd seeing if the sttement would e esier to grgeEolletF fut other hngesF his unusul feture leds to severl lzy lnguges re onstntly updting lzy losures interesting onsequenesF @thunks4A with the results of evluting themF gompilers n perform ommon suexpression rdoxillyD from olletor9s viewpoint wv hs elimintion on reord expressionsF ht isD in the mny fewer ssignments thn rskellD nd grge progrm olletion in wv is likely to e more eientF vl t a @DA eurte ontrol dependene vl s a f@xA vl u a @DA e sttement gurded y onditionl is sid to e the lst line n e implemented s vl u a t y ontrol dependent on the onditionlF roweverD this the ompilerF his trnsformtion would not work denition n e rened for sfe lnguges suh s in vispD slD or lmost ny other lnguge eE wvF use the progrm would e le to test whether u gonsider these two wv frgments nd g frgE nd t pointed to the sme ddressF mentX gompilers nd grgeEolletors n do hshE A if ibH then se q of uXXv ab u onsingF4 ht isD if the reord @DA is to e reE | nil ab FFF tedD nd similr reord lredy exists @nd n e else FFF found using speil hsh tleAD then pointer to the existing reord is used insted of mking new A se q of uXXv ab if ibH then u oneF sn systems tht llow ddress omprisonsD else FFF hshEonsing would entil n oservle semnti | nil ab FFF hnge to the progrmY in wv it would notF xowD hshEonsing my e intolerly slowF fut onsider A if @ibHA if @jbHA s a pEblinkY vrition in whih genertionl grge olletor sn eh se there is feth gurded y two ondiE does hshEmerging of ojets tht survive into the tionlsF he ompiler might wish to hoist the feth seond genertionF hen it9s only neessry to hsh ove the inner onditionlD perhps to improve inE very smll perentge of the ojets tht get lloE strution sheduling or register llotionF ted @sine only few ojets survive grge sn se @A this is impermissileD sine q might e olletionAF his ide hs een implemented y nil| feth from nil might e illegl on the trget wrelo qon$lves t rineton niversityF
II qrge olletors like to move n ojet from registers to invoke new thred|re ll netly enE one ple to notherY ut then they need to updte psulted in the ontinution mehnismF ll the pointers to the ojetF e onurrent grge hred sheduling is muh more eient when olletor might hve troule nding ll these pointE done in the lient proessD without requiring ers quiklyF sn tht seD it might e desirele to hrdwreE nd opertingEsystem ontext swithes hve two usle opies of the ojet|old nd new| when synhronizing or interleving thred exeuE until ll the pointers n e forwrded4 QQF tionsF eent opertingEsystem reserh P hs histriuted systems n opy ojets without shown how to let the operting system shedule proE worrying out identityF uppose we wnt to mke essors while the lient progrms mnge proesses the distriuted nture of system trnsprent to to tke dvntge of the eieny of userEmode the progrmmerF sf severl proessors wnt to look shedulersF sn wv extended with rstElss ontinE t dt struture t the sme timeD to otin dE utionsD the sheduler n e soureElnguge proE equte performne it is neessry to opy piees grm tht mnipultes ontinutions diretlyF his of the dt struture onto the dierent proessorsF pproh is very elegnt nd roustD nd hs proved ith onventionl progrmming lnguge we now suessful in gonurrent wv QS nd wvEhreds hve to worry out ddress identity nd mkE WD two quite dierent onurrent progrmming enE ing updtes visile to ll the proessorsF hese vironments for wvF prolems re usully solved in hrdwre @eFgFD with snoopy hesAF sn wvD worries out updtes disE pper for ll ut referene vluesD whih re rre Q wv trps nd pitflls enough tht onventionl synhroniztion nd mesE sge pssing would e dequtely eientF he syntti nd semnti pitflls tht n wv proE grmmer enounters re muh less severe nd less numerous thn those desried in lnguges suh s he module system g PHD whih is n egregious exmpleF
unEtime spets of the module system turn out to e very simple SF e struture tht exports n wisspelled onstrutors types nd m vlues n e implemented s n orE e wellEknown nd most dngerous pitfll witing dinry mEtuple @types re needed only t ompile the wv progrmmer is the misspelling of onstnt timeAF puntors n e implemented s funtions dt onstrutor in ptternF feuse there is no tht tke strutures @tuplesA s rguments nd reE syntti distintion etween onstrutors nd vriE turn strutures s resultsF ine ll interEmodule lesD ny identier delred s onstrutor is unE linkge n e expressed this wyD onventionl derstood y the ompiler s onstrutorD nd ny linkEloder is not even neessry|whih is prtiE other identier is interpreted s vrile @whih ulrly onvenient in n intertive system tht n mthes nythingAF husD misspelled onstrutor lod nd exeute progrms nd modules on the yF looks like vrileD nd is epted y the omE pilerF por exmpleD the misspelling of nil in this implementtion of length uses the funtion lE pirstElss ontinutions wys to return zeroX e very interesting nd powerful feture of fun length @nillA a H hemeQR is the llEwithEurrentEontinution | length @hedXXrestA a I C length rest mehnismD wherey the dynmi lling ontext sn mny ses @s in this oneAD the ptternEmth of funtion n e strted s nother funE will hve redundnt rules s result of the progrmE tionF tndrd wv does not hve suh rstElss mer9s mistkeF ine the ompiler wrns out reE ontinutionsY ut it turns out tht they n esily dundnt rulesD perhps the error n e deteted e introduedD nd they t very niely into the wv tht wyF fut not in ll sesF end wrning mesE type systemIIF sges re esily ignored y the progrmmerF pirstElss ontinutions mke it esy to impleE he pproh rolog tkes to solve the sme ment oroutinesD or their generliztionD lightweight prolem is to mke onstrutors synttilly difE proesses RSF vowElevel detils tht must ordinrE ferent from vrilesX rolog onstrutors egin ily e onfronted in suh implementtions|suh s with lowerEseD vriles with upperEseF he the llotion of new tivtion stksD the grgeE sme solution would not quite work in wvD for two olletor interfeD nd the mehnisms for sving resonsX wv llows symoli4 identiers suh s
IP XX nd C tht don9t egin with letter @nd for fut it9s frequent nnoyneY when writing proE whih n upperGlowerEse rule wouldn9t pplyAY grm on the integers s m just not thinking out nd wv llows dtEonstrutors to e thinned4 rel numersD nd s m onstntly surprised to see to identillyEnmed vlue indings t module inE the overlodingEresolution filuresF end in tehE terfesD so tht wht is seen s onstrutor in ing the lngugeD s must lwys qulify sttements one module is seen s funtion @vrileA in nE suh s he wv type inferene lgorithm n lE other moduleF hese re oth smll thingsY they re wys derive mostEgenerl type for ny expression4 ute ut minimlly usefulD nd progrmmers ould with tehnilities out hlfEdozen uiltEin operE esily work round their seneF torsF ome vrition of the rolog pproh would yne wy to solve this prolem is to llow runEtime solve this prolem without signintly ltering the resolution of overlodingD s in the lnguge rskell nture of tndrd wvF he rskell lnguge IR RRD IS nd in other extensions of typed lmd uses suh n pprohF lulus IVF sn these lngugesD lss opertors re pssed @t runtimeA s impliit extr rguments to funtions tht tke polymorphi overloded types yverloding s rgumentsF wost lnguges support some kind of overloding of fut this mehnism mkes dynmi semntis opertorsD lso known s d ho polymorphismF sn dependent on stti semntisD whih preludes erE its simplest formD this mens tht n opertor suh tin kinds of seprte ompiltion shemesF end s C n e pplied to integer rguments @yielding rskell uses rther hevyweight mehnism for n integer resultA or to rel rguments @yielding n pprently smll ginF efter llD mking do with rel resultAF his is not the sme s the prmetri nonEoverloded identiers wouldn9t mke progrms polymorphism of wv or visp funtions suh s ons ny igger|one would just hve to mke up dierE or mpX he lgorithm used to implement C is difE ent nmes for dierent opertionsF ferent for integers nd relsD ut the implementtion s m often sked whether s seriously men tht of ons is the sme for ll typesF oting point ddition should not e represented vnguges of the elgol nd fgv fmilies hve y the C symolF ht is extly wht s menX lwys hd overloded opertors uilt inD with overE tndrd wv provides only hlfEdozen overloded loding resolution @the determintion of rgument opertors nywyD nd the use of C or some suh typesD nd therefore of wht implementtion funE dmittedly ugly symol would e resonle prie tion to useA t ompileEtimeF vnguges of the to py for the deletion of overloding from the lnE mthemtil4 fmily hve typilly hd overlodE gugeF he designers of tndrd wv onsidered ing resolution t runEtimeF the prolem refully nd me to the opposite everl lnguges in ll three fmilies hve lE onlusion|so it must e mtter of tsteF lowed progrmmers to dene new overloded idenE tiersD nd to speify the implementtion funtion ek type vriles to use for eh rgument typeF yjetEoriented lnE gugesD espeillyD hve sophistited support for he wv type systemD nd type inferene lgorithmD userEdened overlodingF works very eetively on progrms without side efE gompileEtime overloding resolution nd wvE fetsF rtiulrly importnt is tht the types re style polymorphi type inferene do not work well intuitiveX4 the inferred types seem very nturl together IHF sn proessing funtion denition nd ovious to most progrmmers in most sesF suh s st hs long een known tht this lgorithm does not work for polymorphi referenesF o illustrte fun doule@xA a xCx with n oftEused exmpleD onsider it is impossile to know t ompileEtime whether let vl f a fn xabx in f IY f true end C is to e implemented s integer or otingEpoint he funtion f hs the type VX 3 D nd n dditionF orretly e pplied to n int nd oolF his is not dngerous trp4 for the progrmE fut let f e referene to polymorphi funtion merD sine ny miguous funtion suh s doule nd the type inferene lgorithm nnot e nively will e ught t ompileEtime s typeEheking ppliedF st seems nturl to give polymorphi types errorY the progrmmer will x the prolem @preE to the refD XaD nd 3 opertorsX sumlyA y inserting type onstrintD eFgF fun doule @xX relA a xCx ref X VX 3 @ ref A
IQ Xa X VX @ ref A 3 unit whih is given list of pirsY the rst element of 3 X VX ref 3 eh pir is n integer key nd the seond element is of ritrry type @thoughD of ourseD the sme type xow try to typeEhek the expression for eh element of the listAF he sort funtion returns the list sorted y keyF st is esy to write let vl f a ref@fn xabxA purely funtionl quiksort or merge sort to solve in f Xa @fn xabxCIAY this prolem eientlyF @3fA true fut suppose one expets ll the integers to e in end the rnge I{IHHHD nd the list ontin thousnds sf f hd type VX @@ 3 Aref AD then the progrm of elementsF hen uket sort is fsterD using n would @inppropritelyA typeEhekD nd would go rry of IHHH elementsF fut even though the rry wrong4 t run time y inrementing oolenF o is not returned from sortD or retined wy fter the nive polymorphi type heker hs proved inE sort returnsD the type of this uketEsort progrm dequte to hndle referene ellsF e more pproE would now e prite type for f might e @VX 3 Aref AD with the sortX @int B 9A list Eb @int B 9A list quntier nested inside the ref onstrutorY ut the inditing tht the nonEkey elements of the list nE wv type inferene system nnot ope with inner4 not e polymorphi vluesF st is too d tht this quntiersF purely internl dt struture must e mentioned4 grdelli9s wv ompiler UD nd the initil proE in the interfeF posl for tndrd wv PWD required tht referene wny reserhers hve reently een engged in ells e ompletely monomorphiY tht isD the omE devising etter type inferene systems for polymorE piler must e le to infer type without type vriE phi progrms with referenesPSD PQD IUD RHD RVD les for ny rgument of the ref onstrutorF his whih indites tht the prolem of typeEheking is ertinly sfeD ut insuiently exileF ofteRI referenes is not yet regrded s solvedY4 some of generlized this ideD introduing wekly polymorE these systems ddress the prolem of internlD temE phi4 referenes nd impertive typesF4 hese lE porry referenes desried oveF low funtion tht retes referenes to e pplied to more thn one typeD s long s eh suh type is itself monomorphiF ofte9s impertive types re he wv qrmmr sustntil improvementD nd mke for usle he designers of tndrd wv worked very hrd lngugeY they hve een dopted s prt of the to get the semntis rightD nd to dene the seE tndrd wv henitionF mntis s ompletely nd s formlly s possileF roweverD ofte9s sheme n e mde more exiE nfortuntelyD the sme ttention ws not pid to leF sn prtiulrD it does not seem to work very ntE syntxF hirty yers fter elgolD nd fteen yers urlly with higherEorder funtionsY urrying funE fter D he henition of tndrd wv does not tion of impertive type n led to funtion tht ontin n unmiguous ontextEfree grmmr for is rejeted y ofte9s lgorithmF wueen solved the syntx of the lngugeF this prolem y ssigning numeril wekness inE es presentedD the grmmr is miguous for two dies to the type vrilesPUF wueen9s sheme resonsX he prser must guess4 whether n idenE is stritly more powerful thn ofte9sD nd hs een tier in pttern is vrile or onstrutorY nd implemented in tndrd wv of xew terseyF it must guess4 whether n identier is dened s roweverD wueen9s wek types ren9t very infixD nd if soD t wht preedene nd ssoiE esy for progrmmers to understndF st9s diult tivityF for the uninitited to infer types for funtions tht hese prolems re not very diult to solve seE mke ref ellsY typilly s write the expression nd mntillyF por exmpleD one might think the exE get the ompiler to print out the typeD whih s n pression d e f hs to e prsed very dierE then use in writing module signturesD etF his ently if is n inx opertor thn if isF he soluE pproh to interfe design is the opposite of tht tion is to prse suh n expression s sequene of usully reommended3 tomsD nd implement simple preedene prser he most nnoying thing out ofte9s nd @QU lines of ode in wvGxtA s semnti tion4 wueen9s impertive types is the visiility4 for inx opertorsF of lollyEused referenes in interfe desriptionsF o the prolem is not tht wv hs no ontextEfree gonsider funtion grmmrY it9s tht the grmmr is not lerly speE sortX @int B 9A list Eb @int B 9A list ied in the henitionF yne immeditely runs into
IR prolems when one wnts to implement prser olons optionl fter delrtionsF husD the delE for wvF e good lnguge denition should inlude rtion omplete v@IA grmmr with no redueGredue vl a SY onits nd s few shiftGredue onits s posE vl a TY sileF iven if the implementor intends to prse would hve the sme mening without the using dierent strtegy @eFgFD vv@IA or reursive semiolonsFIH desentAD the v@IA grmmr is useful strting his is good thingY s9d rther not hve semiE pointF he tndrd wv of xew tersey implemenE olons luttering up my progrms @my prose is nE ttion T uses suh grmmr @with TV terminlsD other mtterAF fut it turns out tht etween UT nonterminlsD PQI produtionsD RSP vev@IA struture delrtion nd funtor delrtion sttesAF semiolon is required @though not etween two wost lnguges hve shiftGredue onit with struture delrtions or two funtorsAF he elseF sn the expression only pprent reson for this disrepny is tht if e then if f then g else h the syntx of module delrtions ws not refully it9s not ler whether the else is supposed to mth thought outF the rst then or the seondF his is ustomrily pinllyD s will remrk tht s hve herd from resolved y sying tht the innermost @in this seD mny dierent people tht they nd wv syntx the seondA then is mthedY tht isD n v prser onfusingD uglyD nd diult to lernF es longE should resolve the onit y shiftingF time wv progrmmerD s m quite omfortle with wv leverly voids this prolem y requiring tht wv syntxY ut perhps the frequeny of these omE every if hve oth then nd n else luseF fut plints might serve s hint tht there is n opporE similr prolem ours in se expressionsX tunity for syntx designer of rre tste nd geniusF se e of ab se f snx opertors of ab g | ab h rogrmmers my dene new inx opertors in xowD is the pttern prt of se e or se fc tndrd wvD nd my give them preedene he henition sys tht it9s the ltterY nd this @etween H nd WD where higher numer indiE orresponds to resolving shiftGredue onit in tes tighter indingA nd left or right ssoitivityF fvor of the shiftF his is the only shiftGredue onE sf the progrmmer wnts to dene n exponentiE it in the tndrd wv of xew tersey grmmrF tion opertor BB nd mke it rightEssoitive nd rogrmmers hve grown ustomed to the eE tighterEinding thn multiplitionD the delrtion hvior of ifEthenEelseF fut s n wv progrmE infixr V BB works quite wellF mer s often fll into the se trpX s often write he henition sttes ptternEmthes like the one oveF he solution is to enlose the inner se expression in prenthesesD infix nd infixr ditte left nd right ut s would rther the prolem didn9t our in the ssoitivity respetivelyY ssoition is lE rst pleF wys to the left for dierent opertors of hese extr prentheses re uglyF sn ftD hving the sme preedeneF shiftGredue onit in the grmmr is uglyF e his is not s good rule s it ould eF gonsider etter solution might e to require tht se nd the listElike dttype fn expressions end with endD so the exmple ove dttype 9 listP a xsv would e writtenX | 66 of 9 B 9 listP se e | 88 of 9 B 9 listP of ab se f infixr S 66 88 of ab g rere there re two vors of ons ellsF hen the end expression | ab h end I 66 P 66 Q 88 R 66 xsv xow there is no miguityF st isD howeverD mtter is intended to e listP4 of integersD some of whih of tste whether the end is uglier thn the extr re mrked with 66 nd others with 88D just s prenthesesF IXXPXXQXXRXXnil is n ordinry list of integersF here re some other syntti glithesF st ws IHhe wv top level4 @redEevlEprint loopA dds some lerly the intent of the designers to mke semiE twists of its ownY these re disussed elsewhere in the pperF
IS sn oth sesD the ons opertors @XXD 66D 88A re ll delrtions impliitly introdued y openD not ment to ssoite to the rightF fut the wv hefE just xity delrtionsF he semntis @iFeFD typeD inition requires tht the listP4 expression ove vlueD etFA of n opertor n9t e determined lexE should ssoite to the left euse dierent operE illy euse of the use of openY the progrmmer tors of the sme preedene re usedF erhps who n prse the opertors ut doesn9t know wht the henition ment4 to sy tht opertors of they do is lmost s dly o s the one who isn9t the sme preedene ut opposite ssoitivity ssoE sure out opertor preedeneF ite to the leftF4 fut n even etter rule would e he henition QID pge IH sttes tht tht leftE nd rightEssoitive opertors of the sme more lierl sheme @whih is under onsidertionA4 preedene don9t mix without prenthesesY this is would llow inx spes in signturesD nd then n the rule in rskell IRF open delrtion would reEinstll xities of operE torsF uh sheme hs een implemented in tnE snx vsF wodules drd wv of xew terseyTD nd is quite onvenient to useF snx delrtions re not exported from modulesD nd nnot e speied in signturesF his mkes them signintly less usefulF por exmpleD if one implements module etor eprte ompiltion to implement rndomEessD integerEkeyed tlesD one might wnt signture like he wv lnguge denition is purposely quite signture igy a vgue out the prgmtis of putting progrms toE sig type 9 vetor getherF he henition hooses to pretend tht ll vl vetorX 9 list Eb 9 vetor progrms re typed into n intertive top level4 vl suX 9 vetor B int Eb 9 redEevlEprint loopD nd vguely lludes to the ft end tht progrms might e ompiled from lesFII struture etorX igy a F F F his is resonleX there is nothing wrong with yne might then wnt to mke su n inx opertorD dening progrmming lnguge in the strtD so tht expressions like su i ould e used for without tying it to the onrete detils of operting getting the ith element of vetorF systems nd le systemsF st is fr etter to unE o use vetors in nother module fD one ould derspeify this spet of lnguge thn to get it refer to the vetorEretion funtion etorFvetor wrongF nd the susript funtion etorFsuF fut it is roweverD modern lnguges with module filE more onvenient to write open etor inside fD so ities @inluding gD wodulD edA usully speify tht vetor nd su n e used without prex quite lerly whih prts of progrm n e omE within fF piled seprtely from the rest of the progrmX in gD roweverD one nnot write infix su in the sigE F le generlly requires some Fh les for omE nture igyY within f the su opertor won9t e piltionD ut not other F lesIWY the wodulEP inx unless there is seprte infix su delrE denitionRU is even more spei out the orgE tion in fF niztion of ompiltion unitsF he ide ehind the module system is tht n ritrry piee of stti environment n e enE ine wv hs rther elorte module systemD psultedY4 then open will reonstitute tht enE it would seem tht eh module should e sepE vironment in nother sopeF fy prohiiting this rtely ompilele unitF fut this is not neessrily enpsultion of the xity4 portion of the stti the seY strutures with free struture identiers environmentD the henition mkes infix delrE do not suiently speify wht they re importE tions seondElssF ingF he gommentry suggests some @severeA reE he only good rgument ginst llowing open stritions on the module system tht would llow to reonstitute xity delrtions is tht it might seprte ompiltionF fut on the wholeD the relE mke progrms hrd to understndY the interpreE tionship etween struturesD modulesD nd seprte ttion @iFeFD xityA of n opertor nnot e underE ompiltion ould use some further workF stood y looking lexilly upwrds in the text of the progrm for delrtion of tht identierD euse IIsn ftD most implementtions hve funtion lled use one might not notie the open of module identiE tht llows les to e ompiledY ut they disgree on the er @eFgFD etorAF fut this rgument pplies to semntis of nested usesF
IT estrt strutures open in signtures hen struture denition in wv is onstrined st is ustomryD in writing modulr softwreD to y signtureD the representtions of types re not speify the interfes etween modules nd to imE hiddenY they show throughF4 husD the delrtion plement the modules to meet those interfesF iven of module implementing omplex numersD when the progrmmer develops the implementtion signture gywvi a rstD it is good prtie to pretend otherwise y sig type omplex writing the interfe signture nd lening up the vl B X omplexBomplex Eb omplex implementtion s neessry to meet the signtureF end hen the reder of the progrm n rst underE stnd the interfes @whih re generlly more onE struture gomplex X gywvi a ise thn the implementtionsAD nd then proeed to strut lern out the implementtion of one module t type omplex a rel B rel timeF he signtures of the tndrd wv module vl op B a fn @@rIDthetIAXomplexD system support the writing of ler interfe speiE @rPDthetPAXomplexA ab tionsF @rIBrPD thetICthetPA xow imgine n interfe denition tht sysD end in eetD the signture is dened to e whtE does not hide the ft tht the polr representtion ever interfe hppens to e met y the implemenE is usedX struture delrtionsD even when onE ttion module wF4 hen to understnd D one strined y signturesD llow type nd shring inE must red through the entire implementtion wD formtion to show through4 the onstrintF yther inferring types for ll the vluesD keeping trk of modules tht mke use of the gomplex struture whih identiers re visile in the outermost sopeF will e le to ess the omponents of omplex e rightEthinking softwre engineer should ertinly numerD unless they import gomplex s the prmE frown t suh method of dening interfesF eter of funtorF s hve found tht most people fut this is extly wht is provided y open spes lerning wv re surprised y thisD euse the sigE in signtures3 he signture nture delrtion itself mkes no mention of the signture a sig open w end representtionF speies tht the interfe is just whtever sn some ses the trnspreny of signtures is @lrgestA interfe is otined y elorting the neessry nd usefulY ut in mny ses it would struture wF e useful to use the module system to implement he open spe my e plesingly symmetril strt dt typesF wueen9s originl module to the theoretiinY it my e tehnilly useful in proposlPT provided for strtionD speil dening the semntis of the rest of the module sysE kind of struture delrtion in whih ll type repE temF fut it hs no ple in rel progrmming resenttion nd shring informtion not speied lngugeFIP in the signture onstrint would e hiddenF qivE e relted prolem hs to do with overlpE ing progrmmers the hoie etween struture nd ping open @or inludeA spesF ine open w or strtion would etter support progrmming inlude hs the eet of inluding mny identiE with strt dt typesF estrt dttypes with ersD it is esy for the progrmmer to indvertntly hidden representtions re the pple pie nd mothE @or even purposefullyA inlude two dierent signE erhood of modern softwre engineeringD nd rightly tures ontining the sme typeD vlueD or struture soF identierF hough there is no miguity in the seE yf ourseD there exist other mehnisms for mntis @the lter spe tkes preedeneAD multiple strt dt types in tndrd wv @stype denitions mke the sope of spes muh more omE nd funtorAF fut it is prtiulrly onvenient plited to followD nd mke the implementtion of to use strt dt types t the module levelD semnti nlysis for signtures nd shring muh where strtion is more strightforwrd thn more diultF stypeF end funtors n e lumsy mehnism he sope rules for wv expressionsD while simE for struturing progrmsF pleD re not ompletely trivilY nd tht is ppropriE he gommentry to the denition shows tht teX progrms re omplited thingsF fut it seems strtion is not semntilly prolemtil QHD IP pge VSD nd even gives useful generliztion of e shring onstrint n lso relte signture interfe to free strutureF fut this is not so prolemtil for the wueen9s proposlF st9s pity tht this feture reder of the progrmD sine it hs no eet on the visiility ws omitted from the henitionF of nmesF
IU worthwhile to strive for extreme simpliity in interE stti @lexilA sopeD sttillyEheked modulesF fe @signtureA denitionsX sope rules for signE roweverD some spets of the lnguge design re tures should e trivilF e ler understnding of the hrd to ompile eientlyF interfes of progrm is prerequisite to underE stnding the progrmF emoving openD lolD nd olymorphi equlity inlude spesIQ from tndrd wv would result in muh lener interfesD without using gret inE wv hs n opertor a to test the equlity of two onvenieneF vlues @whih must hve the sme typeAF lues of yne of the rguments for inlude is tht it helps ny of the primive types @integerD relD stringD etFA in writing onisely signture for modules tht my e tested for equlityD ut vlues of funtion stisfy severl dierent speitionsF gonsider type my notF estrt typesD of whih the proE signture rer of hshle vluesD nd signture grmmer hs purposely hidden the representtionD qy for mthemtil group struturesX lso do not dmit equlityY4 they re not equlity signture rer a typesF4 sig type vlue eny vlues of reord type or dttype uilt only vl hsh X vlue Eb int from equlity types4 my e ompred for equlE end ityF iqulity of reordsD listsD nd so on is struturlX the reord @xIY yIA is equl to @xPY yPA if xI a xP nd signture qy a yI a yPY there is no wy to tell if the two reords sig type elem re t the sme ddressF vl id X elem his is ll very wellD ut now there is ompliE vl B X elem B elem Eb elem tionF gonsider the progrm vl inverseX elem Eb elem fun lleq@DDA a a ndlso a end row n these e omined to mke signture for vl t a lleq@QDQDQA hshle groupsc ith inludeD one ould write signture rerqy a vl x a lleq@fn xabxCID @B svviqev3 BA sig inlude rer fn xabICxD inlude qy fn xabxCIA shring type vlue a elem he funtion lleq should hve type resemling end VX 3 oolD so tht we n pss three fut sustrutures serve lmost s oniselyD withE integers to itD or three stringsD or three lists of rel out using inludeX numersF fut we nnot pss ny vlues of type signture rerqy a @suh s int 3 intA tht does not dmit equlityY sig struture rX rer thus the lst delrtion must e illeglF @efter llD struture qX qy to tell whether two funtions re equl4 the omE shring type rFvlue a qFelem piler must e le to tell whether they give the sme end results on ll inputsD whih is rther diultFA sn ftD the ltter pproh is more roustD sine sn tndrd wv the prolem is resolved y introE unfortunte nming oinidenes etween the two duing equlity type vrilesD4 whih n e inE signtures n e distinguished y qulied idenE stntited only y types tht dmit equlityF husD tiers @imgine tht the rer signture lso hd the type of lleq is something like n identity funtion idX vlueEbvlueAF he only disdvntge is tht the lient of rerqy must Va X a a a 3 ool either open q nd rD or use qulied identiers suh s qFid insted of idF where we n sustitute int for aD ut not int 3 intF sn n @egssA wv progrmD equlity type vriE les re written strting with two postrophes inE R rolems in ompiling wv sted of just oneF his seems like lever solutionD ut it introdues wv is designed to e ompiledX mny things n e three kinds of prolems into the wv lngugeX evluted t ompile timeF wv hs stti typesD
IQs m not proposing to remove open delrtions from IF he stti semntis of the lnguge eome expressionsD just open spes from signturesF very omplitedY
IV PF ode genertion nd the runtime system reE neessry for ordinry exeutionF he rgument is quire unplesnt speil sesY often mde tht these tgs re there to llow the grge olletor to trverse pointers nd reordsF QF nd perhps progrmming with equlity types fut it9s possile to devise grge olletor tht isn9t good ide nyhowF relies on the stti type informtion omputed t tti semntisX xow the lnguge designE ompile time QD without ny runtime tgs on dtF ers must worry out type onstrutors tht dE purthermoreD even onventionl grge olletor mit equlityD spes in signtures of types tht dE might use fsfy @fig fg of gesA sheme tht mit equlityD propgtion of the equlity property groups mny ojets of similr type on the sme through shring onstrints nd funtorsD nd so pgeD so tht one tg sues for ll of themF hen onF sn he henition of tndrd wvD no fewer the runtime equlity interpreter4 fes very omE thn twentyEtwo pges mention some syntti or plex tsk in understnding the struture of ojetsF semnti spet of equlity typesY this is pproxiE es to the provision of impliit rguments to funE mtely one out of every four pges of the heniE tionsD this is workle ut inelegntF es the gomE tionF he rmitions of equlity similrly metsE mentry on tndrd wv sttesD the stti nd tsize throughout tndrd wv ompilerF iqulE dynmi semntis n e studied independently of ity types dd signint omplexity to the lnguge one notherF4 QHD prefe sn struturing omE nd its implementtionF pilerD it is very onvenient tht trnsltion of exE hynmi semntisX sn lmost every respet pressions into mhine lnguge is independent of the type heking of n wv progrm is distint from the types of the expressionsF equiring tht some the evlution of the progrmF husD type heking expressions must e treted speilly depending on n e done t ompile timeD nd type tgs need their types orrupts the interfe etween the omE not e rried on runtime ojetsF his sves onE ponents of the ompilerF siderle spe nd timeD nd is one of the most rogrmming with equlity typesX en oftE importnt fetures of the lngugeF used exmple of the utility of equlity types is the fut funtion @suh s lleqD oveA must e implementtion of sets @with unionD intersetionD le to test vriles for equlityD even though etFA s listsF husD the type of these vriles is polymorphi nd not fun set@xA a xXXnil known until run timeF here re two wys tht this fun memer@xD nilA a flse might e omplishedX | memer@xD XXrA a xa orelse IF he runtime representtion of eh ojet n memer@xDrA hve suient tg informtion to determine fun union@XXrDA a whether the ojet is pointerD nd if soD how if memer@DA mny elds re in the pointedEto reordD nd then union@rDA whether the reord is ref ellF hen n else XXunion@rDA equlity interpreter4 n reursively trverse | union@nilDA a dt strutures to test itwise equlity on nonE hen these funtions n e used to mke sets pointersD nd struturl equlity on pointersF s whose elements re ny type D s long s dE elieve this is the solution hosen in ll existing mits equlity @iFeFD doesn9t ontin omponents of wv ompilersF funtionl or strt typeAF end the progrmmer doesn9t even hve to provide n expliit equlity PF he representtion of ny forml prmeter funtion|the ompiler gures it ll outF whose type is polymorphi equlity type vriE le ould e pirD whose rst eld is the fut there re two very signint prolems with vlue itself nd whose seond eld is funE this progrmD nd these prolems re suiently tion for testing equlity on vlues of tht typeF generl tht they my et ny progrm tht hen funtion suh s lleq ould use these mkes muh use of equlity type vrilesF pirstD impliit prmeters to perform equlity testE the set union funtion tkes qudrti timeF eny ingF his is the solution dopted in rskellRRD relisti progrm tht dels with sets will wnt to whih generlizes the notion of equlity types mke set union tke liner timeY nd this n only to inlude other kinds of overlodingF e done if there is some sort of ordering @lessEthnA omprison opertor ville on the elementsD or here re disdvntges to either solutionF he some wy to hsh the elements to integer vluesF rst requires runtime tgs whih re otherwise not husD prodution qulity4 set strtion will e
IW prmeterised y more thn just n equlity funE vlue must e the sme size|one word in typil tionF implementtionAF eondD onsider wht hppens with sets of setsF his shemeD if pplied to dttype like listD es n exmpleD would require tht the representtion of XX e vl a union@set@IADset@PAA pointer to twoEelement reord ontining onE vl a union@set@PADset@IAA strutor nd vlueY the vlue would e pointer vl x a set@A to nother pir ontining nd F ih element of vl t a memer@DxA the listD thenD requires not one ons ell4 ut two3 he set x hs single element tht is the set fIY PgY grdelli9s wv ompilerU voided this extrvE the lst line tests the set fPY Ig for memershipF gne y tking dvntge of the ft tht in the yf ourseD the progrm will tell us tht TP fgD runtime representtion of vluesD pointers ould e whih violtes the set strtionF he prolem distinguished from smll integersF husD the omE is tht struturl equlity is the wrong equlity to piled ode ould tell whih onstrutor @nil or XXA use on setsY the progrmmer should relly provide hd een pplied y seeing if the vlue ws smll n eqset funtion tht tests whether two sets hve integer @nilA or pointer @XXAF he pointer would the sme elementsF then point diretly t reord ontining nd F husD impliit struturl equlity is often d hus the representtion of lists in grdelli9s omE progrmming prtieF he progrmmer should piler @nd in every susequent wv ompilerA is just provide n expliit equlity funtion euse @IA the like the representtion used in vispF expliit funtion will likely e more eient to useD sn ftD ll these ompilers generlize the ide nd @PA the expliit funtion will hve the right seE slightlyX in ny dttype with just one nonEonstnt mntis for the pplitionF onstrutor @nd ny numer of onstnt onstruE e resonle ompromise would e to llow torsAD if the nonEonstnt onstrutor rries vlue kind of sttilly overloded equlity funtionD of tht is lwys represented y pointerD then n exE the kind found in erlier versions of tndrd wv tr indiretion to rry the onstrutor is not neE PWF his equlity opertor worked on ny nonE essryF funtionl monomorphi typeF uh n opertor is xowD onsider the following perfetly legl tnE quite onvenient to the progrmmerD nd does not drd wv progrmX unduly omplite the lnguge semntisD omE funtor p@type 9 t pilerD or runtime systemF @rlf s mny pges of IR dttype 9 list a the henition would mention equlityY equlity nil | XX of 9 t ttriutes would ese to intert with the type A a strut F F F endY heker or the module systemY no equlity interE preter4 would e needed in the runtime systemFA st struture a must e dmitted tht with this solution @s with p@dttype 9 list a wv overlodingA we re left without prinipl types nil | XX of 9 B 9 list in some sesF type 9 t a 9 B 9 list AY httype representtions sn ompiling the funtor p D the ompiler does not eursive dt types re delred in wv using know whether the representtion of 9 t is lwys dttypeD whih denes the onstrutors @nd sE pointerY so n expliit indiretion @ reord for the soited typesA of disjoint union typeF vinked lists onstrutorA must e used in the representtion of re just speil se of this more generl notionF listF he runtime representtion of typil dttype fut in ompiling the struture D the tul pE element onsists of onstrutor nd n ssoited rmeter hs dttype list in whih the vlue rE vlueF e strightforwrd implementtion of this ried y XX is reordD nd thus lwys pointerF representtion would e s twoEelement reordD o the representtion hosen y the ompiler will with one eld ontining smll integer tg @stndE use grdelli9s optimiztionF ing for the onstrutorA nd the other ontining hen when lists reted outside of p re pssed the vlue @sine wv hs polymorphi typesD every to funtions inside p D the progrm will go wrongX dierent ompiltion units will disgree out the IRges RD IVD IWD PID PPD PSD PTD URD USD UUD UW of the henitionQI would still mention equlityY pges IQD ITD QQD representtion of listsF QSD QTD QWD RHD RID RQD RRD SU would no longer need toF husD tndrd wv does not permit grdelli9s
PH optimiztionYIS ut ll the implementtions use it he initil sis euse the lterntive is too expensiveF he henition speies n initil sisD tht isD set he prolem is it more generlF here re of predened typesD vluesD nd exeptions tht re mny other possile generliztions of grdelli9s the uiltEin funtions4 @etFA of ny wv systemF tehniqueD ll with the im of mking the repE hese inlude the rithmeti opertors on integers resenttions of dttypes more ompt nd eE nd relsD string ontentionD few opertors on ientF xone of these tehniques work ross funtor listsD nd so onF oundriesF he initil sis is not lrge enough to write rel grdelli9s tehnique is vrint of the ideD progrms tht use nontrivil inputGoutputD or tht py for strtion only where things re strtF intert muh with the operting systemF ht9s veroy9s representtion nlysis pplies to funtionsY perfetly eptleY this is lnguge denitionD grdelli9s to dt struturesF fut it ppers tht not lirry moduleF he type nd module systems this ide nnot e mde to pply to reursive of tndrd wv re dequte to desrie ppropriE dttypes in tndrd wvY this is extremely unE te lirriesD nd tht9s wht is importntF fortunteF s elieve the prolem lies in the prtil fut the initil sisD suh s it isD hs some rough strtion of dttypesF sn the exmple oveD edgesX the progrmmer hs strted list into tD ut hs not strted the dttype listF his is here re funtions for reding nd writing n unusul progrmF he whole point of onE strings of hrtersD for onverting integers rete dttype is tht it is not strtY if the proE into singleEhrter strings @nd kAD nd grmmer wnted n strt type in the interfe for ontenting stringsD nd for exploding4 then the prmeter of p wouldn9t hve mentioned strings into lists of singleEhrter stringsD nd dttype t llF imploding4 @ontenting list of strings toE husD solution to this prolem might e to getherAF fut there is no wy to ess the ith hnge very slightly the notion of dttypeF snE hrter of string in onstnt time|there is sted of sying tht dttype is the disjoint sum no sustring opertor3 he only wy to extrt of severl typesD let us sy tht it is the disjoint n internl hrter of string is to explode sum of severl produt typesF ht isD the vlue the string nd then to trverse the resulting rried y onstrutor is not just typeD it is listY this tkes time liner in the length of the reord typeF xote tht this is extly the wy tht stringF vrint reord works in slF here is no wy to mke updtele rrys hen the prolemti progrm ove would not with onstntEtime ess to ritrry eleE e leglF he funtor denition would e llowedD mentsF errys n e simulted y lists @or ut the dttype in the tul prmeter would not treesA of ref ellsD ut ess nd updte opE mth the dttype in the forml prmeterF ertions will then tke liner @or logrithmiA his slight restrition would llow ompilers to timeF pdtele rrys re ertinly not out use muh more eient representtions of onrete of ple in lnguge with updtele refsF dttypes in wvF et present we re experimentE ing with n implementtion of this representtion he rithmeti opertors my overowD in @nd onsequent lnguge restritionA to explore whih se the henition presries tht C will this trdeoF rise the um exeptionD B will rise the rod exE yne might think tht ompiler should lso repE eptionD nd so onF st is extremely inonvenient resent eh element of n @int intAlist s triple for the implementor to hve distint exepE @intY intY til pointerAF fut here the produt type tions for the dierent opertorsY most omputE @int intA is not prt of the dttype itselfD ut prt ers don9t rise seprte hrdwre exeptions for of the type prmeter of the list onstrutorF his dierent kinds of overowF end the progrmE would led to prolems when polymorphi funtions mer would lmost lwys e served just s well on list types re pplied to speillyErepresented y single exeption lled yverflowF listsF husD suh n optimiztion hs prolems not only t funtor oundries ut t funtion oundE here is no it string typeD nd there re no riesF itwise logil opertors on the integer typeF here re mny pplitions of itwise operE ISgrdelliD of ourseD ws not ompiling lnguge with tors in grphisD numer theoryD ryptogrE funtorsF phyD nd other resF yn the other hndD it
PI is worth noting tht wv9s div nd mod hve hefenseD xvl ulitions nd porms genterD rounding ehvior @towrds negtive innityD hildelphiD eD IWVHF not towrds zeroA tht llow shifts nd msks P homs iF endersonD frin xF fershdD idE to e dened using powers of twoY ompilers wrd hF vzowskD nd renry wF vevyF heduler ould optimize this seD in prinipleF tivtionsX ietive kernel support for the userE level mngement of prllelismF egw rnsF on pon n inputGoutput errorD the so exeption gomputer ystemsD IH@IAXSQ{UWD perury IWWPF is rised with string rgumentF he formt Q endrew F eppelF untime tgs ren9t neessryF of the rgument is speied in the henitionD visp nd ymoli gomputtionD PXISQ{TPD IWVWF nd this formt does not provide enough inE R endrew F eppelF gompiling with gontinutionsF formtion for serious pplitionsF st would gmridge niversity ressD IWWPF hve een preferle to leve the ontents of the string unspeied rther thn premturely S endrew F eppel nd hvid fF wueenF e tndrd wv ompilerF sn qilles uhnD editorD settling on n indequte stndrdF puntionl rogrmming vnguges nd gomputer o nish on trivil noteX the list ontenE erhiteture @vxg PURAD pges QHI{PRD xew orkD IWVUF pringerEerlgF tion opertor d is delred inxD ssoiting to the leftF rogrms would ompute the sme T endrew F eppel nd hvid fF wueenF tnE result under right ssoitivityD ut would run drd wv of xew terseyF sn wrtin irsingD ediE fsterD sine d must opy its left rgument ut torD hird snt9l ympF on rogF vngF smplemenE ttion nd vogi rogrmmingD pges I{IQD xew not its right oneF orkD eugust IWWIF pringerEerlgF st is worth noting tht every implementtion of U vu grdelliF gompiling funtionl lngugeF sn wv sine grdelli9s hs hd onstnt time rry IWVR ympF on vs nd puntionl rogrmmingD susript nd n eient sustring funtionY the pges PHV{IUD xew orkD IWVRF egw ressF henition ould hve provided helpful stndrdE V ill glinger nd vrs homs rnsenF ss expliit iztionF dellotion relly fster thn grge olletionc unpulished mnusriptD IWWPF W iri gF gooper nd tF qregory worrisettF edding S gonlusion threds to tndrd wvF ehnil eport gw E gEWHEIVTD hool of gomputer ieneD grnegie he populrity of wv seems to e inresingD oth wellon niversityD ittsurghD eD heemer IWWHF s lnguge for writing rel progrms nd s IH vuis hmsF ype essignment in rogrmming strting point for theoretil investigtions of type vngugesF hh thesisD heprtment of gomputer theory nd lnguge designF rogrmmers should ieneD niversity of idinurghD IWVSF note tht the good points of wv disussed in this II frue huD oert rrperD nd hvid wE pper re ll rther generl nd importntY the ritE ueenF yping rstElss ontinutions in wvF iisms tend to e nrrowD tehnilD nd not lwys sn iighteenth ennul egw ympF on riniples importntF of rogF vngugesD pges ITQ{UQD xew orkD tn heorists should note thtD even though some of IWWIF egw ressF the ritiisms re minor nd not of muh theoretil IP wF tF qordonD eF tF wilnerD nd gF F dsworthF interestD they ll et the usility of the lngugeF idinurgh vgpF pringerEerlgD xew orkD IWUWF hose theorists who ntiipte designing lnguge IQ gF eF F roreF rints on rogrmmingEvnguge themselves somedy might wnt to rememer this hesignD pges IWQ{PITF rentie rllD IWVWF ritiqueD long with the lssis of the genreIQD RTF keynote ddress to the egw sqvex onferene in IWUQF eknowledgment IR eport on the progrmming lnguge rskellX erE sion IFIF ehnil eport ehnil eportD le s would like to thnk houg wslroy nd n nonyE niversity nd qlsgow niversityD eugust IWWIF mous referee for mny vlule ommentsF IS eport on the progrmming lnguge rskellD nonEstritD purely funtionl lngugeD version IFPF eferenes sqvex xotiesD PU@SAD wy IWWPF IT uthleen tensen nd xiklus irthF slX ser I wilitry stndrdX ed progrmming lngugeF wnul nd eportF pringerEerlgD xew orkD ehnil eport wsvEhEIVISD heprtment of IWURF
PP IU ierre touvelot nd hvid uF qiordF elgeri QP qreg xelsonD editorF ystems rogrmming with reonstrution of types nd eetsF sn iighteenth wodulEQF rentie rllD inglewood glisD xtD ennul egw ympF on riniples of rogF vnE IWWIF gugesD pges QHQ{QIHD xew orkD tn IWWIF egw QQ ott xettles nd tmes F y9ooleF grnegie ressF wellon nivFD ittsurghD eD personl ommuniE IV tefn uesF ype inferene in the presene of tion from ott xettlesD IWWHF overlodingD sutyping nd reursive typesF sn QR tF ees nd F glingerF evised report on the roF IWWP egw gonfF on visp nd puntionl lgorithmi lnguge hemeF sqvex xotiesD rogrmmingD pges IWQ{PHRF egw ressD IWWPF PI@IPAXQU{UWD IWVTF IW frin F uernighn nd hennis wF ithieF he g QS tohn rF eppyF gonurrent progrmming with rogrmming vngugeF rentieErllD inglewood eventsF ehnil reportD gornell niversityD heptF glisD xtD IWUVF of gomputer ieneD sthD xD IWWHF PH endrew uoenigF g rps nd itfllsF eddisonE QT tohn rF eppy nd imden F qnsnerF he eene esleyD edingD wssD IWVWF lirry mnulF gornell nivF heptF of gomputer ieneD wrh IWWIF PI vier veroyF noxed ojets nd polymorphi typingF sn xineteenth ennul egw ympF on QU golin unimn nd hvid kelingF rep prolE riniples of rogF vngugesD pges IUU{IVVD xew ing of lzy funtionl progrmsF ehnil eport orkD tnury IWWPF egw ressF IUPD niversity of orkD heptF of gomputer iE eneD reslingtonD ork HI ShhD nited uingdomD PP vier veroy nd wihel wunyF hynmis in epril IWWPF mlF sn tF rughesD editorD puntionl rogrmming QV hong ho nd endrew F eppelF mrtest vnguges nd gomputer erhitetureX Sth egw reompiltionF sn roF wentieth ennul egw gonferene @vxg SPQAD pges RHT{RPTF pringerE sqvexEsqeg ympF on riniples of roE erlgD IWWIF grmming vngugesD pge to pperF egw ressD PQ vier veroy nd ierre eisF olymorphi type IWWQF inferene nd ssignmentF sn iighteenth ennul QW oert eF hwF smproving grge olletor perE egw ympF on riniples of rogF vngugesD formne in virtul memoryF ehnil eport pges PWI{QHPD xew orkD tn IWWIF egw ressF gvEEVUEQPQD tnford niversityD lo eltoD PR renry vieermn nd grl rewittF e relEtime geD IWVUF grge olletor sed on the lifetimes of ojetsF RH tenEierre lpin nd ierre touvelotF olymorE gommunitions of the egwD PT@TAXRIW{PWD IWVQF phi typeD regionD nd eet infereneF ehnil PS tohn wF vussen nd hvid uF qiordF olyE eport iwEgs iGISHD iole des wines de risD morphi eet systemsF sn pifteenth ennul egw perury IWWIF ympF on riniples of rogF vngugesD pges RU{ RI wds ofteF ype inferene for polymorphi refE SUD xew orkD tn IWVVF egw ressF erenesF snformtion nd gomputtionD VWXI{QRD xovemer IWWHF PT hvid wueenF wodules for tndrd wvF sn roF IWVR egw gonfF on vs nd puntionl RP hvid wF ngrF he hesign nd ivlution of rogrmmingD pges IWV{PHUD xew orkD IWVRF righ erformne mlltlk ystemF ws ressD egw ressF gmridgeD weD IWVTF PU hvid fF wueenF wekEtypesF histriuted RQ hilip dlerF he essene of funtionl progrmE with tndrd wv of xew terseyD IWVVF ming @invited tlkAF sn xineteenth ennul egw ympF on riniples of rogF vngugesD pges I{ PV oin wilnerF e theory of type polymorphism in IRD xew orkD tn IWWPF egw ressF progrmmingF tournl of gomputer nd ystem RR hilip dler nd tephen flottF row to mke ienesD IUXQRV{USD IWUVF dEho polymorphism less d hoF sn ixteenth enE PW oin wilnerF e proposl for tndrd wvF sn nul egw ympF on riniples of rogF vngugesD egw ymposium on vs nd puntionl roE pges TH{UTD xew orkD tnury IWVWF egw ressF grmmingD pges IVR{WUD xew orkD IWVRF egw RS withell ndF gontinutionEsed multiproessE ressF ingF sn gonfF eord of the IWVH visp gonfFD pges QH oin wilner nd wds ofteF gommentry IW{PVD xew orkD eugust IWVHF egw ressF on tndrd wvF ws ressD gmridgeD wsE RT tF elshD F tF neeringerD nd gF eF F roreF shusettsD IWWIF emiguities nd inseurities in slF oftwre| QI oin wilnerD wds ofteD nd oert rrperF rtie nd ixperieneD U@TAXTVS{WTD IWUUF he henition of tndrd wvF ws ressD gmE RU xiklus irthF rogrmming in wodulEPF ridgeD weD IWVWF pringerEerlgD xew orkD xD IWVIF
PQ RV endrew uF rightF olymorphi referenes for mere mortlsF sn roeedings of the iuropen ymE posium on rogrmmingD IWWPF
PR