Copyright | (c) The University of Glasgow 2001-2009 (c) Giovanni Campagna <gcampagn@cs.stanford.edu> 2014 |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | libraries@haskell.org |

Stability | unstable |

Portability | non-portable (GHC Extensions) |

Safe Haskell | None |

Language | Haskell2010 |

This module provides a data structure, called a Compact, for holding fully evaluated data in a consecutive block of memory.

*Since: 1.0.0*

- data Compact a
- getCompact :: Compact a -> a
- inCompact :: Compact b -> a -> IO Bool
- isCompact :: a -> IO Bool
- newCompact :: NFData a => Word -> a -> IO (Compact a)
- newCompactNoShare :: NFData a => Word -> a -> IO (Compact a)
- appendCompact :: NFData a => Compact b -> a -> IO (Compact a)
- appendCompactNoShare :: NFData a => Compact b -> a -> IO (Compact a)

# Documentation

A `Compact`

contains fully evaluated, pure, and immutable data. If
any object in the compact is alive, then the whole compact is
alive. This means that `Compact`

s are very cheap to keep around,
because the data inside a compact does not need to be traversed by
the garbage collector. However, the tradeoff is that the memory
that contains a `Compact`

cannot be recovered until the whole `Compact`

is garbage.

getCompact :: Compact a -> a Source #

Retrieve the object that was stored in a Compact

newCompact :: NFData a => Word -> a -> IO (Compact a) Source #

Create a new `Compact`

, with the provided value as suggested block
size (which will be adjusted if unsuitable), and append the given
value to it, as if calling `appendCompact`

newCompactNoShare :: NFData a => Word -> a -> IO (Compact a) Source #

Create a new `Compact`

, but append the value using `appendCompactNoShare`

appendCompactNoShare :: NFData a => Compact b -> a -> IO (Compact a) Source #

Append a value to a `Compact`

. This function differs from
`appendCompact`

in that it will not preserve internal sharing
in the passed in value (and it will diverge on cyclic structures).