From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pAS5tSp0005848 for ; Mon, 28 Nov 2011 06:55:30 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AigBADUh007RVdK2mGdsb2JhbABEqn0IIgEBAQEBCAkNBxQlgXIBAQEDARICExMGATgBAwELAQUFNBI0AQUBHAYuB4djmGwKjkmEF4kuAgUKiXVjBIgfjCuGcYZnPYFLgjo X-IronPort-AV: E=Sophos;i="4.69,582,1315173600"; d="scan'208";a="132897009" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Nov 2011 06:55:29 +0100 Received: by iakl21 with SMTP id l21so13550849iak.27 for ; Sun, 27 Nov 2011 21:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=eTDzUqOxrOHi+DDtV8LQwFIgYySukegyurKT9tjPti8=; b=Kzd7yhf8fMpbaX28hK8NV1iOlh/q9swQ1SgwaKcuK99cuO7moTSYX2tGarn81fQG5S WlUM9/txAclu2FaKIDMoPzD39T5797WT4+Vo0PGZj7PA9WOZ2VwiW/TanDtNkxMOJtV2 WtktFvtUwgZ42bj5SKou0tg09g9gNOx2ueiM8= Received: by 10.42.148.136 with SMTP id r8mr22301713icv.1.1322459728364; Sun, 27 Nov 2011 21:55:28 -0800 (PST) Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp. [58.158.128.157]) by mx.google.com with ESMTPS id eh34sm41477498ibb.5.2011.11.27.21.55.25 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 27 Nov 2011 21:55:27 -0800 (PST) Sender: Jacques Garrigue Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: Date: Mon, 28 Nov 2011 14:55:23 +0900 Cc: =?utf-8?Q?Markus_W=2E_Wei=C3=9Fmann?= , caml-list@inria.fr Content-Transfer-Encoding: 7bit Message-Id: References: To: Gabriel Scherer X-Mailer: Apple Mail (2.1084) Subject: Re: [Caml-list] 3.13.0 stricter on interfaces? (building extlib) On 2011/11/26, at 19:33, Gabriel Scherer wrote: > There is a slighlt misinterpretation in your analysis of the issue: > the problem comes from the fact that OCaml 3.13 standard library has > added a ?seed optional parameter to the Hashtbl.create > method. Extlib's interface still assumes <=3.12 interface with no > parameter (and in particular didn't change this function interface), > and tries to check the new Hashtbl.create standard function with the > old (int -> ('a,'b) t) interface. > > In particular, this problem does *not* come from a change of behavior > of the typer, only from libraries changing. > (And the change is on stdlib's side, not extlib's.) Indeed, the compiler never erases optional arguments to match a specific signature. > The OCaml manual is not very explicit about implicit coercions > regarding optional arguments: > >> Normally the compiler generates a type error if you attempt to pass >> to a function a parameter whose type is different from the expected >> one. 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. > > It seems that in some cases it is able to convert from `?x:foo -> bar` > to `bar`. Indeed: > > # (fun (f : int -> int) -> f 3) (fun ?(x=0) y -> x+y);; > - : int = 3 > > However, this doesn't seem to work when checking interfaces: Indeed again, as written in the manual, this specific case only concerns functions passed as function argument. This is not the case of exports from a module. More precisely, in 3.12 this applies only to function arguments and record fields, in trunk this applies also to variant arguments (both normal and polymorphic) and to explicit type annotations. > Here are are a few ways this issue could be resolved: > > 1. the stdlib could change to revert to the old interface, adding > a `create_seed` function > > 2. extlib could introduce a conditional compilation trick to support > either interfaces depending on OCaml version; ugly and painful to > deal with in ocamldoc > > 3. instead of repeating `val create : int -> ('a, 'b) t` in its own > interface, extlib could include (module type of Hashtbl) (referring > to stdlib's Hashtbl module). This way, their interface would keep in > synch with stdlib's change, and they would have to change their > implementation correspondingly. There is another solution which works with all versions of OCaml 4. In extHashtbl.ml, add the following line let create x = create x This will discard optional arguments. People who need the full version can get it from the standard library. Jacques Garrigue