28.01.2015 Views

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

type).Ifthecheckfails,theexceptionDefinitionErrorisraised. ischeckedforresolutionerrors<strong>and</strong>otherrestrictions(e.g.eachvariant denitionincludesacaseidforeachpossiblevalueoftheenumeration oper<strong>and</strong>isafullyinitializeddenitionsmodule.Thedenitionsmodule Thisoperationcompletestheinitializationofadenitionsmodule.The Ifthechecksucceeds,theidcomponentofthedenitionsmoduleisre-<br />

11.<strong>Hermes</strong>Operations131<br />

attributebehaveslikeaconstraint:anyattempttomodifythedenitions initionsmodulearereplacedbytheuniqueidentier.Thedenitionsmod-<br />

uleacquirestheattributecheckeddefinitions.Thecheckeddefinitions placedbyauniqueidentier.Allreferencestothatidentierwithinthedef-<br />

modulewilldiscardtheattributecheckeddefinitions.Unlikeaconstraint attribute,checkeddefinitionscannotbeusedinanassertstatement; anteedthatwhentwotypenamesorattributenamesareequal,theyalways mescanenforce\nameequivalence"oftypes.Noothercheckeddenitions modulecanpossiblyhavethesamemoduleidentier.Thereforeitisguar-<br />

denotethesametypeorattributedenition. theattributecanonlybeassertedbyexecutingthecheckdefinitions statement.<br />

11.11Constraints Becausecheckeddenitionsaregivenauniquemoduleidentier,Her-<br />

attribute{construction<br />

argumentbenon-negative.Aprogramlibrarymightbedenedasatable ::=constraint(<br />

ofcheckedprograms. Forinstance,theinterfacetoasquare-rootfunctionmightrequirethatthe Constraintsareprogrammer-denedpredicatesonthevaluesofvariables.It isoftendesirabletoincludeconstraintsininterfacesorintypedenitions. )isconstraint{typestateconstraint{expression [declaration[,declaration]...]<br />

betrackedastypestateattributes.Currently,<strong>Hermes</strong>isnotsophisticated enoughtounderst<strong>and</strong>thesemanticsofconstraintpredicateswellenough totrackhowtheyarepreservedunderalloperations.Forexample,the compilerwillnotdeterminethataddingonetoanon-negativenumberwill yieldanothernon-negativenumber.Whatitwilldoisthefollowing: In<strong>Hermes</strong>,theprogrammercanspecifythatcertainconstraintsareto<br />

addthetypestateattributeNonNegative(a)iftheoperationassert associateanamewithapredicate{e.g.NonNegative(x)withthe whichwilltestwhethera>=0<strong>and</strong>raiseanexceptionifitisnot. predicatex>=0.ThisdenesanoperationassertNonNegative(a)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!