title: Memory footprint of Haskell data types
body: <p>How can I find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it at runtime (e.g. in GHCi) or is it possible to estimate memory requirements of a compound data type from its components?</p>
  
  <p>In general, if memory requirements of types <code>a</code> and <code>b</code> are known, what is the memory overhead of algebraic data types such as:</p>
  
  <pre><code>data Uno = Uno a
  data Due = Due a b
  </code></pre>
  
  <p>For example, how many bytes in memory do these values occupy?</p>
  
  <pre><code>1 :: Int8
  1 :: Integer
  2^100 :: Integer
  \x -&gt; x + 1
  (1 :: Int8, 2 :: Int8)
  [1] :: [Int8]
  Just (1 :: Int8)
  Nothing
  </code></pre>
  
  <p>I understand that actual memory allocation is higher due to delayed garbage collection. It may be significantly different due to lazy evaluation (and thunk size is not related to the size of the value). The question is, given a data type, how much memory does its value take when fully evaluated?</p>
  
  <p>I found there is a <code>:set +s</code> option in GHCi to see memory stats, but it is not clear how to estimate the memory footprint of a single value.</p>