Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Andrew Conway <arc@labri.u-bordeaux.fr>
To: caml-list@pauillac.inria.fr
Cc: boos@gr6.u-strasbg.fr (Christian Boos)
Subject: Re: modules local to functions.
Date: Tue, 09 Jan 1996 10:34:00 +0100	[thread overview]
Message-ID: <9601090934.AA21977@waves.labri.u-bordeaux.fr> (raw)
In-Reply-To: Your message of "Tue, 09 Jan 1996 09:04:10 +0100." <9601090804.AA08645@gr6.u-strasbg.fr>



I wrote:

> > 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 (...)

Christian Boos commented:

>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!

Ah. I expected (though I hadn't looked into the code at all) that
a run time structure creation (eg struct let n = variable end) was
very similar to the creation of a tuple/normal structure, just requiring
sticking some values into a block of memory. I then expected that a 
module creation from a functor was very similar to a partial function
application, (with perhaps a bit of execution) and could thus be done 
at run time (as distinct from, say C++ templates which produce specialised 
code for each application).

But it may well be significantly more complex than that.

> One can get around the problem by defining n as a function or reference
> and changing it dynamically.

Ugh! I hadn't thought of that, and it is a good idea even if just
a little inelegant. Unfortunately it is not appropriate in my case as
I have several values in the structure which get defined when the module
is created and which depend on n...ie:


    module Makespecific(N:Specifyn) = struct
       type mytype = int
       let computednumber = complexfunction N.n 
       let mirror () : mytype = computednumber
    end

and I only want to call complexfunction once for each module instantiation.

Of course, I could make "computednumber" a reference, and I could have
a function "change_n_and_recompute_everything", but again it is an inelegant
solution that is hard to understand, and I end up with "!"s all over the
code for no algorithmically justifyable reason.

Yeah yeah, I know I am being picky...

Thanks,

Andrew.





  reply	other threads:[~1996-01-09 17:58 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
1996-01-09  9:34   ` Andrew Conway [this message]
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=9601090934.AA21977@waves.labri.u-bordeaux.fr \
    --to=arc@labri.u-bordeaux.fr \
    --cc=boos@gr6.u-strasbg.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