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 FAA13345; Tue, 15 Oct 2002 05:52:01 +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 FAA13760 for ; Tue, 15 Oct 2002 05:52:00 +0200 (MET DST) Received: from psyche.kaba.or.jp (psyche.kaba.or.jp [202.249.19.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9F3ps510587 for ; Tue, 15 Oct 2002 05:51:58 +0200 (MET DST) Received: from mail.kaba.or.jp (cascade.kaba.or.jp [202.249.19.34]) by psyche.kaba.or.jp (Postfix) with ESMTP id 448A822B9C; Tue, 15 Oct 2002 12:51:52 +0900 (JST) Received: from localhost (erg.kaba.or.jp [202.249.19.58]) by mail.kaba.or.jp (Postfix) with ESMTP id 12B3449A89; Tue, 15 Oct 2002 12:51:51 +0900 (JST) To: checker@d6.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] monomorphic restriction or typing/scanf bug? In-Reply-To: <200210150329.g9F3TAX26896@plinky.bolt-action.com> References: <200210150329.g9F3TAX26896@plinky.bolt-action.com> 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: <20021015125124J.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 15 Oct 2002 12:51:24 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Chris Hecker > The "scan" function in the code below works if it's at global scope, > but not if it's defined inside the test2 function. Is this a bug or a > typing restriction? I assume the latter (and that I could have boiled > this example to one of the ones in the FAQ?), but I don't understand > these kinds of polymorphism typing issues. This is a known issue: named type variables inside an expression are restricted to be monomorphic for the whole toplevel expression. They can only be generalized afterwards. (This is to ensure that two identical variable names in an expression refer to the same variable) The standard workaround is to use nameless ones. > (* this works *) > let test2 () = > let line = "Foo 1" in > let scan s (fmt : (_, Scanf.Scanning.scanbuf, _) format) f = > try > raise (FB (Scanf.sscanf s fmt f)); > () > with > End_of_file | Scanf.Scan_failure _ -> () > in > try > scan line "Foo %d" (fun i -> Foo i); > scan line "Bar %d %d" (fun i j -> Bar (i,j)); > failwith "bad line" > with > FB t -> t 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