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 DAA16137; Wed, 16 Oct 2002 03:53:07 +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 DAA15896 for ; Wed, 16 Oct 2002 03:53:06 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g9G1r5D18651 for ; Wed, 16 Oct 2002 03:53:05 +0200 (MET DST) Received: (qmail 19864 invoked from network); 16 Oct 2002 01:53:02 -0000 Received: from node-d8e9cca2-sfo-onnet.worldcom.com (HELO checkerlap.d6.com) (216.233.204.162) by relay1.pair.com with SMTP; 16 Oct 2002 01:53:02 -0000 X-pair-Authenticated: 216.233.204.162 Message-Id: <4.3.2.7.2.20021015183630.0345cb18@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Tue, 15 Oct 2002 18:53:09 -0700 To: caml-list@inria.fr From: Chris Hecker Subject: Re: [Caml-list] monomorphic restriction or typing/scanf bug? In-Reply-To: References: <4.3.2.7.2.20021015135925.033299e8@mail.d6.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [Brian sent this to me privately, but it was a good point I forgot about, so I'm replying publicly.] At 14:31 10/15/2002 -0700, brogoff@speakeasy.net wrote: >On Tue, 15 Oct 2002, Chris Hecker wrote: > > Now, if only we could have local exceptions to make those "C break-like > > exception patterns" easier! >Why do the exceptions need anything more than module locality, especially >when function locality can be achieved with local modules? Ack, I forgot about that solution, and forgot the specifics of the fact that I asked about this and there was a thread about it over a year ago: http://groups.google.com/groups?th=6f10c8b9743e7f20 I actually didn't forget that I asked, but for some reason I thought the restrictions on types escaping the local modules applied to exceptions as well. Oops! Thanks for pointing it out! Of course, as that thread says, "let exception Blah" would be nice, or "local open" to make this pattern nicer to work with. Anyway, using all of the ideas from this thread leads me to the following simple answer to my earlier post (which is closely related to the earlier post about scanf in pattern matching): type t = Foo of int | Bar of int * int let test line = let module Scan = struct exception Result of t let scan s fmt f = try raise (Result (Scanf.sscanf s fmt f)) with End_of_file | Scanf.Scan_failure _ -> () end in try Scan.scan line "Foo %d" (fun i -> Foo i); Scan.scan line "Bar %d %d" (fun i j -> Bar (i,j)); failwith "bad line" with Scan.Result t -> t # test "Foo 1";; - : t = Foo 1 # test "Bar 1 2";; - : t = Bar (1, 2) # test "Bar 1";; Exception: Failure "bad line". Chris ------------------- 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