Skip to content

Instantly share code, notes, and snippets.

{-# UNPACK #-} Unpacking strict fields

This is one of the most powerful techniques you can use to optimise data structures.

When a constructor field is marked strict, and it is a single-constructor type, then it is possible to ask GHC to unpack the contents of the field directly in its parent. For example, given this:

data T = T {-# UNPACK #-} !(Int,Float)