1 (* Copyright (C) 2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
32 (** perform debugging output? *)
35 (** debugging print *)
38 prerr_endline ("TACTICALS WARNING: " ^ s)
40 (** AUX TACTIC{,AL}S *)
43 naive implementation of ORELSE tactical, try a sequence of tactics in turn:
44 if one fails pass to the next one and so on, eventually raises (failure "no
46 TODO warning: not tail recursive due to "try .. with" boxing
48 let rec try_tactics ~(tactics: (string * tactic) list) ~status =
49 warn "in Ring.try_tactics";
51 | (descr, tac)::tactics ->
52 warn ("Ring.try_tactics IS TRYING " ^ descr);
54 let res = tac ~status in
55 warn ("Ring.try_tactics: " ^ descr ^ " succedeed!!!");
61 | (CicTypeChecker.NotWellTyped _)
62 | (CicUnification.UnificationFailed) ->
64 "Ring.try_tactics failed with exn: " ^
65 Printexc.to_string e);
66 try_tactics ~tactics ~status
67 | _ -> raise e (* [e] must not be caught ; let's re-raise it *)
69 | [] -> raise (Fail "try_tactics: no tactics left")
71 let thens ~start ~continuations ~status =
72 let (proof,new_goals) = start ~status in
75 (fun (proof,goals) goal tactic ->
76 let (proof',new_goals') = tactic ~status:(proof,goal) in
77 (proof',goals@new_goals')
78 ) (proof,[]) new_goals continuations
80 Invalid_argument _ -> raise (Fail "thens: wrong number of new goals")
82 let then_ ~start ~continuation ~status =
83 let (proof,new_goals) = start ~status in
85 (fun (proof,goals) goal ->
86 let (proof',new_goals') = continuation ~status:(proof,goal) in
87 (proof',goals@new_goals')
88 ) (proof,[]) new_goals