I am working with a file format the contains 32 bit integers.
I need to use int32 on 32 bit systems.  I would like to use plain
integers, unboxed and with native machine operations, on 64 bit
systems.

Is there any way to convince ocamlopt to choose between int and
int32 representations _at compile time_?

I could use first class modules to select implementations at
runtime, which is not worth the code complexity and still
requires an indirect function call to add numbers.  I could
conditionally compile different files depending on word size,
which strikes me as an ugly and fragile solution.

I want to be able to write "int32" and have that be compiled
like an ordinary integer type if 32 bits and tag fit into a
word, and as a boxed type otherwise.  (The compiler could
mask off excess precision if desired.)  Is there a reason ocaml
can't provide this?

Another implementation would have each instance of an int32 or
int64 be boxed or not depending on whether the value fits into
a word.  I don't know whether this would be faster or slower in
practice.  There is a tradeoff between allocations and
conditional branches.

    --John Carr ([email protected])

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to