I have trouble understanding how UNPACK works in Haskell.
Consider, for example, the following data declarations:
data P a b = P !a !b
data T = T {-# UNPACK #-} !(P Int Int)
How will datatype T be unpacked? Will it be equivalent to
data T' = T' !Int !Int
or will the Ints be further unpacked:
data T'' = T'' Int# Int#
? What about
data U = U {-# UNPACK #-} !(P Int (P Int Int))
?
The GHC documentation describes the UNPACK pragma as follows:
The
UNPACKindicates to the compiler that it should unpack the contents of a constructor field into the constructor itself, removing a level of indirection.
How will datatype
Tbe unpacked?
data T = T (P Int Int) corresponds to

Therefore, data T = T {-# UNPACK #-} !(P Int Int) corresponds to

In plain English, UNPACK has unpacked the contents of constructor P into the field of constructor T, removing one level of indirection and one constructor header (P).
data T = T {-# UNPACK #-} !(P Int Int) isn't as "compact" as data T'' = T'' Int# Int#:

What about
data U = U {-# UNPACK #-} !(P Int (P Int Int))?
Similarly, data U = U (P Int (P Int Int)) corresponds to

and data U = U {-# UNPACK #-} !(P Int (P Int Int)) corresponds to

In plain English, UNPACK has unpacked the contents of constructor P into the field of constructor U, removing one level of indirection and one constructor header (P).
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