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
How to cleanly encode "quasi-constants"?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-06-26 (10:20)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: How to cleanly encode "quasi-constants"?
> I have a question about this : is there a way to make easily a compile
> time constants?
> (if i have a let var = func constant_argument, and i know that this
> can't change from an execution to an other, i want it to be evaluated
> only once)
> -- 
> Rémi Vanicat

When you have a definition in a program as:

 let var = func constant_argument;;

then the value to bind to var is evaluated once and for all, i.e.
the expression ``func constant_argument'' will be evaluated and its
value bound to var.

Strictly speaking, this is not evaluated at compiled time: it is
evaluated at ``launch time'' when the program is initialized. In
effect this cannot be evaluated at compile time, since it would
necessitate the compiler to have acces to the ``func'' function, hence
to have access to all the functions accessed from ``func'''s body,
hence potentially access to the entire program. It means the compiler
should evaluate an unrestricted computation. Since we donnot want to
have the compiler looping, we thus need to detect looping programs and
this is not trivial (!).

If you can compute the constants by another Caml program of your own,
you can write those constants directly in your code: this way they
would not be computed at runtime as desired.

All the best,

Pierre Weis

INRIA, Projet Cristal,,