My understanding is that an Int value is a pointer to a thunk (double indirection) and an unboxed Int# is just a pointer to a 32/64 bit int. Is that correct? How does the pointer encode the fact that it's referring to an unboxed value?
The Haskell standard states that an Int is "A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]". Is there some optimization in GHC where those extra bits are used to eliminate the indirections?
The GHC documentation has some good information. But basically, you're correct in saying that an Int
value is a pointer to a thunk. However, an unboxed value is not a pointer to the unboxed value, it is the unboxed value itself. Also, the Haskell standard report merely gives the lower limit on the range of Int
. IIRC, GHC Int
's have more than 30-bits.
I don't think GHC uses the extra bits of unboxed types to store any metadata, but it does use the bits of pointers to do so. See this page for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With