Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to automatically open given modules, as is done for Pervasives. #3938

Closed
vicuna opened this issue Dec 29, 2005 · 3 comments
Closed

Option to automatically open given modules, as is done for Pervasives. #3938

vicuna opened this issue Dec 29, 2005 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Dec 29, 2005

Original bug ID: 3938
Reporter: jroewen
Assigned to: @mshinwell
Status: resolved (set by @mshinwell on 2016-12-06T21:53:32Z)
Resolution: fixed
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Tags: patch

Bug description

Hi,

I'd like to see some sort of option to the ocaml compiler to have it automatically 'open' given modules so that values in them are automatically accessible.

Something like -auto-open IO.

The reason for this is that for Desert Spring-Time (DST) to be able to provide some sort of API compatibility with standard O'Caml library, I'd need to be able to have one or two modules automatically opened.

This is because implementing things like IO in ocaml require to break Pervasives API (moving IO out), otherwise to develop the IO module, you end up with the problem of a) not being able to USE pervasives, and b) since pervasives depends on the new module, not being able to use the standard library itself!

So, if say print_endline is moved to IO module for example, all programs compiled for DST will need to add an "open IO" line to each module that uses it. This is not a good thing IMO, as it special cases programs to DST.

If instead, we could add "-auto-open IO" to some ocaml flags in a Makefile for example, this requirement would disappear, essentially providing API compatability between standard ocaml programs on other platforms and DST.

@vicuna
Copy link
Author

vicuna commented Dec 29, 2005

Comment author: jroewen

I don't know how to do a diff, so here's my breakdown of implementing this option again ocaml 3.08.4:

driver/compile.ml:
44:
+/- let initial = try
50:

  • in
  • List.fold_left (fun a b -> try Env.open_pers_signature b a with Not_found -> fatal_error (Printf.sprintf "cannot open cmi for %s" b)) initial !Clflags.open_libs

driver/main.ml:
98:

  • let _open s = open_libs := s :: !open_libs

driver/main_args.ml:
29:

  •  val _open : string -> unit
    

84:

  • "-open", Arg.String F._open,
  •       "<module>  Add <module> to the list of automatically opened modules";
    

driver/main_args.mli:
29:

  •  val _open : string -> unit
    

tools/ocamlcp.ml:
57:

  • let _open s = option_with_arg "-open" s

utils/clflags.ml:
21:
+and open_libs = ref ([] : string list) (* -open *)

As you can see, it's a fairly simple addition, though I suppose it could be abused as an alternative to using open, and would at the very least break ocamldep from finding correct dependencies.

@vicuna
Copy link
Author

vicuna commented Sep 8, 2008

Comment author: Yoric

This feature would be quite nice for Batteries Included, too, although for different reasons: where DST wishes to replace Pervasives with something smaller, we'd like to replace it with something bigger, without altering ocamlc.

At the moment, the only manner I can think of auto-opening a module is to pre-process every single source file and add "open Foo" at the first line. It's a bit wasteful.

@vicuna
Copy link
Author

vicuna commented Dec 6, 2016

Comment author: @mshinwell

The "-open" compiler flag now exists, which presumably solves this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants