caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus@oefai.at>
To: Andreas Rossberg <rossberg@ps.uni-sb.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] choosing modules at runtime
Date: Tue, 24 Sep 2002 12:37:41 +0200	[thread overview]
Message-ID: <20020924103741.GB31883@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <3D90321D.DEFBF3AA@ps.uni-sb.de>

Andreas Rossberg schrieb am Dienstag, den 24. September 2002:
> It's not too bad, just do:
> 
>  let (algoA, algoB, algoC) =
>    if (use algorithm 1) then
>    (M_1.algoA, M_1.algoB, M_1.algoC)
>    else if (use algorithm 2) then
>    (M_2.algoA, M_2,algoB, M_2.algoC) ...
> 
> But admittedly it still is somewhat annoying.

Especially if you have many more than three functions.

Even worse, if the modules are generated locally, they might involve
abstract types not visible outside. It could be legal to combine these
functions to generate something that is concrete in another context,
but the type system won't allow you to escape scopes, e.g.:

  module type M = sig
    type t
    val v : t
    val to_int : t -> int
  end

  module Func (Arg : M) : M = struct
    include Arg
  end

  let f x =
    let module Arg = struct
      type t = int
      let v = x
      let to_int x = x end in
    let module MyMod = Func (Arg) in
    MyMod.v, MyMod.to_int

  let _ =
    let v, to_int = f 42 in
    print_int (to_int v)

The compile will print the following error:

  File "foo.ml", line 12, characters 2-143:
  This `let module' expression has type Func(Arg).t * (Func(Arg).t -> int)
  In this type, the locally bound module name Arg escapes its scope

If we could return the whole module "MyMod" instead (much more convenient
than returning a tuple anyway), the context (i.e. the one including the
abstract type) could be always provided at the place of use.

> Such a feature is not impossible to add, but represents a significant
> complication of the language that may not be considered worthwhile.

It would be interesting to learn, how many people could really need
first class modules already now. Then we'd see whether the complication
is worthwhile or not. If it doesn't take a Herculean effort to implement
them, I'd find them useful enough. Of course, if INRIA has even better
things to do implement now, I won't mind... ;-)

Best regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
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


  reply	other threads:[~2002-09-24 10:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-24  8:48 Henri Dubois-Ferriere
2002-09-24  9:36 ` Andreas Rossberg
2002-09-24 10:37   ` Markus Mottl [this message]
2002-09-24 10:08 ` Markus Mottl
2002-09-24 10:18 ` Olivier Andrieu
2002-09-24 17:24   ` Sven LUTHER
2002-09-24 10:42 ` Yamagata Yoriyuki
2002-09-24 12:43 ` Alessandro Baretta
2002-09-24 12:55   ` Maxence Guesdon
2002-09-24 10:40 Sebastien.deMentendeHorne
2002-09-24 11:00 ` Markus Mottl
2002-09-24 11:09 Sebastien.deMentendeHorne
2002-09-24 11:41 ` Markus Mottl
2002-09-30  7:28   ` John Max Skaller
2002-10-02 13:04     ` Alessandro Baretta
2002-10-02 13:28       ` Dave Mason
2002-10-02 20:57         ` Chris Hecker

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=20020924103741.GB31883@fichte.ai.univie.ac.at \
    --to=markus@oefai.at \
    --cc=caml-list@inria.fr \
    --cc=rossberg@ps.uni-sb.de \
    /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).