Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: <john.else@citrix.com>
To: caml-list@inria.fr
Subject: [Caml-list] C binding with labelled arguments
Date: Wed,  7 Nov 2012 16:54:58 +0100 (CET)	[thread overview]
Message-ID: <sympa.1352300034.12139.841@inria.fr> (raw)

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

             reply	other threads:[~2012-11-07 15:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-07 15:54 john.else [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sympa.1352300034.12139.841@inria.fr \
    --to=john.else@citrix.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox