doc-src/IsarAdvanced/Codegen/Thy/examples/collect_duplicates.ML
author wenzelm
Thu, 14 Jun 2007 23:04:40 +0200
changeset 23395 15fb6637690e
parent 23250 9886802cbbd6
child 23850 f1434532a562
permissions -rw-r--r--
method assumption: uniform treatment of prems as legacy feature;

structure ROOT = 
struct

structure HOL = 
struct

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

end; (*struct HOL*)

structure List = 
struct

fun memberl A_ x (y :: ys) = HOL.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*)