doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author haftmann
Thu, 26 Apr 2007 13:32:55 +0200
changeset 22798 e3962371f568
parent 22751 1bfd75c1f232
child 23107 0c3c55b7c98f
permissions -rw-r--r--
updated doc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     1
structure ROOT = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     2
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     3
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     4
structure Code_Generator = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     5
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     6
22386
4ebe883b02ff new code theorems
haftmann
parents: 22188
diff changeset
     7
type 'a eq = {op_eq : 'a -> 'a -> bool};
4ebe883b02ff new code theorems
haftmann
parents: 22188
diff changeset
     8
fun op_eq (A_:'a eq) = #op_eq A_;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
     9
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    10
end; (*struct Code_Generator*)
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    11
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    12
structure List = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    13
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    14
22188
a63889770d57 adjusted manual to improved treatment of overloaded constants
haftmann
parents: 22015
diff changeset
    15
fun memberl A_ x (y :: ys) =
22015
12b94d7f7e1f adaptions
haftmann
parents: 21994
diff changeset
    16
  Code_Generator.op_eq A_ x y orelse memberl A_ x ys
22188
a63889770d57 adjusted manual to improved treatment of overloaded constants
haftmann
parents: 22015
diff changeset
    17
  | memberl A_ x [] = false;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    18
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    19
end; (*struct List*)
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    20
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    21
structure Codegen = 
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    22
struct
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    23
22798
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    24
fun collect_duplicates B_ xs ys (z :: zs) =
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    25
  (if List.memberl B_ z xs
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    26
    then (if List.memberl B_ z ys then collect_duplicates B_ xs ys zs
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    27
           else collect_duplicates B_ xs (z :: ys) zs)
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    28
    else collect_duplicates B_ (z :: xs) (z :: ys) zs)
e3962371f568 updated doc
haftmann
parents: 22751
diff changeset
    29
  | collect_duplicates B_ xs ys [] = xs;
21147
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    30
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    31
end; (*struct Codegen*)
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    32
737a94f047e3 continued tutorial
haftmann
parents:
diff changeset
    33
end; (*struct ROOT*)