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 (11:11)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Even at compile time 2*2=4!

Jakob Lichtenberg wrote:

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

I wish to suggest one possibility.

1) You write a module defining the type of the datastructure 
you wish to precompute and load
2) You write a program importing the above module, which 
computes the datastructure and marshals it to a file. You 
run this program.
3) You write a library which, upon being loaded, searches 
the filesystem for the appropriate file, unmarshals it and 
binds the precomputed data to an identifier.
4) You write your programs referring to the the identifier 
exported by #3.


module: type_of_four.ml
type four = int

module: compute_four.ml
open Type_of_four

let four:four = 2 * 2

let _ = Marshal.to_channel (open_out "foo") four []

module: four.ml
open Type_of_four

let (four:four) = Marshal.from_channel (open_in "foo")

module: sixteen.ml
open Four

let sixteen = four * four


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