Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's a non-sequitur. Bools require only a single bit and variants/enums don't need all 64 bits. Those are completely distinct cases from the integer case which is fundamental and performance-critical.


They are exactly the same as integers in that they are not pointers and thus count as dead-ends for the garbage collection algorithm.

In theory, you could unbox some extra things at the cost of complicating the garbage collection algorithm and the memory representatio of values. GHC does this for Haskell but the Ocaml guys don't because they highly value keeping the compiler as simple as possible.

By the way, integer tagging is only important if your code s heavy in arithmetic operations or floating point operations (Ocaml tries to unbox floating point arrays, but sometimes it has to box floats). This often not that big of a problem and in the worst case you can always link Ocaml with C if you really want to.


> They are exactly the same as integers in that they are not pointers and thus count as dead-ends for the garbage collection algorithm.

Except that they are not the same since bools and enums don't need 64 bits and you mostly don't do integer arithmetic with them.

> In theory, you could unbox some extra things at the cost of complicating the garbage collection algorithm and the memory representatio of values. GHC does this for Haskell but the Ocaml guys don't because they highly value keeping the compiler as simple as possible.

I'm unclear on how special-casing integers and foisting a lot of bit-twiddling on all integer operations makes the compiler less complicated. Treating all values uniformly and using machine arithmetic everywhere would seem to minimize compiler complexity and make things faster.

> By the way, integer tagging is only important if your code s heavy in arithmetic operations or floating point operations (Ocaml tries to unbox floating point arrays, but sometimes it has to box floats). This often not that big of a problem and in the worst case you can always link Ocaml with C if you really want to.

Noted: if you want to do numerical work in OCaml, use C ;-)

But seriously, is there code that isn't heavy on integer arithmetic or floating point operations? Do computers do anything else?


The bit twidling means that you can store any kind of Ocaml value in a single machine word.

https://realworldocaml.org/v1/en/html/memory-representation-...

This makes the generated executables less efficient but it makes the lives of the compiler and garbage collector easier: Every single variable or function parameter has the same size and you can easily tell if a value is a pointer or not just by looking at it.

In a way, its a little bit like executing bytecode in a virtual machine. The executable does some extra bit twiddling, boking and tagging but lots of things get simpler because of the uniform value representation.

> But seriously, is there code that isn't heavy on integer arithmetic or floating point operations? Do computers do anything else?

Lots of software nowadays is bottlenecked by the speed of network interfaces or RAM, meaning that the arithmetic speed isn't a big factor.


Thanks, that's a reasonable explanation. I can see how storing every value in exactly one machine word and having the low bit always indicate whether a value is immediate or a pointer is a nice simple design.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: