module alloy/A_TypCtxStruct -- Use this example to show the basic structural rules -- that govern a type context or TypeCtx. -- An Entity defines the content of a record in the Eventful Stories system abstract sig Entity {} -- An ERoot is the root element in a single type hierarchy. -- ERoots define the "is-a" relationship for its hierarchy, -- say for Person, Event. Location, Time sig ERoot extends Entity { rname: one TName } -- An EType defines a type and the contents of the record (attrnames) sig EType extends Entity { ename: one TName, -- The full name of the Entity sup: one Entity, -- An Entity has one supertype attrnames: some AName -- Attribute field names in the Entity. } { this != sup -- No reflexive super type definition } sig TName {} -- A Type name sig AName {}-- An attribute name -- A type context TypeCtx consists of a -- hierarchical definition of sub- and super-types -- placing each Entity type in the hierarchy. sig TypeCtx { types: some EType, root: some ERoot }{ -- An ERoot is at the top of every supertype hierarchy all t: types | one r : root | r in t.^sup no t: types | t in t.^sup -- No supertype cycles -- A unique name for each Entity and Root all disj e, e_: types | e.ename != e_.ename all disj r, r_: root | r.rname != r_.rname all r: root | all e: types | no (r.rname & e.ename) -- Attribute names must be unique for an EType -- Attribute names are also unique in an EType supertype hierarchy. all e: root+types | no (e.attrnames & e.^sup.attrnames) } fact { -- Each EType and ERoot is in one TypeCtx only all disj tc, tc_: TypeCtx | no (tc.types & tc_.types) all disj tc, tc_: TypeCtx | no (tc.root & tc_.root) -- Each EType and ERoot is in a TypeCtx, not free all r: ERoot | one tc: TypeCtx | r in tc.root all t: EType | one tc: TypeCtx | t in tc.types } pred show { } run show for 4 but exactly 1 TypeCtx run show for 5 but exactly 1 TypeCtx