caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andrew Conway <arc@labri.u-bordeaux.fr>
To: Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: caml-list@pauillac.inria.fr
Subject: Re: modules local to functions.
Date: Wed, 10 Jan 1996 17:22:32 +0100	[thread overview]
Message-ID: <9601101622.AA09726@waves.labri.u-bordeaux.fr> (raw)
In-Reply-To: Your message of "Wed, 10 Jan 1996 16:27:22 +0100." <199601101527.QAA22663@pauillac.inria.fr>



I wrote a while ago:

> However, there are cases when I want to define a module in the middle
> of a function [...] That is, I would like to be abe to do:

Xavier Leroy replied:

>I still need to be convinced of the usefulness of local functor
>applications (Andrew Conway's example was too sketchy to illuminate me),
>but it can definitely be done.

OK, here comes my attempt.

I want to write a function that uses a large number of arrays as a
essential part of its process. These arrays contain small positive
values, in a range specified in the function (eg 0 to 2). As these
arrays are copied around very frequently, and memory consumption
is significant, it is worth while having them as a packed array.

So, I implemented a packed array functor that takes as arguement
the number of bits needed, and returns a module implementing that
packed array.

I would like the code to be as memory efficient as reasonably possible, and 
so, for instance, when the range is 0 to 1, the packed array should be of
just one bit per location.

[ I am using it in a dynamic programming problem. It already wants to use more
  than the available memory, so I have to sacrifice time for memory already.
  Packing from 2 bits to 1 bits roughly divides the execution time by a 
  factor of 4. And no, I can't see a significantly better algorithm 
  unfortunately, and it is not from a lack of looking. ]

There are other parameters to the function, and I would like to make
a table of the value of the function for all parameters. 

At the moment what I do is declare (at file scope) a module PA with
a fixed number of bits. I then generate that section of the table
that can be done efficiently with that sized packed array. I then 
edit the source, recompile with a different sized packed array, 
and print out another section of the table, etc.

This multiple-recompilation is an annoyance. In this particular case
it is not a major problem as I only want to do it a few times (and
a few times for debugging, and a few times when I change the function
slightly). However, it is a real example of when declaring a module
inside a function would significantly increase the straightforward 
expressability of the language.

[ Note: I am aware that there are lots of work arounds, and in particular
  that one could regard functors as syntactic sugar, but they are very nice
  syntactic sugar for a really ugly alternative. ]

Andrew.








  reply	other threads:[~1996-01-10 17:43 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
1996-01-10 15:27 ` Xavier Leroy
1996-01-10 16:22   ` Andrew Conway [this message]
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=9601101622.AA09726@waves.labri.u-bordeaux.fr \
    --to=arc@labri.u-bordeaux.fr \
    --cc=Xavier.Leroy@inria.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;
as well as URLs for NNTP newsgroup(s).