-- file: structSpecSTG.mod --> to select the lastly loaded module automatically set auto context on --> string of naturals mod! STRG-NAT { protecting(NAT) -- NAT is a built-in module of naturals [ Nat < Strg ] -- any natural is string of length one -- a binary juxtaposing operation for strings op (_ _) : Strg Strg -> Strg {assoc} } --> to show parse trees set verbose on open STRG-NAT parse 2 (3 4) . red 2 (3 4) . close --> end the effect of "verbose" set verbose off -- mod* TRIV { [ Elt ] } is a system built-in --> parameterized string mod! STRG (X :: TRIV) { -- any natural is string of length one [ Elt < Strg ] -- a binary juxtaposing operation for strings op (_ _) : Strg Strg -> Strg {assoc} } -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> there are several ways to instantiate parameter -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- (0) standard way of declaring view first and instantiate -- a formal parameter using it; view natAsTriv from TRIV to NAT {sort Elt -> Nat} make NAT-STRG0 (STRG(X <= natAsTriv)) make NAT-STRG0' (STRG(natAsTriv)) -- (1) on the fly view declaration make NAT-STRG1 (STRG(X <= view to NAT {sort Elt -> Nat})) -- (2) on the fly view declaration of shorter version -- this is a recommend way to instanciate parameters make NAT-STRG2 (STRG(NAT{sort Elt -> Nat})) -- (3) on the fly view declaration using the mod construct mod! NAT-STRG3 {protecting(STRG(NAT{sort Elt -> Nat}))} -- (4) on the fly view declaration -- with sort renaming *{sort Strg -> NatStrg} make NAT-STRG4 ((STRG(NAT{sort Elt -> Nat}))*{sort Strg -> NatStrg}) -- (5) making use of default view mechanism: -- it is possible because the sort Nat is -- declared to be the principal-sort -- in the built-in module NAT; -- it is not recommended if you are not -- get used to the notions of -- principal-sort and default view; -- with sort renaming *{sort Strg -> NatStrg} make NAT-STRG5 ((STRG(NAT))*{sort Strg -> NatStrg}) --> test for NAT-STRG2 --> to show parse trees set verbose on open NAT-STRG2 parse ((1 2) (3 2)) . red ((1 2) (3 2)) . close open NAT-STRG4 parse ((1 2) (3 2)) . red ((1 2) (3 2)) . close --> end the effect of "verbose" set verbose off --> the following is also working, --> but not recommended if you are not --> get used to the notions of --> principal-sort and default view mod! NAT-STRG6 {protecting(STRG(X <= NAT))} make NAT-STRG7 (STRG(X <= NAT)) --> BARE-NAT mod! BARE-NAT { [ NzNat Zero < Nat ] op 0 : -> Zero op s_ : Nat -> NzNat } --> notice that the following does not work --> because the pricipal sort is not declared --> in the module BARE-NAT make NAT-STRG8 (STRG(BARE-NAT)) make NAT-STRG9 (STRG(X <= BARE-NAT)) --> if the principal sort is declared as: mod! BARE-NATwithPsort principal-sort Nat { [ NzNat Zero < Nat ] op 0 : -> Zero op s_ : Nat -> NzNat } --> then the following two work make NAT-STRG10 (STRG(BARE-NATwithPsort)) make NAT-STRG11 (STRG(X <= BARE-NATwithPsort)) eof