doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author wenzelm
Thu, 07 Dec 2006 00:42:04 +0100
changeset 21687 f689f729afab
parent 21452 f825e0b4d566
child 21993 4b802a9e0738
permissions -rw-r--r--
reorganized structure Goal vs. Tactic;

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*)