src/Pure/General/same.ML
changeset 32017 e91a3acf8383
parent 32015 7101feb5247e
child 32022 c2f4ee07647f
equal deleted inserted replaced
32016:597b3b69b8d8 32017:e91a3acf8383
    11   type ('a, 'b) function = 'a -> 'b  (*exception SAME*)
    11   type ('a, 'b) function = 'a -> 'b  (*exception SAME*)
    12   type 'a operation = ('a, 'a) function  (*exception SAME*)
    12   type 'a operation = ('a, 'a) function  (*exception SAME*)
    13   val commit: 'a operation -> 'a -> 'a
    13   val commit: 'a operation -> 'a -> 'a
    14   val function: ('a -> 'b option) -> ('a, 'b) function
    14   val function: ('a -> 'b option) -> ('a, 'b) function
    15   val capture: ('a, 'b) function -> 'a -> 'b option
    15   val capture: ('a, 'b) function -> 'a -> 'b option
       
    16   val map: 'a operation -> 'a list operation
    16 end;
    17 end;
    17 
    18 
    18 structure Same: SAME =
    19 structure Same: SAME =
    19 struct
    20 struct
    20 
    21 
    30 fun function f x =
    31 fun function f x =
    31   (case f x of
    32   (case f x of
    32     NONE => raise SAME
    33     NONE => raise SAME
    33   | SOME y => y);
    34   | SOME y => y);
    34 
    35 
       
    36 fun map f [] = raise SAME
       
    37   | map f (x :: xs) = (f x :: commit (map f) xs handle SAME => x :: map f xs);
    35 
    38 
    36 end;
    39 end;