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 470DFBC57 for ; Thu, 23 Sep 2010 17:05:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0BAAMJm0zRVdI0kWdsb2JhbACiKAgVAQEBAQkLCgcRAx+rJ4k9ghSGUS6IVQEBAwWFPASFBIU0hWA X-IronPort-AV: E=Sophos;i="4.57,223,1283724000"; d="scan'208";a="72630880" Received: from mail-pz0-f52.google.com ([209.85.210.52]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Sep 2010 17:05:31 +0200 Received: by pzk27 with SMTP id 27so481445pzk.39 for ; Thu, 23 Sep 2010 08:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=XCFjZvXi14O29D7TzXjDh1yq54FpPyV22WslPCir+Qs=; b=moHItDeU4CU5bxGXg8ZAq9zZ5WCmX4AvOSNM1oLOgoBjoUobz79kRee+SUaf2pCwCJ Nape57bMt/BmjkodYcdGvJW0EQaepxqV+pS3QAEcSoKPyvrSOO73r68hKbonGy8rfmqk 8H6D0PaM2LLxC7NWc5H0bFKZIxH7RN5ZbZpp0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=bYxzfV57fyqP5EW22cRT7VBQzDY85DW2Oxl6xTDnfZARx4aIN6XuTT7n3KkiK+8v01 42bwH5h9+RH8xX3gOZ5ivb26u6ok+F9t/fdsus68+qX5QGSiIWcSQcL3D5UkzgdLppfw 4jCfOSFV1tkyCTzd9laexI0gRd2u2zk+TES9M= MIME-Version: 1.0 Received: by 10.142.252.21 with SMTP id z21mr1506502wfh.111.1285254330229; Thu, 23 Sep 2010 08:05:30 -0700 (PDT) Received: by 10.220.41.203 with HTTP; Thu, 23 Sep 2010 08:05:30 -0700 (PDT) In-Reply-To: References: Date: Thu, 23 Sep 2010 17:05:30 +0200 Message-ID: Subject: Re: [Caml-list] Optional arguments "between" non-optional ones From: Adrien To: bluestorm Cc: Caml Mailing List Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; ocaml:01 swapped:01 compiler:01 restrictive:01 wrote:01 caml-list:01 functions:01 caml:02 argument:02 argument:02 inferred:02 coerce:02 coerce:02 parameter:02 match:02 On 23/09/2010, bluestorm wrote: > (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. I actually expected types (?a:'a -> unit -> unit -> ...) and (unit -> ?a:'a -> unit -> ...) to work alike. I'm wondering why the arguments are "dropped" from the first case but not the second. Also, that's what I've done: I've simply swapped two parameters in a function and it's working well now. > 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. Well spotted. I had gone a bit through the documentation but hadn't seen that. > A fix is to add an annotation when defining h : > > let h (f : _ -> ?a:_ -> _) = > f () () > > # let () = h f;; > bouh! > bouh! > I had tried to add an annotation too but (unit -> unit -> unit). Now, thinking again about it and with your explanation, I understand better why it had failed. I was trying to coerce f into a more restrictive (or simply different?) type but the solution was keep the type of h's argument broader. Thanks. -- Adrien Nader