doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author urbanc
Fri, 17 Nov 2006 17:32:30 +0100
changeset 21405 26b51f724fe6
parent 21190 08ec81dfc7fb
child 21452 f825e0b4d566
permissions -rw-r--r--
added an intro lemma for freshness of products; set up the simplifier so that it can deal with the compact and long notation for freshness constraints (FIXME: it should also be able to deal with the special case of freshness of atoms)

structure ROOT = 
struct

structure Code_Generator = 
struct

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

end; (*struct Code_Generator*)

structure HOL = 
struct

fun op_eq (A_:'a Code_Generator.eq) a b = Code_Generator.eq A_ a b;

end; (*struct HOL*)

structure List = 
struct

fun memberl (A_1_:'a_1 Code_Generator.eq) x (y :: ys) =
  HOL.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*)