diff --git a/eval.ml b/eval.ml index ccf01c7..4e9c8d6 100644 --- a/eval.ml +++ b/eval.ml @@ -241,18 +241,25 @@ module External = struct end let find_operator op ts = - let filter t = - List.filter (fun (ts, _) -> - match ts with [] -> false | x::_ -> t=x) + let open List in + let filter_type t i = + filter (fun (ts, _) -> + nth_opt ts i + |> Option.map ((=) t) + |> Option.value ~default: false) in - let rec aux ops = function - | [] -> List.nth_opt ops 0 + let rec aux ops i = function + | [] -> + ops + |> filter (fun (ts, _) -> length ts = i) + |> Fun.flip nth_opt 0 | t::ts -> - (match aux (filter t ops) ts with - | None -> Option.bind (Type.supertype t) (fun t -> aux ops (t::ts)) - | Some _ as x -> x) + (match aux (filter_type t i ops) (i+1) ts with + | None -> Option.bind (Type.supertype t) + (fun t -> aux ops i (t::ts)) + | Some _ as x -> x) in - aux (Operator.get op) ts + aux (Operator.get op) 0 ts let promote_values = let rec promote_until t v =