let rec atoms_type_to_string (parentheses : bool) (a_term : Types.basic_type Types.term_structure) : string =
match a_term with
Base(term) | Prime(term) ->
(match term with
Agent -> "agent"
| Public_key -> "public_key"
| Symmetric_key -> "symmetric_key"
| Text -> "text"
| Message -> "message"
| Protocol_id -> "protocol_id"
| Channel -> "channel"
| Channel_dy -> "channel_dy"
| Channel_ota -> "channel_ota"
| Bool -> "bool"
| Hash_func -> "hash_func"
| Nat -> "nat"
| Enum(list) ->
"{"
^(List.fold_left
(fun s num ->
if not (num = List.hd list) then
s^","^(string_id#get_name num)
else
s^(string_id#get_name num))
"" list)
^"}")
| Inv t -> "inv("^(atoms_type_to_string false t)^")";
| Hash t -> "apply(hash_func,"^(atoms_type_to_string false t)^")";
| Set [] -> "set"
| Set lt -> "set("^(atoms_type_to_string false (List.hd lt))^")"
| Pair(t1,t2) ->
"pair("^(atoms_type_to_string false t1)^","^(atoms_type_to_string false t2)^")"
| Crypt(t1,t2) -> "crypt("^(atoms_type_to_string false t2)^","^(atoms_type_to_string false t1)^")"
| Scrypt(t1,t2) -> "scrypt("^(atoms_type_to_string false t2)^","^(atoms_type_to_string false t1)^")"
| Function(t,lt) ->
let string_of_args =
match lt with
[] -> "unit"
| [t1] -> atoms_type_to_string true t1
| t1::l ->
List.fold_left
(fun s t ->
s^" * "^(atoms_type_to_string true t))
(atoms_type_to_string true t1) l
in
if parentheses then
"("^string_of_args^" -> "^(atoms_type_to_string true t)^")"
else
string_of_args^" -> "^(atoms_type_to_string true t)
| _ -> "message"