Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Replacing Pervasives?

0 views
Skip to first unread message

David Teller

unread,
Sep 8, 2008, 4:07:22 AM9/8/08
to OCaml
Dear list,

Does anyone know how I can get a module to be auto-opened by the
compiler, in the same vein as Pervasives? I would very much prefer not
having to tweak around the source code of ocamlc for this purpose.

Thanks,
David

--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Angry researcher: French Universities need reforms, but the LRU act brings liquidations.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

David Teller

unread,
Sep 8, 2008, 5:17:49 AM9/8/08
to OCaml
Technically, I guess I can write a Camlp4 extension just to add "open
Foo" at the beginning of every file, but it seems a bit complex for such
a simple task. Any other idea?

Thanks,
David

Romain Bardou

unread,
Sep 8, 2008, 6:04:20 AM9/8/08
to David Teller, OCaml
David Teller a écrit :

> Technically, I guess I can write a Camlp4 extension just to add "open
> Foo" at the beginning of every file, but it seems a bit complex for such
> a simple task. Any other idea?
>
> Thanks,
> David
>
>
> On Mon, 2008-09-08 at 10:06 +0200, David Teller wrote:
>> Dear list,
>>
>> Does anyone know how I can get a module to be auto-opened by the
>> compiler, in the same vein as Pervasives? I would very much prefer not
>> having to tweak around the source code of ocamlc for this purpose.
>>
>> Thanks,
>> David
>>

I guess you could try and make your own stdlib directory, and then call
ocamlc using:

ocamlc -nostdlib -I mystdlib

or something like that...

--
Romain Bardou

David Teller

unread,
Sep 8, 2008, 6:53:23 AM9/8/08
to Romain Bardou, OCaml
Would that open anything by default?


On Mon, 2008-09-08 at 12:04 +0200, Romain Bardou wrote:
> I guess you could try and make your own stdlib directory, and then
> call
> ocamlc using:
>
> ocamlc -nostdlib -I mystdlib
>
> or something like that...
>
--

David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Angry researcher: French Universities need reforms, but the LRU act
brings liquidations.

_______________________________________________

Romain Bardou

unread,
Sep 8, 2008, 11:06:25 AM9/8/08
to OCaml
David Teller a écrit :

> Would that open anything by default?
>
>
> On Mon, 2008-09-08 at 12:04 +0200, Romain Bardou wrote:
>> I guess you could try and make your own stdlib directory, and then
>> call
>> ocamlc using:
>>
>> ocamlc -nostdlib -I mystdlib
>>
>> or something like that...
>>

My guess is that it would try to open mystdlib/Pervasives.cmo...

In other word it's as if you changed your "official"
stdlib/Pervasives.cmo except that it's cleanier as you don't actually
override it (which would change your Pervasives for all your projects).

I didn't try it though, so maybe I'm missing something.

Another way to automatically open your module would be to do a weird
Makefile such as:

%.cmo: %.ml
echo "open Myperv;;\n" > $*.temp.ml
cat $*.ml >> $*.temp.ml
ocamlc -c $*.temp.ml -o $*.cmo
rm $*.temp.ml

Or you could do this using some Ocamlbuild plug-in, or just by using the
-ocamlc option of Ocamlbuild...

Basically, just use any hack which can replace your ocamlc by a script
which adds "open Myperv;;\n" before calling ocamlc ^^

--
Romain Bardou

David Teller

unread,
Sep 8, 2008, 1:35:07 PM9/8/08
to Romain Bardou, OCaml
On Mon, 2008-09-08 at 17:06 +0200, Romain Bardou wrote:
> In other word it's as if you changed your "official"
> stdlib/Pervasives.cmo except that it's cleanier as you don't actually
> override it (which would change your Pervasives for all your projects).
>
> I didn't try it though, so maybe I'm missing something.

Well, I did :)
Technically, it fails because you have to name your new module
Pervasives and thus cause a conflict with the original Pervasives.

> Basically, just use any hack which can replace your ocamlc by a script
> which adds "open Myperv;;\n" before calling ocamlc ^^

Yes, that's the kind of things I have in mind.
Unfortunately, it seems that ocamlc only supports one "-pp" tag. So if I
use a simple "-pp 'cat myprefix.ml'", I become incompatible with
Camlp4 :/

Any other idea?

Cheers,
David

--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
Angry researcher: French Universities need reforms, but the LRU act brings liquidations.

_______________________________________________

0 new messages