From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 5D5BD7F256 for ; Wed, 7 Nov 2012 17:17:26 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.210.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.210.182 as permitted sender) identity=mailfrom; client-ip=209.85.210.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ia0-f182.google.com) identity=helo; client-ip=209.85.210.182; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ia0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloEAD6JmlDRVdK2m2dsb2JhbABEsT2RJQJ0CCMBAQEBAQgJCwkUJ4IeAQEFJxkBGxILAQMMBgULDQ0hIgERAQUBChIZCAqHZQEDDwudbYwwgniFDwoZJwMKWYh1AQUMjAGBZYE9gyUDkkmDMoEcjUcWKYQS X-IronPort-AV: E=Sophos;i="4.80,730,1344204000"; d="scan'208";a="161705957" Received: from mail-ia0-f182.google.com ([209.85.210.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 07 Nov 2012 17:17:25 +0100 Received: by mail-ia0-f182.google.com with SMTP id k10so2181429iag.27 for ; Wed, 07 Nov 2012 08:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=znedQgLCYOlBPmsg+gj1RQljyVzyckNS4QJPKRbIAPk=; b=qfIX8DfLIB46XPdM94nFZ47To3/OENRiyBYs0LJULWwEip/ii7SV6TgZCzwGowyNXB jvRxUVYrL2kMn4SgCsVs8BHEnp30Z7jPVw41oNjcFhmUlZ0UMLLf4vOmFqq+qh4KHzv3 Dk3FLIdD6H8MCRyZtXRXhyDAq5mkJn5n8/+yOO61OwlTfLWf7mMP6JYaJeFnnFtLqIFh SDLVoFntVUQLTYle+DEd0BmjSAf0/e1RoWKvPi7zrjOq8LyiLE0Pkl/Doui+a3uygT5G LBpBoTfdbM8JNbX+tNRxCqnFZvYlaTAsrsgWAnWSUjwZhaBxxdyLTwC9idRce+C5Pdp9 twiw== Received: by 10.50.1.200 with SMTP id 8mr5084145igo.51.1352305044016; Wed, 07 Nov 2012 08:17:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.50.184.199 with HTTP; Wed, 7 Nov 2012 08:16:43 -0800 (PST) In-Reply-To: References: From: Gabriel Scherer Date: Wed, 7 Nov 2012 17:16:43 +0100 Message-ID: To: john.else@citrix.com Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] C binding with labelled arguments 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, 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