From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA19279; Fri, 4 Apr 2003 02:36:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA19236 for ; Fri, 4 Apr 2003 02:36:22 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h340aK528491 for ; Fri, 4 Apr 2003 02:36:21 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2/3.7W) with ESMTP id JAA05019; Fri, 4 Apr 2003 09:36:11 +0900 (JST) To: francois@rouaix.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] mystified by typing of optional arguments In-Reply-To: References: X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030404093611O.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 04 Apr 2003 09:36:11 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Spam: no; 0.00; jacques:01 caml-list:01 typable:01 inference:01 -principal:01 ocamlc:01 principality:01 3.06:01 val:01 3.06,:01 ocaml:01 caml:01 int:01 garrigue:01 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Francois Rouaix > Hi all, > The following example mystifies me > > let f ?opt x = > match opt with > | None -> x > | Some dx -> x + dx > > let g x = x + 1 > > > let h1 = function > | 0 -> [g] > | _ -> [f; g] > > > let h2 = function > | _ -> [f; g] > > > h1 is typable but not h2. > Why is that ? As stated in many places in the manual, type inference for optional arguments is not principal. But there is a now a -principal option to ocaml and ocamlc, which attempts to recover principality, and gives more information in such cases. % ocaml -principal Objective Caml version 3.06+27 (2003-03-31) [...] # let h1 = function | 0 -> [g] | _ -> [f; g] ^ ;; Warning: Eliminated optional argument without principality val h1 : int -> (int -> int) list = Note that -principal itself is available in ocaml 3.06, but would not provide the above warning. Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners