src/Pure/tctical.ML
changeset 671 e0be228a9c5b
parent 631 8bc44f7bbab8
child 703 3a5cd2883581
equal deleted inserted replaced
670:ff4c6691de9d 671:e0be228a9c5b
     6 Tacticals
     6 Tacticals
     7 *)
     7 *)
     8 
     8 
     9 infix 1 THEN THEN' THEN_BEST_FIRST;
     9 infix 1 THEN THEN' THEN_BEST_FIRST;
    10 infix 0 ORELSE APPEND INTLEAVE ORELSE' APPEND' INTLEAVE';
    10 infix 0 ORELSE APPEND INTLEAVE ORELSE' APPEND' INTLEAVE';
       
    11 
       
    12 infix 0 THEN_ELSE;
    11 
    13 
    12 
    14 
    13 signature TACTICAL =
    15 signature TACTICAL =
    14   sig
    16   sig
    15   structure Thm : THM
    17   structure Thm : THM
    60   val tapply		: tactic * thm -> thm Sequence.seq
    62   val tapply		: tactic * thm -> thm Sequence.seq
    61   val THEN		: tactic * tactic -> tactic
    63   val THEN		: tactic * tactic -> tactic
    62   val THEN'		: ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    64   val THEN'		: ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    63   val THEN_BEST_FIRST	: tactic * ((thm->bool) * (thm->int) * tactic) 
    65   val THEN_BEST_FIRST	: tactic * ((thm->bool) * (thm->int) * tactic) 
    64 			  -> tactic
    66 			  -> tactic
       
    67   val THEN_ELSE		: tactic * (tactic*tactic) -> tactic
    65   val traced_tac	: (thm -> (thm * thm Sequence.seq) option) -> tactic
    68   val traced_tac	: (thm -> (thm * thm Sequence.seq) option) -> tactic
    66   val tracify		: bool ref -> tactic -> thm -> thm Sequence.seq
    69   val tracify		: bool ref -> tactic -> thm -> thm Sequence.seq
    67   val trace_BEST_FIRST	: bool ref
    70   val trace_BEST_FIRST	: bool ref
    68   val trace_DEPTH_FIRST	: bool ref
    71   val trace_DEPTH_FIRST	: bool ref
    69   val trace_REPEAT	: bool ref
    72   val trace_REPEAT	: bool ref
   121 
   124 
   122 (*Like APPEND, but interleaves results of tac1 and tac2.*)
   125 (*Like APPEND, but interleaves results of tac1 and tac2.*)
   123 fun (Tactic tf1)  INTLEAVE  (Tactic tf2) = 
   126 fun (Tactic tf1)  INTLEAVE  (Tactic tf2) = 
   124   Tactic (fn state =>  Sequence.interleave(tf1 state,
   127   Tactic (fn state =>  Sequence.interleave(tf1 state,
   125                           Sequence.seqof(fn()=> Sequence.pull (tf2 state))));
   128                           Sequence.seqof(fn()=> Sequence.pull (tf2 state))));
       
   129 
       
   130 (*Conditional tactic.
       
   131 	tac1 ORELSE tac2 = tac1 THEN_ELSE (all_tac, tac2)
       
   132 	tac1 THEN tac2   = tac1 THEN_ELSE (tac2, no_tac)
       
   133 *)
       
   134 fun (Tactic tf) THEN_ELSE (Tactic tf1, Tactic tf2) = 
       
   135   Tactic (fn state =>  
       
   136     case Sequence.pull(tf state) of
       
   137 	None    => tf2 state		(*failed; try tactic 2*)
       
   138       | seqcell => Sequence.flats 	(*succeeded; use tactic 1*)
       
   139 	            (Sequence.maps tf1 (Sequence.seqof(fn()=> seqcell))));
       
   140 
   126 
   141 
   127 (*Versions for combining tactic-valued functions, as in
   142 (*Versions for combining tactic-valued functions, as in
   128      SOMEGOAL (resolve_tac rls THEN' assume_tac) *)
   143      SOMEGOAL (resolve_tac rls THEN' assume_tac) *)
   129 fun tac1 THEN' tac2 = fn x => tac1 x THEN tac2 x;
   144 fun tac1 THEN' tac2 = fn x => tac1 x THEN tac2 x;
   130 fun tac1 ORELSE' tac2 = fn x => tac1 x ORELSE tac2 x;
   145 fun tac1 ORELSE' tac2 = fn x => tac1 x ORELSE tac2 x;