@@ -9,9 +9,9 @@ let ( let* ) x f = Result.bind x ~f
99
1010let unifiable r r' = StellarRays. solution [ (r, r') ] |> Option. is_some
1111
12- let constellations_compatible c1 c2 =
13- (* Check if two constellations are compatible for Match (~=) *)
14- (* Uses unifiable which requires opposite polarities for interaction *)
12+ let constellations_matchable c1 c2 =
13+ (* Check if two constellations are matchable for Match (~=) *)
14+ (* Uses term unification (ignoring polarity, only checking function name equality) *)
1515 let open Lsc_ast in
1616 (* Extract all rays from both constellations *)
1717 let rays_from_constellation c =
@@ -20,9 +20,9 @@ let constellations_compatible c1 c2 =
2020 let rays1 = rays_from_constellation c1 in
2121 let rays2 = rays_from_constellation c2 in
2222
23- (* Check if any ray from c1 is unifiable with any ray from c2 *)
23+ (* Check if any ray from c1 can unify with any ray from c2 (ignoring polarity) *)
2424 List. exists rays1 ~f: (fun r1 ->
25- List. exists rays2 ~f: (fun r2 -> unifiable r1 r2) )
25+ List. exists rays2 ~f: (fun r2 -> terms_unifiable r1 r2) )
2626
2727let rec find_with_solution env x =
2828 let rec search_objs = function
@@ -32,7 +32,12 @@ let rec find_with_solution env x =
3232 let value_normalized = map_ray env ~f: (replace_indices 0 ) value in
3333 let x_normalized = replace_indices 1 x in
3434 match StellarRays. solution [ (key_normalized, x_normalized) ] with
35- | Some substitution -> Some (value_normalized, substitution)
35+ | Some substitution ->
36+ (* Only use renamed value if there's actual parameter substitution *)
37+ let result_value =
38+ if List. is_empty substitution then value else value_normalized
39+ in
40+ Some (result_value, substitution)
3641 | None -> search_objs rest )
3742 in
3843 search_objs env.objs
@@ -299,7 +304,7 @@ let rec eval_sgen_expr (env : env) :
299304 let * env2, eval2 = eval_sgen_expr env1 expr2 in
300305 let const1 = List. map eval1 ~f: Marked. remove in
301306 let const2 = List. map eval2 ~f: Marked. remove in
302- if constellations_compatible const1 const2 then Ok (env2, [] )
307+ if constellations_matchable const1 const2 then Ok (env2, [] )
303308 else Error (MatchError { term1 = eval1; term2 = eval2; message; location })
304309 | Use path -> (
305310 let open Lsc_ast.StellarRays in
0 commit comments