doc-src/IsarAdvanced/Codegen/Thy/examples/set_list.ML
author haftmann
Tue, 05 Jun 2007 15:16:08 +0200
changeset 23247 b99dce43d252
parent 23107 0c3c55b7c98f
child 23250 9886802cbbd6
permissions -rw-r--r--
merged Code_Generator.thy into HOL.thy

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 List = 
struct

fun foldr f (x :: xs) a = f x (foldr f xs a)
  | foldr f [] a = a;

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

end; (*struct List*)

structure Set = 
struct

datatype 'a set = Set of 'a list;

val empty : 'a set = Set [];

fun insert x (Set xs) = Set (x :: xs);

fun uniona xs (Set ys) = List.foldr insert ys xs;

fun union (Set xs) = List.foldr uniona xs empty;

fun member A_ x (Set xs) = List.memberl A_ x xs;

end; (*struct Set*)

end; (*struct ROOT*)