ghc-heap-view-0.2: Extract the heap representation of Haskell values and thunks

MaintainerJoachim Breitner <>
Safe HaskellSafe-Infered




With this module, you can investigate the heap representation of Haskell values, i.e. to investigate sharing and lazy evaluation.


Heap data types

allPtrs :: Closure -> [Box]Source

For generic code, this function returns all referenced closures.

data StgInfoTable Source

This is a somewhat faithful representation of an info table. See for more details on this data structure. Note that the Storable instance provided here does _not_ support writing.



Reading from the heap

getClosureData :: a -> IO ClosureSource

This function returns parsed heap representation of the argument _at this moment_, even if it is unevaluated or an indirection or other exotic stuff. Beware when passing something to this function, the same caveats as for asBox apply.

getBoxedClosureData :: Box -> IO ClosureSource

Like getClosureData, but taking a Box, so it is easier to work with.

getClosureRaw :: a -> IO (Ptr StgInfoTable, [Word], [Box])Source

This returns the raw representation of the given argument. The second component of the triple are the words on the heap, and the third component are those words that are actually pointers. Once back in Haskell word, the Word may be outdated after a garbage collector run, but the corresponding Box will still point to the correct value.


data Box Source

An arbitrarily Haskell value in a safe Box. The point is that even unevaluated thunks can safely be moved around inside the Box, and when required, e.g. in getBoxedClosureData, the function knows how far it has to evalue the argument.


Box Any 


asBox :: a -> BoxSource

This takes an arbitrary value and puts it into a box. Note that calls like

 asBox (head list) 

will put the thunk "head list" into the box, not the element at the head of the list. For that, use careful case expressions:

 case list of x:_ -> asBox x