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 EAA12753; Tue, 15 Oct 2002 04:41:26 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA12760 for ; Tue, 15 Oct 2002 04:41:25 +0200 (MET DST) Received: from plinky.bolt-action.com (node-d8e9cca3-sfo-onnet.worldcom.com [216.233.204.163]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9F2fLD16851 for ; Tue, 15 Oct 2002 04:41:24 +0200 (MET DST) Received: from CHECKERATH (node-d8e9cca2-sfo-onnet.worldcom.com [216.233.204.162]) by plinky.bolt-action.com (8.11.6/8.9.3) with SMTP id g9F3TAX26896 for ; Mon, 14 Oct 2002 20:29:10 -0700 Date: Mon, 14 Oct 2002 20:29:10 -0700 Message-Id: <200210150329.g9F3TAX26896@plinky.bolt-action.com> From: Chris Hecker To: caml-list@inria.fr Subject: [Caml-list] monomorphic restriction or typing/scanf bug? Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. Chris type t = Foo of int | Bar of int * int exception FB of t (* works *) let scan s (fmt : ('a, Scanf.Scanning.scanbuf, 'b) format) f = try raise (FB (Scanf.sscanf s fmt f)) with End_of_file | Scanf.Scan_failure _ -> () let test () = let line = "Foo 1" 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 (* doesn't work *) let test2 () = let line = "Foo 1" in let scan s (fmt : ('a, Scanf.Scanning.scanbuf, 'b) 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 ------------------- 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