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/.
33 (** perform debugging output? *)
36 (** debugging print *)
39 prerr_endline ("TACTICALS WARNING: " ^ s)
41 (** AUX TACTIC{,AL}S *)
44 naive implementation of ORELSE tactical, try a sequence of tactics in turn:
45 if one fails pass to the next one and so on, eventually raises (failure "no
47 TODO warning: not tail recursive due to "try .. with" boxing
49 let rec try_tactics ~(tactics: (string * tactic) list) ~status =
50 warn "in Ring.try_tactics";
52 | (descr, tac)::tactics ->
53 warn ("Ring.try_tactics IS TRYING " ^ descr);
55 let res = tac ~status in
56 warn ("Ring.try_tactics: " ^ descr ^ " succedeed!!!");
62 | (CicTypeChecker.NotWellTyped _)
63 | (CicUnification.UnificationFailed) ->
65 "Ring.try_tactics failed with exn: " ^
66 Printexc.to_string e);
67 try_tactics ~tactics ~status
68 | _ -> raise e (* [e] must not be caught ; let's re-raise it *)
70 | [] -> raise (Fail "try_tactics: no tactics left")
72 let thens ~start ~continuations ~status =
73 let (proof,new_goals) = start ~status in
76 (fun (proof,goals) goal tactic ->
77 let (proof',new_goals') = tactic ~status:(proof,goal) in
78 (proof',goals@new_goals')
79 ) (proof,[]) new_goals continuations
81 Invalid_argument _ -> raise (Fail "thens: wrong number of new goals")
83 let then_ ~start ~continuation ~status =
84 let (proof,new_goals) = start ~status in
86 (fun (proof,goals) goal ->
87 let (proof',new_goals') = continuation ~status:(proof,goal) in
88 (proof',goals@new_goals')
89 ) (proof,[]) new_goals