caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] C binding with labelled arguments
@ 2012-11-07 15:54 john.else
  2012-11-07 16:16 ` Gabriel Scherer
  0 siblings, 1 reply; 5+ messages in thread
From: john.else @ 2012-11-07 15:54 UTC (permalink / raw)
  To: caml-list

Hi,

If I have a C function like so:

CAMLprim value stub_add_ints(value first, value second) {
  CAMLparam2(first, second);
  int sum;

  sum = Int_val(first) + Int_val(second);
  CAMLreturn(Val_int(sum));
}

and I write an OCaml binding for it:

external add_ints : int -> int -> int  = "stub_add_ints"

is there any way to give the OCaml function labelled arguments, other than
writing a pure OCaml wrapper function? I'd like to be able to call

add_ints ~first:3 ~second:4;;

instead of just

add_ints 3 4;;

If I define the binding like this:

external add_ints : first:int -> second:int -> int  = "stub_add_ints"

it compiles, but the labels seem to be ignored - calling the function with
labelled arguments gives the error "This argument cannot be applied with label
~first", and looking up the function's type with OCamlSpotter indeed shows
that the function's type has no label information.

Thanks,
John

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-07 17:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-07 15:54 [Caml-list] C binding with labelled arguments john.else
2012-11-07 16:16 ` Gabriel Scherer
2012-11-07 16:26   ` john.else
2012-11-07 16:40     ` Florent Monnier
2012-11-07 17:02       ` John Else

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).