caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Grégoire Henry" <henry@pps.univ-paris-diderot.fr>
To: Gerd Stolpmann <info@gerd-stolpmann.de>
Cc: Alain Coste <alaincoste@club-internet.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Why are modules handled differently by the interpreter and the compiler
Date: Mon, 5 Nov 2012 03:30:55 +0100	[thread overview]
Message-ID: <20121105023055.GA26666@mlqds.hnr.gr> (raw)
In-Reply-To: <1351958190.8536.17@samsung>

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

> What could be implemented as an extension is a #use_as_module
> directive that adds the implicit module. This could be in deed
> useful for debugging, especially when it overlooks the mli file if
> present - if you #load, the definition hiding of the mli file takes
> place, and you cannot see unexported definitions anymore. Of course,
> this is sometimes in the way when you test things out.
> 
> Now that compiler-libs is installed this extension could probably
> even be implemented outside the compiler. Anyone up for it?

Well, here it is:

  $ ocamlmktop -o myocaml mod_use.ml
  $ cat test.ml
  let x = 53
  $ ./myocaml
        OCaml version 4.00.1

  # #mod_use "test.ml";;
  module Test : sig val x : int end
  # Test.x;;
  - : int = 53

Regards,
Grégoire

[-- Attachment #2: mod_use.ml --]
[-- Type: text/plain, Size: 935 bytes --]


open Parsetree

let filter_out_directives lb =
  List.concat
    (List.map
       (function
         | Ptop_def s -> s
         | Ptop_dir _ -> [])
       lb)

let parse_mod_use_file parse_use_file name lb =
  let modname =
    String.capitalize (Filename.chop_extension (Filename.basename name))
  in
  let items = filter_out_directives (parse_use_file lb) in
  [ Ptop_def
      [{pstr_desc =
        Pstr_module ( Location.mknoloc modname ,
                      { pmod_desc = Pmod_structure items;
                        pmod_loc = Location.none } );
        pstr_loc = Location.none }] ]

let dir_mod_use name =
  let parse_use_file = !Toploop.parse_use_file in
  Toploop.parse_use_file := parse_mod_use_file parse_use_file name;
  ignore (Toploop.use_file Format.std_formatter name);
  Toploop.parse_use_file := parse_use_file

let () =
  Hashtbl.add Toploop.directive_table "mod_use"
    (Toploop.Directive_string dir_mod_use)

  reply	other threads:[~2012-11-05  2:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-03 15:21 Alain Coste
2012-11-03 15:34 ` Didier Cassirame
2012-11-03 15:55   ` Didier Cassirame
2012-11-03 15:58     ` Didier Cassirame
2012-11-03 16:52     ` Alain Coste
2012-11-03 17:14       ` Gabriel Scherer
2012-11-03 15:56 ` AW: " Gerd Stolpmann
2012-11-05  2:30   ` Grégoire Henry [this message]
2012-11-05 11:23     ` Gerd Stolpmann
2012-11-05 19:53     ` Alain Coste

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=20121105023055.GA26666@mlqds.hnr.gr \
    --to=henry@pps.univ-paris-diderot.fr \
    --cc=alaincoste@club-internet.fr \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.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).