doc-src/IsarAdvanced/Codegen/Thy/examples/set_list.ML
changeset 25370 8b1aa4357320
parent 24421 acfb2413faa3
child 26513 6f306c8c2c54
equal deleted inserted replaced
25369:5200374fda5d 25370:8b1aa4357320
    10 struct
    10 struct
    11 
    11 
    12 fun foldr f (x :: xs) a = f x (foldr f xs a)
    12 fun foldr f (x :: xs) a = f x (foldr f xs a)
    13   | foldr f [] a = a;
    13   | foldr f [] a = a;
    14 
    14 
    15 fun member A_ x (y :: ys) = HOL.eqop A_ x y orelse member A_ x ys
    15 fun member A_ x (y :: ys) =
       
    16   (if HOL.eqop A_ y x then true else member A_ x ys)
    16   | member A_ x [] = false;
    17   | member A_ x [] = false;
    17 
    18 
    18 end; (*struct List*)
    19 end; (*struct List*)
    19 
    20 
    20 structure Set = 
    21 structure Set = 
    24 
    25 
    25 val empty : 'a set = Set [];
    26 val empty : 'a set = Set [];
    26 
    27 
    27 fun insert x (Set xs) = Set (x :: xs);
    28 fun insert x (Set xs) = Set (x :: xs);
    28 
    29 
    29 fun union xs (Set ys) = List.foldr insert ys xs;
    30 fun uniona xs (Set ys) = List.foldr insert ys xs;
    30 
    31 
    31 fun member A_ x (Set xs) = List.member A_ x xs;
    32 fun member A_ x (Set xs) = List.member A_ x xs;
    32 
    33 
    33 fun uniona (Set xs) = List.foldr union xs empty;
    34 fun unionaa (Set xs) = List.foldr uniona xs empty;
    34 
    35 
    35 end; (*struct Set*)
    36 end; (*struct Set*)