doc-src/IsarAdvanced/Codegen/Thy/examples/set_list.ML
author wenzelm
Sat, 15 Sep 2007 19:26:17 +0200
changeset 24582 57599da58045
parent 24421 acfb2413faa3
child 25370 8b1aa4357320
permissions -rw-r--r--
ML_Lex.keywords; tuned comments;

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) = HOL.eqop A_ x y orelse 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 union xs (Set ys) = List.foldr insert ys xs;

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

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

end; (*struct Set*)