From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 3A17BBC57 for ; Thu, 23 Sep 2010 16:32:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0BAPsBm0zRVdg0kGdsb2JhbACiKAgVAQEBAQkJDAcRAx+rAIk9ghSGUi6IVQEBAwWFPASKOIkD X-IronPort-AV: E=Sophos;i="4.57,223,1283724000"; d="scan'208";a="72608137" Received: from mail-qw0-f52.google.com ([209.85.216.52]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Sep 2010 16:32:41 +0200 Received: by qwf6 with SMTP id 6so1688835qwf.39 for ; Thu, 23 Sep 2010 07:32:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=XbQOrBENg91/eRfUjON8dcGXp7roqqHeo9ihToysMbI=; b=hYNd7WD2ldajfqJDREAlC5BaYVdBXE+gjxAE+5RRuyt6tfS8/vZ92A6Y8B3p50s4Vf QecIxDiWK11WrAI81M80/l3b084V9ZW9XLHwD/ybNTM0sPYgGRsZKChklhRBIrVgQgUq HFmVG2faLI1CJ57C1B/BjTrM1u4zYBR1eSDjE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=xmZOmA8JfNzLfuFNyIb2EvjZNjMCVgDGhSkyFyDCU5rJA47oZhBLmlBstnYZ3XWPIo iO9hbmx4MjE2e0lXzK3uIrFquKdU/Y21ujcVhNkB9Jopgh9Ojls5k9BSUMuRvB/UvhIe p9ywNCOd/Gl9Xrc8WZSVajke/kv3rw4SFgQxI= Received: by 10.224.11.20 with SMTP id r20mr1389271qar.29.1285252360883; Thu, 23 Sep 2010 07:32:40 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.28.210 with HTTP; Thu, 23 Sep 2010 07:32:20 -0700 (PDT) In-Reply-To: References: From: bluestorm Date: Thu, 23 Sep 2010 16:32:20 +0200 X-Google-Sender-Auth: XgPMjDE5Ky_50coj0l5L-5M1EzA Message-ID: Subject: Re: [Caml-list] Optional arguments "between" non-optional ones To: Adrien Cc: Caml Mailing List Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; ocaml:01 compiler:01 caml-list:01 functions:01 caml:02 argument:02 argument:02 inferred:02 coerce:02 parameter:02 match:02 declaration:02 annotation:02 defining:02 unit:03 (sorry for any double-posting) The problem is that in your declaration of h, the inferred type for f is of the form (unit -> unit -> ...), and you use it with the different type (unit -> ?a:'a -> unit -> ...). Changing ?a to be the first parameter of f change f's type to (?a:'a -> unit -> unit -> ...). OCaml knows that it can implicitly coerce functions when the optional parameters appear in the first position. This is explained in the manual : http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#htoc39 > However, in the specific case where the expected type > is a non-labeled function type, and the argument is > a function expecting optional parameters, the compiler > will attempt to transform the argument to have it match > the expected type, by passing None for all optional parameters. A fix is to add an annotation when defining h : let h (f : _ -> ?a:_ -> _) = f () () # let () = h f;; bouh! bouh!