doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author wenzelm
Fri, 24 Nov 2006 22:05:18 +0100
changeset 21522 bd641d927437
parent 21452 f825e0b4d566
child 21993 4b802a9e0738
permissions -rw-r--r--
added export_morphism; ProofContext.init;

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_1_:'a_1 Code_Generator.eq) x (y :: ys) =
  Code_Generator.op_eq A_1_ x y orelse memberl A_1_ x ys
  | memberl (A_1_:'a_1 Code_Generator.eq) x [] = false;

end; (*struct List*)

structure Codegen = 
struct

fun collect_duplicates (A_:'a Code_Generator.eq) xs ys (z :: zs) =
  (if List.memberl A_ z xs
    then (if List.memberl A_ z ys then collect_duplicates A_ xs ys zs
           else collect_duplicates A_ xs (z :: ys) zs)
    else collect_duplicates A_ (z :: xs) (z :: ys) zs)
  | collect_duplicates (A_:'a Code_Generator.eq) y ys [] = y;

end; (*struct Codegen*)

end; (*struct ROOT*)