let check_cons handle_error =
let rec check_cons_rec = function
Cons(t1,t2)
| Delete(t1,t2) ->
(match t2 with
Base(Var(n))
| Prime(Var(n)) ->
handle_error
(fun _ ->
(try
(match (Globals.type_table#get_type n) with
Set([]) ->
()
| Set(h::_) ->
handle_error
(fun _ ->
try (compare_types t1 h)
with Invalid_argument _ -> raise (Invalid_build "2"))
()
| _ ->
handle_error (fun _ -> raise (Invalid_build "3")) ())
with Not_found ->
raise (Undefined_var (Globals.string_id#get_name n))))
()
| Cons(_)
| Delete(_) -> check_cons_rec t2
| Set(l) -> List.iter (compare_terms handle_error t1) l
| _ ->
handle_error (fun _ -> raise (Invalid_build "3")) ())
| _ -> ()
in
check_cons_rec