doc-src/IsarAdvanced/Codegen/Thy/examples/set_list.ML
author chaieb
Wed, 27 Feb 2008 14:39:48 +0100
changeset 26154 894f3860ebfd
parent 25370 8b1aa4357320
child 26513 6f306c8c2c54
permissions -rw-r--r--
Installation of Quantifier elimination for ordered fields moved to Library/Dense_Linear_Order.thy

structure HOL = 
struct

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

end; (*struct HOL*)

structure List = 
struct

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

fun member A_ x (y :: ys) =
  (if HOL.eqop A_ y x then true else member A_ x ys)
  | member 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 member A_ x (Set xs) = List.member A_ x xs;

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

end; (*struct Set*)