Remove duplicate elements: Difference between revisions

Line 958:
 
=={{header|CafeOBJ}}==
The parametrized module NO-DUP-LIST(ELEMENTS :: TRIV) defines the signature of simplea space separated list structure. The removal of duplicates is handled by the equational properties listed after the signature in brackets {}. There is no user written code in module NO-DUP-LIST. The binary operation (_, _) is associative, commutative, and idempotent, meaning (x , x) = x. This list structure does not permit duplicates, they are removed during evaluation (called reduction in CafeOBJ). Using this module we can perform set union, just by evaluating two lists e.g:
<lang> red (1 2 3 4) (3 2 1 5) .
--> (4 5 1 2 3):Int
Line 992:
 
 
The evaluation automatically uses right associativity. So starting with:
 
<lang> (1 1 2 1 1)</lang>
Line 1,000:
<lang> (1 ((1 2) (1 1))) </lang>
 
ByIdempotency idempotencyis applied at rightmost brackets:
We get rewrite ''(1 1) -> 1'' . The term is now:
 
Line 1,006:
 
Any further occurrence of 1 will be removed.
 
By idempotency applied at inner brackets ''(1 2) ''.
WeIdempotency getis rewriteapplied at inner brackets ''(1 2) -> 2 ''. Term is now:
We get rewrite ''(1 2) -> 2 ''. The term is now:
 
<lang>(1 (2 1))</lang>
101

edits