src/Pure/General/basics.ML
changeset 41493 f05976d69141
parent 39232 69c6d3e87660
child 51930 52fd62618631
equal deleted inserted replaced
41492:7a4138cb46db 41493:f05976d69141
    29   val the: 'a option -> 'a
    29   val the: 'a option -> 'a
    30   val these: 'a list option -> 'a list
    30   val these: 'a list option -> 'a list
    31   val the_list: 'a option -> 'a list
    31   val the_list: 'a option -> 'a list
    32   val the_default: 'a -> 'a option -> 'a
    32   val the_default: 'a -> 'a option -> 'a
    33   val perhaps: ('a -> 'a option) -> 'a -> 'a
    33   val perhaps: ('a -> 'a option) -> 'a -> 'a
       
    34   val merge_options: 'a option * 'a option -> 'a option
    34 
    35 
    35   (*partiality*)
    36   (*partiality*)
    36   val try: ('a -> 'b) -> 'a -> 'b option
    37   val try: ('a -> 'b) -> 'a -> 'b option
    37   val can: ('a -> 'b) -> 'a -> bool
    38   val can: ('a -> 'b) -> 'a -> bool
    38 
    39 
    88 fun the_default x (SOME y) = y
    89 fun the_default x (SOME y) = y
    89   | the_default x NONE = x;
    90   | the_default x NONE = x;
    90 
    91 
    91 fun perhaps f x = the_default x (f x);
    92 fun perhaps f x = the_default x (f x);
    92 
    93 
       
    94 fun merge_options (x, y) = if is_some x then x else y;
       
    95 
    93 
    96 
    94 (* partiality *)
    97 (* partiality *)
    95 
    98 
    96 fun try f x = SOME (f x)
    99 fun try f x = SOME (f x)
    97   handle exn => if Exn.is_interrupt exn then reraise exn else NONE;
   100   handle exn => if Exn.is_interrupt exn then reraise exn else NONE;