let rec term_to_type = function
    Base(Var(i))
  | Base(Const(i))
  | Prime(Var(i)) ->
      Globals.type_table#get_type i
  | Prime(_) -> (* add a semantic error in this following case ! *)
      prerr_endline "Utils.term_to_type: Warning: invalid primed constant";
      raise Not_found
  | Cons(_,t2)
  | Delete(_,t2) ->
      term_to_type t2
  | Set(l) ->
      let rec find_applied = function
          t::lt ->
            (try
              Set([term_to_type t])
            with Not_found -> find_applied lt)
        | [] -> raise Not_found
      in
      find_applied l
(*  | Lst(l) ->
      let rec find_applied = function
          t::lt ->
            (try
              Lst([term_to_type t])
            with Not_found -> find_applied lt)
        | [] -> raise Not_found
      in
      find_applied l*)

  | Pair(t1,t2) ->
      Pair(term_to_type t1, term_to_type t2)
  | Scrypt(t1,t2) ->
      Scrypt(term_to_type t1, term_to_type t2)
  | Crypt(t1,t2) ->
      Crypt(term_to_type t1, term_to_type t2)
  | Inv(t) ->
      Inv(term_to_type t)
  | Function(t1,lt) ->
      Function(term_to_type t1, List.map term_to_type lt)
  | Hash(_) ->
      prerr_endline "Utils.term_to_type: Impossible error: invalid hash type/term"
      raise Not_found