HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Data.FlatBag

  • 1 type
  • 7 values
  • Packageghc-9.10.3
  • Exports8
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceFlatBag.hs
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.

Instances4Functor, Foldable, Traversable, NFData

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.

valuefromSizedSeq :: SizedSeq 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.