From: Alain Frisch <frisch@clipper.ens.fr>
To: Chris Hecker <checker@d6.com>
Cc: caml-list@inria.fr
Subject: [Caml-list] Local open (was: monomorphic restriction or typing/scanf bug?)
Date: Wed, 16 Oct 2002 08:42:59 +0200 (MET DST) [thread overview]
Message-ID: <Pine.SOL.4.44.0210160836250.25523-100000@clipper.ens.fr> (raw)
In-Reply-To: <4.3.2.7.2.20021015183630.0345cb18@mail.d6.com>
On Tue, 15 Oct 2002, Chris Hecker wrote:
> Of course, as that thread says, "let exception Blah" would be nice, or
> "local open" to make this pattern nicer to work with.
cf http://www.eleves.ens.fr/home/frisch/soft#openin
With the syntax extension below, you can do:
glouglou ~/openin $ ocaml camlp4o.cma pa_openin.cmo
Objective Caml version 3.06
Camlp4 Parsing version 3.06
# let () = open Unix in ();;
# let () = struct exception E end in raise E;;
Exception: E.
That is: local open and local structure items.
Of course, you get ugly error messages when trying to have a type escape
its scope:
# let () = struct type t = A end in A;;
This `let module' expression has type OPENIN_5.t
In this type, the locally bound module name OPENIN_5 escapes its scope
Here is the code of the syntax extension:
let no = ref 0
let local_struct loc st e =
incr no;
let x = "OPENIN_" ^ (string_of_int !no) in
let st = st @ [<:str_item< value res = $e$ >>] in
<:expr< let module $x$ = struct $list: st$ end in ($uid:x$.res) >>
EXTEND
GLOBAL: Pcaml.expr;
Pcaml.expr: LEVEL "expr1" [
[ "open"; i = LIST1 UIDENT SEP "."; "in";
e = Pcaml.expr LEVEL "top" ->
local_struct loc [<:str_item< open $i$ >>] e
| "struct"; st = LIST0 [ s = Pcaml.str_item; OPT ";;" -> s ]; "end";
"in";
e = Pcaml.expr LEVEL "top" ->
local_struct loc st e
]
];
END
-- Alain
-------------------
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
prev parent reply other threads:[~2002-10-16 6:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-15 3:29 [Caml-list] monomorphic restriction or typing/scanf bug? 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
2002-10-16 6:42 ` Alain Frisch [this message]
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=Pine.SOL.4.44.0210160836250.25523-100000@clipper.ens.fr \
--to=frisch@clipper.ens.fr \
--cc=caml-list@inria.fr \
--cc=checker@d6.com \
/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