From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: john.else@citrix.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] C binding with labelled arguments
Date: Wed, 7 Nov 2012 17:16:43 +0100 [thread overview]
Message-ID: <CAPFanBE2KBDCpg9Bu+xnTijZvVcpNmOr1hp4qo9US4dRGnJQ0Q@mail.gmail.com> (raw)
In-Reply-To: <sympa.1352300034.12139.841@inria.fr>
Given that the argument passing order of labelled functions is not
specified, it seems like it would be really safer to use a wrapper
function. Why wouldn't you do this?
(If that is for performance reason, the wrapper should be inlined when
used from inside the same module, and if you want to expose the
external globally you can always re-define it along with its wrapper
in any module.)
On Wed, Nov 7, 2012 at 4:54 PM, <john.else@citrix.com> wrote:
> 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
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
next prev parent reply other threads:[~2012-11-07 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-07 15:54 john.else
2012-11-07 16:16 ` Gabriel Scherer [this message]
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=CAPFanBE2KBDCpg9Bu+xnTijZvVcpNmOr1hp4qo9US4dRGnJQ0Q@mail.gmail.com \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=john.else@citrix.com \
/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