doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author krauss
Thu, 17 May 2007 22:33:41 +0200
changeset 22999 c1ce129e6f9c
parent 22798 e3962371f568
child 23107 0c3c55b7c98f
permissions -rw-r--r--
Added unification case study (using new function package)

structure ROOT = 
struct

structure Code_Generator = 
struct

type 'a eq = {op_eq : 'a -> 'a -> bool};
fun op_eq (A_:'a eq) = #op_eq A_;

end; (*struct Code_Generator*)

structure List = 
struct

fun memberl A_ x (y :: ys) =
  Code_Generator.op_eq A_ x y orelse memberl A_ x ys
  | memberl A_ x [] = false;

end; (*struct List*)

structure Codegen = 
struct

fun collect_duplicates B_ xs ys (z :: zs) =
  (if List.memberl B_ z xs
    then (if List.memberl B_ z ys then collect_duplicates B_ xs ys zs
           else collect_duplicates B_ xs (z :: ys) zs)
    else collect_duplicates B_ (z :: xs) (z :: ys) zs)
  | collect_duplicates B_ xs ys [] = xs;

end; (*struct Codegen*)

end; (*struct ROOT*)