caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Replacing Pervasives?
@ 2008-09-08  8:06 David Teller
  2008-09-08  9:17 ` [Caml-list] " David Teller
  2008-09-08 21:03 ` Richard Jones
  0 siblings, 2 replies; 8+ messages in thread
From: David Teller @ 2008-09-08  8:06 UTC (permalink / raw)
  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. 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08  8:06 Replacing Pervasives? David Teller
@ 2008-09-08  9:17 ` David Teller
  2008-09-08 10:04   ` Romain Bardou
  2008-09-08 21:03 ` Richard Jones
  1 sibling, 1 reply; 8+ messages in thread
From: David Teller @ 2008-09-08  9:17 UTC (permalink / raw)
  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


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08  9:17 ` [Caml-list] " David Teller
@ 2008-09-08 10:04   ` Romain Bardou
  2008-09-08 10:51     ` David Teller
  0 siblings, 1 reply; 8+ messages in thread
From: Romain Bardou @ 2008-09-08 10:04 UTC (permalink / raw)
  To: David Teller; +Cc: 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08 10:04   ` Romain Bardou
@ 2008-09-08 10:51     ` David Teller
  2008-09-08 15:06       ` Romain Bardou
  0 siblings, 1 reply; 8+ messages in thread
From: David Teller @ 2008-09-08 10:51 UTC (permalink / raw)
  To: Romain Bardou; +Cc: 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. 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08 10:51     ` David Teller
@ 2008-09-08 15:06       ` Romain Bardou
  2008-09-08 17:35         ` David Teller
  0 siblings, 1 reply; 8+ messages in thread
From: Romain Bardou @ 2008-09-08 15:06 UTC (permalink / raw)
  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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08 15:06       ` Romain Bardou
@ 2008-09-08 17:35         ` David Teller
  2008-09-08 20:40           ` Stefano Zacchiroli
  0 siblings, 1 reply; 8+ messages in thread
From: David Teller @ 2008-09-08 17:35 UTC (permalink / raw)
  To: Romain Bardou; +Cc: 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. 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08 17:35         ` David Teller
@ 2008-09-08 20:40           ` Stefano Zacchiroli
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Zacchiroli @ 2008-09-08 20:40 UTC (permalink / raw)
  To: OCaml

On Mon, Sep 08, 2008 at 07:35:04PM +0200, David Teller wrote:
> 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).
> Technically, it fails because you have to name your new module
> Pervasives and thus cause a conflict with the original Pervasives.

Why you need to have the legacy Pervasives around? You can remove it
and/or include what you need of it in your customized Pervasives, can't
you? That wouldn't violate your requirement of messing around with
ocamlc code, you would only do that with the standard library source
files.

> > Basically, just use any hack which can replace your ocamlc by a script 
> > which adds "open Myperv;;\n" before calling ocamlc ^^
> 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 :/

You can use a shell script (or a real program) of your which first
invokes camlp4 as a filter and first feeds into it myprefix.ml and after
that the real file. More generally your custom program can combine
together a pipeline of any number of preprocessors.

Cheers.

-- 
Stefano Zacchiroli -*- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
I'm still an SGML person,this newfangled /\ All one has to do is hit the
XML stuff is so ... simplistic  -- Manoj \/ right keys at the right time


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Replacing Pervasives?
  2008-09-08  8:06 Replacing Pervasives? David Teller
  2008-09-08  9:17 ` [Caml-list] " David Teller
@ 2008-09-08 21:03 ` Richard Jones
  1 sibling, 0 replies; 8+ messages in thread
From: Richard Jones @ 2008-09-08 21:03 UTC (permalink / raw)
  To: David Teller; +Cc: OCaml

On Mon, Sep 08, 2008 at 10:06:06AM +0200, David Teller wrote:
>  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.

Have a look at the source to xavierbot, which obliterates large parts
of the standard library when it starts up (for security reasons).

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-09-08 21:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-08  8:06 Replacing Pervasives? David Teller
2008-09-08  9:17 ` [Caml-list] " David Teller
2008-09-08 10:04   ` Romain Bardou
2008-09-08 10:51     ` David Teller
2008-09-08 15:06       ` Romain Bardou
2008-09-08 17:35         ` David Teller
2008-09-08 20:40           ` Stefano Zacchiroli
2008-09-08 21:03 ` Richard Jones

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).