doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author haftmann
Fri, 24 Aug 2007 14:14:17 +0200
changeset 24421 acfb2413faa3
parent 23850 f1434532a562
child 25182 64e3f45dc6f4
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23250
9886802cbbd6 updated documentation
haftmann
parents: 23107
diff changeset
     1
structure HOL = 
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     2
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     3
24421
acfb2413faa3 updated
haftmann
parents: 23850
diff changeset
     4
type 'a eq = {eqop : 'a -> 'a -> bool};
acfb2413faa3 updated
haftmann
parents: 23850
diff changeset
     5
fun eqop (A_:'a eq) = #eqop A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     6
23250
9886802cbbd6 updated documentation
haftmann
parents: 23107
diff changeset
     7
end; (*struct HOL*)
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     8
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     9
structure List = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    10
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    11
24421
acfb2413faa3 updated
haftmann
parents: 23850
diff changeset
    12
fun member A_ x (y :: ys) = HOL.eqop A_ x y orelse member A_ x ys
23850
f1434532a562 updated
haftmann
parents: 23250
diff changeset
    13
  | member A_ x [] = false;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    14
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    15
end; (*struct List*)
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    16
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    17
structure Codegen = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    18
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    19
22798
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    20
fun collect_duplicates B_ xs ys (z :: zs) =
23850
f1434532a562 updated
haftmann
parents: 23250
diff changeset
    21
  (if List.member B_ z xs
f1434532a562 updated
haftmann
parents: 23250
diff changeset
    22
    then (if List.member B_ z ys then collect_duplicates B_ xs ys zs
22798
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    23
           else collect_duplicates B_ xs (z :: ys) zs)
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    24
    else collect_duplicates B_ (z :: xs) (z :: ys) zs)
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    25
  | collect_duplicates B_ xs ys [] = xs;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    26
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    27
end; (*struct Codegen*)