HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleghc-10.0.0.20260917GHC2024

GHC.Data.FlatBag

  • 1 type
  • 7 values
datadata FlatBag a
#

Store elements in a flattened representation.

A FlatBag is a data structure that stores an ordered list of elements in a flat structure, avoiding the overhead of a linked list. Use this data structure, if the code requires the following properties:

  • Elements are stored in a long-lived object, and benefit from a flattened representation.

  • The FlatBag will be traversed but not extended or filtered.

  • The number of elements should be known.

  • Sharing of the empty case improves memory behaviour.

A FlagBag aims to have as little overhead as possible to store its elements. To achieve that, it distinguishes between the empty case, singleton, tuple and general case. Thus, we only pay for the additional three words of an Array if we have at least three elements.

Instances5Functor, Foldable, Traversable, NFData, Binary

Construction

2 declarations
valuefromList :: Word -> [a] -> FlatBag a
#

Store the list in a flattened memory representation, avoiding the memory overhead of a linked list.

The size n needs to be smaller or equal to the length of the list. If it is smaller than the length of the list, overflowing elements are discarded. It is undefined behaviour to set n to be bigger than the length of the list.

valuefromSmallArray :: SmallArray a -> FlatBag a
#

Convert a SizedSeq into its flattened representation. A 'FlatBag a' is more memory efficient than '[a]', if no further modification is necessary.