Checking OCaml type signature from C
Let's say I have an OCaml function
let _ = register "cbf_coh_insert" (fun k v -> print_endline ("Inserted key=" ^ k ^ " value=" ^ v))
That is a function that takes two arguments. On the C side, I would call that with caml_callback2(*caml_named_value("cbf_coh_insert"), k, v);
. Is there a way, on the C side, to check that the number of arguments (2 in this case)开发者_高级运维 match? Other than I guess calling it and trying to trap a SIGSEGV. Thanks!
UPDATE: some background.
NO WAI
This should be ensured at compile time (either manually or by code generation or by parsing and checking whether C and OCaml code are in sync)
UPDATE
Example register function :
let on_cbf_coh_insert (f : string -> string -> unit) = register "cbf_coh_insert" f
UPDATE
I wish it was possible to pass a closure/let binding straight into C.
Why do you think it is not possible? Look at existing bindings that do this all the time.
BTW This question is a perfect illustration for XY problem.
精彩评论