My question: is there a way to pass a polymorphic Comparator here so that do_something can keep the same polymorphic interface? I’m imagining something that would be used like this:
Or is there a better way to go about this?
Ideally I’d like to get rid of the polymorphic comparison someday, which I assume would require passing down the appropriate comparator at every callsite. But I’d like to avoid that for now, if possible.
Thanks for the reply. When I pass Comparator.Poly.comparator, I get the error
Error: This expression has type
('a, Comparator.Poly.comparator_witness) Comparator.t
but an expression was expected of type
('b, 'c) Set.comparator =
(module Core_kernel__.Comparator.S with type comparator_witness = 'c and type t = 'b)
My apologies, I may have been looking at the wrong docs when I quoted the type for comparator, which is actually ('a, 'b) Set.comparator .
use Core_kernel.Using_comparator.stable_dedup_list: this function takes a _ Comparator.t as the ~comparator argument, or
to use Core_kernel.Set.stable_dedup_list, which takes a Comparator.S as the ~comparator argument, do something along the lines:
open Core_kernel
let do_something (type a) (l : a list) =
let module C = struct include Comparator.Poly type t = a end in
Set.stable_dedup_list (module C) l;;