Hacker News new | ask | show | jobs
by naasking 3354 days ago
> 3. OCaml in particular uses 63/31-bit ints due to implementation details, which isn't a good fit for 64/32-bit integers

I'm not sure what "isn't a good fit" is supposed to mean.

1 comments

Try storing an integer literal that requires 64 bits in a variable that can hold only 63 bits.

It's not going to make it impossible (you may just need something like a ShortIntLiteral and a LongIntLiteral variant), but it's going to require additional effort.

Sure, but not many real programs actually need the full 64-bits. Many of the ones that may seem to require the full bit width are doing bit ops on larger bit streams, for which there's ocaml-bitstream. What sort of programs are you thinking of?
Umm, compilers? That's what the post was about. Compilers need to be able to represent integer literals up to machine precision.
Compilers for languages with full-width integers need to represent full-width integer literals while compiling, sure. I'm not sure that it's:

a) all that common to need full width integers while compiling even these languages, and

b) all that problematic to use boxed numbers in this context, or big_int.

What you are saying here is that it isn't a huge problem in practice, and I agree with that. However, that's not what the original post was saying. It said that OCaml was especially suited for writing compilers because of its ints, which is the exact opposite claim.
Use Int64.t?
1. This wasn't what the original article was talking about.

2. int64's are normally boxed.