English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Even at compile time 2*2=4!
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-19 (10:46)
From: Jakob Lichtenberg <jakob.lichtenberg@a...>
Subject: [Caml-list] Even at compile time 2*2=4!
Fellow O'Caml hackers,

I have this complicated module 'fourLib.ml' that binds the value 'four' to
the *computed* value of four:
let four = (Printf.printf "Now we do the complicated calculation of
            let res = 2*2
            in res);

A sample application 'sixteen.ml':
let _ = Printf.printf "4 * 4  is %d" (FourLib.four * FourLib.four);

I wish to package/compile my 'fourLib' so that I can avoid doing the
complicated calculation '2*2' each and every time I load 'fourLib'.  (I am
sure that you can imagine an even more requiring computational task than
evaluating '2*2'.)

Currently I build as follows:
  > ocamlc -c fourLib.ml
  > ocamlc  -c sixteen.ml
  > ocamlc -o sixteen fourLib.cmo sixteen.cmo

Unfortunately 2*2 is first calculated when I run the application:
  > ./sixteen
  Now we do the complicated calculation of 2*2...
  4 * 4  is 16

1. I am willing to rewrite the library, the way stuff is build, etc....  I
basically just want ocaml to evaluate 2*2 before the final linking.  Is my
only hope to serialize Four.four and then load it?

2. Can I build a new top-level interactive environment 'ocaml_with_fourLib'
where this module is 'pre-loaded'.  Again, the actual calculation of 2*2
should be done when I build ocaml_with_fourLib - not when I start it.


- Jakob Lichtenberg

Jakob Lichtenberg - jl@itu.dk - http://www.itu.dk/people/jl/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners