The {-# UNPACK #-}
pragma tells the compiler to eliminate redundant constructors. Quoting Haskell wiki:
For example, given this:
data T = T {-# UNPACK #-} !(Int,Float)
GHC will represent the type T like this:
data T = T Int Float
eliminating the tuple. This is commonly used to put unboxed Ints directly in a constructor:
data T = T {-# UNPACK #-} !Int
will be represented as
data T = T Int#
I was wondering, does this also work when the field to be unpacked is polymorphic? For example, if I define
data S' a = S String {-# UNPACK #-} !a
type S1 = S' Int
newtype S2 = S2 (S' Int)
will functions that work with S1
or S2
be optimized?