From: Chris Hecker <checker@d6.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] monomorphic restriction or typing/scanf bug?
Date: Tue, 15 Oct 2002 18:53:09 -0700 [thread overview]
Message-ID: <4.3.2.7.2.20021015183630.0345cb18@mail.d6.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0210151424320.453-100000@grace.speakeasy.net >
[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
next prev parent reply other threads:[~2002-10-16 1:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 3:29 Chris Hecker
2002-10-15 3:51 ` Jacques Garrigue
2002-10-15 12:19 ` Pierre Weis
2002-10-15 21:03 ` Chris Hecker
2002-10-15 21:20 ` Chris Hecker
[not found] ` <Pine.LNX.4.44.0210151424320.453-100000@grace.speakeasy.net >
2002-10-16 1:53 ` Chris Hecker [this message]
2002-10-16 6:42 ` [Caml-list] Local open (was: monomorphic restriction or typing/scanf bug?) Alain Frisch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4.3.2.7.2.20021015183630.0345cb18@mail.d6.com \
--to=checker@d6.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox