Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003938OCaml~DO NOT USE (was: OCaml general)public2005-12-29 10:242016-12-06 22:53
Assigned Toshinwell 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003938: Option to automatically open given modules, as is done for Pervasives.

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.
Attached Files

- Relationships

-  Notes
jroewen (reporter)
2005-12-29 12:19

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

+/- let initial = try
+ 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

+ let _open s = open_libs := s :: !open_libs

+ val _open : string -> unit
+ "-open", Arg.String F._open,
+ "<module> Add <module> to the list of automatically opened modules";

+ val _open : string -> unit

+ let _open s = option_with_arg "-open" s

+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.
Yoric (reporter)
2008-09-08 11:16

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.
shinwell (developer)
2016-12-06 22:53

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

- Issue History
Date Modified Username Field Change
2005-12-29 10:24 jroewen New Issue
2005-12-29 12:19 jroewen Note Added: 0003467
2006-01-05 14:20 doligez Status new => acknowledged
2008-09-08 11:16 Yoric Note Added: 0004599
2013-09-03 17:00 doligez Tag Attached: patch
2016-12-06 22:53 shinwell Note Added: 0016681
2016-12-06 22:53 shinwell Status acknowledged => resolved
2016-12-06 22:53 shinwell Resolution open => fixed
2016-12-06 22:53 shinwell Assigned To => shinwell
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker