From: boos@gr6.u-strasbg.fr (Christian Boos)
To: caml-list@pauillac.inria.fr
Cc: arc@labri.u-bordeaux.fr
Subject: Re: modules local to functions.
Date: Tue, 9 Jan 96 09:04:10 +0100 [thread overview]
Message-ID: <9601090804.AA08645@gr6.u-strasbg.fr> (raw)
In-Reply-To: <9601081207.AA14189@waves.labri.u-bordeaux.fr>
> I have a functor such as follows:
>
> module type Specifyn = sig val n : int end;;
>
> module Makespecific(N:Specifyn) = struct
> type mytype = int
> let mirror () : mytype = N.n
> end;;
>
> I can apply it at the main level like:
>
> module Fred = Makespecific(struct let n = 7 end);;
>
> However, there are cases when I want to define a module in the middle
> of a function (eg a functor of packed binary arrays where I want to (...)
Hello,
I have encountered a similar problem yesterday!
My understanding is that YOU CAN'T do that in CSL at all: functor
application means code generation, and there's no runtime code
generation!
One way to circumvent this problem is to change slightly the semantic
of your argument module, for example:
module type Specifyn = sig val n : unit -> int end
^^^^^^^
This should be not too inconvenient, and almost as simple to use as
yours:
module Makespecific(N:Specifyn) = struct
type mytype = int
let mirror () : mytype = N.n ()
^^
end
let toto_fred_n = ref 10
module Fred = Makespecific(struct let n () = !toto_fred_n end)
let toto digits =
toto_fred_n := digits;
Fred.mirror ()
(This particular solution may even be expressed simpler:
module type Specifyn = sig val n : int ref end
^^^
module Makespecific(N:Specifyn) = struct
type mytype = int
let mirror () : mytype = !N.n
^
end
module Fred_N = struct let n = ref 10 end
module Fred = Makespecific(Fred_N)
let toto digits =
Fred_N.n := digits;
Fred.mirror ()
)
Hope it helps!
Christian
next prev parent reply other threads:[~1996-01-09 16:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-01-08 12:07 Andrew Conway
1996-01-09 8:04 ` Christian Boos [this message]
1996-01-09 9:34 ` Andrew Conway
1996-01-10 15:27 ` Xavier Leroy
1996-01-10 16:22 ` Andrew Conway
1996-01-10 17:08 ` Error message format (was Re: modules local to functions.) Christian Boos
1996-02-16 10:12 ` modules local to functions. (again) Christian Boos
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=9601090804.AA08645@gr6.u-strasbg.fr \
--to=boos@gr6.u-strasbg.fr \
--cc=arc@labri.u-bordeaux.fr \
--cc=caml-list@pauillac.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