-- The parametrized module NO-DUP-LIST(ELEMENTS :: TRIV) defines the signature of simple Haskell like list structure. -- The removal of duplicates is handled by the equational properties listed after the signature in brackets {} -- The binary operation _,_ is associative, commutative, and idempotent. -- This list structure does not permit duplicates, they are removed during evaluation (called reduction in CafeOBJ) -- Actual code is contained in module called NO-DUP-LIST. -- The tests are performed after opening instantiated NO-DUP-LIST with various concrete types. -- For further details see: http://www.ldl.jaist.ac.jp/cafeobj/ mod! NO-DUP-LIST(ELEMENTS :: TRIV) { [ List < Elem < Elt] -- Sorts in Ordered Sorted Algebra op [] : -> List { prec: 0 } -- Empty List op _,_ : Elt Elt -> Elt { comm assoc idem prec: 80 l-assoc } op [_] : Elt -> List { prec: 0 } } -- Test on lists of INT, CHARACTER, and STRING open NO-DUP-LIST(INT) reduce [ 1 , 2 , 1 , 1 ] . -- Gives [ 1 , 2 ] open NO-DUP-LIST(CHARACTER) reduce [ 'a' , 'b' , 'a' , 'a' ] . -- Gives [ 'a' , 'b' ] open NO-DUP-LIST(STRING) reduce [ "abc" , "def" , "abc" ] . -- Gives [ "def" , "abc" ]