Created: 2023-01-11 09:52
The UNPACK
pragma instruct the compiler to unwrap, or unbox, a value so that the actual value would be used instead of a pointer to it.
See the definition of Data.Map for example:
data Map k a
= Tip
| Bin
{-# UNPACK #-} !Size -- size, unpacked Int
!k -- key
a -- value
!(Map k a) -- left side tree
!(Map k a) -- right side tree
type Size = Int
Using the unpacked Int
here means the compiler saves the actual machine Int
instead of a pointer. But it wasn’t strict the thunk to the Int
would be what’s unpacked.