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] Function forward declaration?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-07 (15:13)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Function forward declaration?
On Thu, 2004-04-08 at 00:24, Ville-Pertti Keinonen wrote:
> On Apr 7, 2004, at 4:52 PM, skaller wrote:

> Minor nit - you probably mean "idle thread"...and it really isn't 
> currently common in the above form, since most modern CPUs 

That may be true, but 99% of all real time code is executed
on archaic processors because of the price tag (we're talking
instrumentation and device control and $1 parts here .. )

> I'd expect (but haven't attempted to prove) detecting uninitialized 
> values to be equivalent to the halting problem, so there would 
> inevitably be cases that would need to be rejected, detected at 
> run-time or result in unsound programs.

I suspect you are right for a totally unconstrained
language, whatever that means.

However clearly, this isn't the case for
a constrained language: uninitialised values are impossible
in Ocaml as it stands and any fault is detected immediately
by the parser :D

I don't know the exact algorithm, but Java allows a variable
to be declared without an initialiser, provided it 
is 'manifestly assigned before use'. That condition is
reputedly easy to check by both machine and human.

Of course, Charity guarrantees termination, so with
the constraints it imposes the halting problem itself
is easily solved (it isn't Turing complete).

Perhaps then, your observation needs to be inverted
to a question: what is a reasonable balance between
expressiveness and error trapping?

The Ocaml solution is least expressive, and its STILL
fails to catch all errors because sometimes programs
have to 'cheat' the system by using the wrong type
for a variable, or a wrong value to initialise it,
or even Obj.magic (eg: variable length array cannot
be defined in Ocaml without cheating).

Still, I personally find most code can be organised
so the number of initialisation tricks is quite small
and not too offensive: there is just one I'm aware
of in Felix. 

That particular case isn't a result of the Ocaml language
per se, but its compilation model.

There is a record containing the build number, 
which changes every compilation,
the record is compiled last to avoid full recompile every time,
and so can't be accessed by the rest of the system. 
So an 'uninitialised variable' is used which is compiled first, 
and the last initialisation the program does is to store 
the build number constant into the variable.

That build number is used when Marshalling data,
to allow a check the same version of the binary
creates and reads the data: I don't do any marshalling
during "initialisation" .. :D

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: