let match_message (name : string) (state : string) (m1 : string) (name2 : string) (state2 : string) (m2 : string) : bool =
let rec adjust_pair m =
let rec adjust m =
let decomp = decompose m in
if(decomp=[]) then m
else if((car decomp)="pair") then (list2string "," (List.map adjust (cdr decomp)))
else ((car decomp)^"("^(list2string "," (List.map adjust_pair (cdr decomp)))^")")
in
let decomp = decompose m in
if(decomp=[])
then m
else(
if((car decomp)="pair")
then((car decomp)^"("^(list2string "," (List.map adjust (cdr decomp)))^")")
else ((car decomp)^"("^(list2string "," (List.map adjust_pair (cdr decomp)))^")")
)
in
let rec zip_pair m =
let rec aux l =
match l with [] -> ""
|[x] -> (zip_pair x)
|(x::ls) -> "pair("^(zip_pair x)^","^(aux ls)^")"
in
let decomp = decompose m in
if(decomp=[]) then m
else if((car decomp)="pair") then (aux (cdr decomp))
else (zip_pair (car decomp))^"("^(list2string "," (List.map zip_pair (cdr decomp)))^")"
in
let (exist_match,sub) = get_match_message_story name state m1 name2 state2 m2 (!untyped_variable) in
if(exist_match<>(-1))
then(
if (sub=[]) then false
else true
)
else(
let t1 = get_type_of_var_in_state name state m1 in
let t2 = get_type_of_var_in_state name2 state2 m2 in
if(not(compatible t1 t2))
then (add_in_match_message_story name state m1 name2 state2 m2 (!untyped_variable) []; false)
else(
let m01 = adjust_pair m1 in
let m02 = adjust_pair m2 in
let l_sub = unify name m01 name2 m02 !untyped_variable in
let l_sub_res = (List.map
(fun (name1,value,name2,var) -> (name1,(zip_pair value),name2,var))
l_sub)
in
add_in_match_message_story name state m1 name2 state2 m2 (!untyped_variable) l_sub_res;
(l_sub<>[])
)
)