src/Pure/General/same.ML
changeset 79272 899f37f6d218
parent 79131 cd17a90523d4
child 79400 0824ca1f1da0
equal deleted inserted replaced
79271:b14b289caaf6 79272:899f37f6d218
    12   type 'a operation = ('a, 'a) function  (*exception SAME*)
    12   type 'a operation = ('a, 'a) function  (*exception SAME*)
    13   val same: ('a, 'b) function
    13   val same: ('a, 'b) function
    14   val commit: 'a operation -> 'a -> 'a
    14   val commit: 'a operation -> 'a -> 'a
    15   val commit_id: 'a operation -> 'a -> 'a * bool
    15   val commit_id: 'a operation -> 'a -> 'a * bool
    16   val catch: ('a, 'b) function -> 'a -> 'b option
    16   val catch: ('a, 'b) function -> 'a -> 'b option
       
    17   val compose: 'a operation -> 'a operation -> 'a operation
    17   val function: ('a -> 'b option) -> ('a, 'b) function
    18   val function: ('a -> 'b option) -> ('a, 'b) function
    18   val map: 'a operation -> 'a list operation
    19   val map: 'a operation -> 'a list operation
    19   val map_option: ('a, 'b) function -> ('a option, 'b option) function
    20   val map_option: ('a, 'b) function -> ('a option, 'b option) function
    20 end;
    21 end;
    21 
    22 
    31 fun commit f x = f x handle SAME => x;
    32 fun commit f x = f x handle SAME => x;
    32 fun commit_id f x = (f x, false) handle SAME => (x, true);
    33 fun commit_id f x = (f x, false) handle SAME => (x, true);
    33 
    34 
    34 fun catch f x = SOME (f x) handle SAME => NONE;
    35 fun catch f x = SOME (f x) handle SAME => NONE;
    35 
    36 
       
    37 fun compose g f x =
       
    38   (case catch f x of
       
    39     NONE => g x
       
    40   | SOME y => commit g y);
       
    41 
    36 fun function f x =
    42 fun function f x =
    37   (case f x of
    43   (case f x of
    38     NONE => raise SAME
    44     NONE => raise SAME
    39   | SOME y => y);
    45   | SOME y => y);
    40 
    46