From: Anton Moscal <msk@post.tepkom.ru>
To: John Prevost <j.prevost@cs.cmu.edu>
Cc: caml-list@inria.fr
Subject: Re: Local opening of modules
Date: Tue, 10 Nov 1998 19:04:45 +0300 (MSK) [thread overview]
Message-ID: <Pine.LNX.4.03.9811101745250.27072-100000@post.tepkom.ru> (raw)
In-Reply-To: <Pine.LNX.3.95L.981027152714.13499A-100000@naiad.fac.cs.cmu.edu>
On Tue, 27 Oct 1998, John Prevost wrote:
> This is a question that I found asked back in the logs, but which I
> found no answer to:
>
> Is there any good reason that Caml doesn't have a mechanism like SML's
> to open a module locally? For example:
>
> let open Num in
> let a = num_of_int 2739 in
> let b = num_of_int 234 in
> let bar = a +/ b;;
>
[...]
>
> Maybe there's a technical constraint in the way Caml is organized that
> keeps this from being done?
>
With CamlP4 preprocessor (tool for syntax extension of Ocaml) I got
this effect by the following grammar extension:
====cut====
let (uniq_lid, uniq_uid) =
let cnt = ref 0 in
(incr cnt; fun () -> Printf.sprintf "l_uniq_id_%d" !cnt),
(incr cnt; fun () -> Printf.sprintf "U_uniq_id_%d" !cnt)
EXTEND
expr: LEVEL "expr1"
[[
"let"; "open"; path = LIST1 UIDENT SEP "."; "in"; e = expr LEVEL "top" ->
let temp = uniq_uid ()
and res = uniq_lid ()
in
<:expr< let module $temp$ =
struct open $path$; value $lid:res$ = $e$; end in $uid:temp$.$lid:res$
>>
]];
END
====cut====
After making these changes you can write in your program something like:
====cut====
module M = struct
module N = struct let x = 1 end;;
end
let x = let open M.N in x
====cut====
Regards,
Anton
next prev parent reply other threads:[~1998-11-12 7:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-27 20:35 John Prevost
1998-11-10 16:04 ` Anton Moscal [this message]
1998-11-10 21:22 ` John Prevost
1998-11-25 15:17 ` Objects as sums Anton Moscal
1998-11-26 15:58 ` Didier Remy
1998-11-28 10:46 ` Anton Moscal
1998-11-30 12:35 ` Jerome Vouillon
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.LNX.4.03.9811101745250.27072-100000@post.tepkom.ru \
--to=msk@post.tepkom.ru \
--cc=caml-list@inria.fr \
--cc=j.prevost@cs.cmu.edu \
/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