Is there at least one function poly_f that work on all 'a spec with a return type independent of 'a?
If the answer is yes, you can either replace your list of spec by a list of closure:
let close spec () = poly_f spec
let methods = [
close { cmd_t = Ctypes.(returning int) ; imp = (fun _self -> 42) };
close { cmd_t = Ctypes.(returning string); imp = (fun _self -> "Hello") }
]
or erase the type information behind an existential quantification with
type any_spec = Any: 'a spec -> any_spec
let methods =[
Any { cmd_t = Ctypes.(returning int) ; imp = (fun _self -> 42) };
Any { cmd_t = Ctypes.(returning string); imp = (fun _self -> "Hello") }
]
with the guarantee that at least List.map (fun (Any s) -> poly_f s) will work on the methods list.