-- ======================================================================== -- SEQ: Generic Sequence -- ======================================================================== -- ======================================================================== -- a comment starts with '-- ' or '** ' and ends at the end of line -- -- a convention for commenting: -- '-- ' is used before the commented CafeOBJ text -- '** ' is used after the commented CafeOBJ text -- ======================================================================== -- ======================================================================== -- Sequence (i.e. associative list) with {id: emp} -- Sequence mod! SEQ (X :: TRIV) {[Elt < Seq] -- empty Sequence op emp : -> Seq . op (_ _) : Seq Seq -> Seq {constr assoc id: emp} -- -- equality of sequences -- for the case if either side is emp and other side is non-emp eq (emp = (S21:Seq E:Elt S22:Seq)) = false . -- for the case if both sides are non-emp ceq (E1:Elt S1:Seq = E2:Elt S2:Seq) = ((E1 = E2) and (S1 = S2)) if not((S1 == emp) and (S2 == emp)) . ** note that without the condition of ceq, ** (E1 = E2) gets into infinite loop ** because (E1 = E2) matchs to the left-hand side ** and appears also in the right-hand side ceqs ** if (S1 = emp) is used instead of (S1 == emp) ** ((`e1:Elt `s1:Seq) = (`e2:Elt `s2:Seq)) ** can not be reduced -- -- head (leftmost element) of a Seq op hd_ : Seq -> Elt . eq hd (E:Elt S:Seq) = E . } -- ======================================================================== provide seq -- ======================================================================== eof ** end of file -- test of SEQ -- three literals of Aid mod AID3lt { -- Aid literals [AidLt < Aid] -- an equation for literals of sort AidLt eq (B1:AidLt = B2:AidLt) = (B1 == B2) . -- arbitrary Aid literals ops b1 b2 b3 : -> AidLt . } -- open SEQ(AID3lt{sort Elt -> Aid}) . red b1 b2 = b1 b2 . red b2 b1 = b1 b2 . red b1 b2 b3 = b1 b2 b3 . red b2 b1 b3 = b1 b2 b3 . red hd (b1 b2) . red hd b1 b2 . red b1 `s:Seq = b1 `s:Seq . red b1 `s1:Seq = b1 `s2:Seq . red b1 `s:Seq = b2 `s:Seq . close