Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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 '' 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 '':
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
  > ocamlc  -c
  > 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 - -
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: