Hermes: A Tutorial and Reference Manual - Researcher - IBM
Hermes: A Tutorial and Reference Manual - Researcher - IBM
Hermes: A Tutorial and Reference Manual - Researcher - IBM
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
theelementwillalsobeknownbyapplyingthefunctionelementtypeof. Thethirdrulesaysthatifthetypeofthetableisknown,thenthetypeof headerlineisfollowedbythreetyperules.Therstruleisaclassrule,which unconditionallyinferredorcheckedtobeoftypepredefined!integer. statesthatthetypeoftablemustbeanorderedtabletype.Thesecondrule saysthattheoper<strong>and</strong>position|thisistheoper<strong>and</strong>afterthewordat|is 9.TypeChecking<strong>and</strong>Inference81<br />
sideoper<strong>and</strong>isknownarered.Eachtimeaninferenceruleisred,it infersthetypeoftheoper<strong>and</strong>onitsleftside.Ifthatoper<strong>and</strong>currentlyhas tion,theinferenceruleswithemptyright-h<strong>and</strong>sides,orwhoseright-h<strong>and</strong> typeisassignedbygeneratinganinferreddeclarationfortheoper<strong>and</strong>.Now matchisanerror.Iftheoper<strong>and</strong>currentlyhasunknowntype,theinferred resultswhichwereexplicitlymarkedwithatypespecier.Foreachopera-<br />
knowntype,theinferredtypeischeckedagainsttheknowntype.Amis-<br />
typesofthoseoper<strong>and</strong>swhicharevariablenames,<strong>and</strong>ofthoseexpression Thetypecheckingalgorithmbeginsbycomputingallknowntypes|the<br />
thatthetypeofthisoper<strong>and</strong>isknown,thismaycauseotherrulestore.<br />
example,thetestvariablesusedinif,while,select,<strong>and</strong>thepredicate unknowntypes,theprogramisinerror<strong>and</strong>thecompilerwillageach arenottable-driven.Theyarenotedintheappendixascomments.For occurrenceofsuchvariables. allvariablesshouldhavebeenassignedtypes.Ifanyvariablesstillhave eredoper<strong>and</strong>s,butareinsteadgroupedwiththequalier.Typeinference <strong>and</strong>typecheckingarealsoperformedforthesevariables,butthosechecks Typecheckingcontinuesuntilnoadditionalringsarepossible.Bynow,<br />
inaselector(theexpressionfollowingthekeywordwhere)areinferredas predefined!boolean.Becauseofthisinference,itislegaltowriteexpressionslikeif(a>b),whichotherwisewouldbeambiguoussincethe<br />
operation>canreturnaresultofanybooleantype.Thisinferencecan Therearesomevariableswhich,fortechnicalreasons,arenotconsid-<br />
messagethattheinteger-literaloperationcannotyieldaresultoftype<br />
leadtodetectionoftypeerrorselsewhere,e.g.if(3)...willproducea<br />
redundant. positionoper<strong>and</strong>isoftypepredefined!integer,aclassrulewouldbe itmaybeofanytype.Sinceaninferencerulealreadyguaranteesthatthe beanorderedtable.Thereisnoclassrulefortheelementoper<strong>and</strong>,since known.Forexample,thetableoper<strong>and</strong>oftheinsertatoperationmust isappliedregardlessofwhethertheoper<strong>and</strong>'stypewasinferredororiginally isaconstraintonthepossibletypesagivenoper<strong>and</strong>canhave.Theclassrule Note:Typechecking<strong>and</strong>inferencingisperformedafterresolution.Type Afteralltypeshavebeeninferred,theclassrulesareinvoked.Aclassrule<br />
Charstring. correctnessisneverusedasacriterionfordisambiguatinganame. thattypeCharstringisatableofChar,<strong>and</strong>thatQueueisatableof Herearefourexamplesillustratingtypeinference<strong>and</strong>checking.Assume