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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 69CADBC29 for ; Wed, 9 Aug 2006 09:48:29 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k797mQBr018212 for ; Wed, 9 Aug 2006 09:48:26 +0200 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 JAA05758 for ; Wed, 9 Aug 2006 09:48:25 +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.13.6/8.13.6) with ESMTP id k797mNCV018201 for ; Wed, 9 Aug 2006 09:48:24 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k797ghHn001210; Wed, 9 Aug 2006 16:42:45 +0900 (JST) Date: Wed, 09 Aug 2006 16:42:32 +0900 (JST) Message-Id: <20060809.164232.15671006.garrigue@math.nagoya-u.ac.jp> To: Christophe.Troestler@umh.ac.be Cc: caml-list@inria.fr Subject: Re: [Caml-list] format polymorphism From: Jacques Garrigue In-Reply-To: <20060807.013312.243185382.Christophe.Troestler@umh.ac.be> References: <20060807.013312.243185382.Christophe.Troestler@umh.ac.be> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44D9934A.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44D99347.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; polymorphism:01 christophe:01 troestler:01 christophe:01 troestler:01 umh:01 fmt:01 fmt:01 printf:01 printf:01 scanf:01 sscanf:01 well-typed:01 cheers:01 caml-list:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Christophe TROESTLER > Could someone tell me why, say "%s", is of type > > 'a. (string -> 'b, 'a, 'b) format > > instead of > > 'a 'b. (string -> 'b, 'a, 'b) format It clearly has the second type! > I am asking this because if one wants to use the same format string > both for reading and printing in a given function, one needs the > latter type: > > type 'a fmt = { fmt: 'b 'c. ('a,'b,'c) format } > fun (s: _ fmt) -> Printf.printf s.fmt, Scanf.sscanf "string" s.fm With your definition of fmt, you are requiring 'c to be independent from 'a. But If you look at the type of "%s", you see that 'a = string -> 'c, so that {fmt="%s"} is not well-typed. A solution is to define it as type 'a fmt = {fmt: 'b 'c. ('a -> 'b, 'c, 'b) format} The drawback is that only allows formats taking one argument. One could add definitions for any defined number of arguments, but I don't see any generic solution. Cheers, Jacques Garrigue