BSD-3-Clause licensed by Andrew Lelechenko, James Cook
Maintained by Andrew Lelechenko

Module documentation for

This version can be pinned in stack with:bitvec-,3363

Bit vectors library for Haskell.

The current vector package represents unboxed arrays of Bool allocating one byte per boolean, which might be considered wasteful. This library provides a newtype wrapper Data.Bit.Bit and a custom instance of unboxed Data.Vector.Unboxed.Vector, which packs booleans densely. It is a time-memory tradeoff: 8x less memory footprint at the price of moderate performance penalty (mostly, for random writes).

Thread safety

  • Data.Bit is faster, but thread-unsafe. This is because naive updates are not atomic operations: read the whole word from memory, modify a bit, write the whole word back.

  • Data.Bit.ThreadSafe is slower (up to 2x), but thread-safe.

Similar packages

  • bv and bv-little offer only immutable size-polymorphic bit vectors. bitvec provides an interface to mutable vectors as well.

  • array is memory-efficient for Bool, but lacks a handy Vector interface and is not thread-safe.


  • Redesign API from the scratch.
  • Add a thread-safe implementation.
  • Add ‘nthBitIndex’ function.

  • Fix ‘Read’ instance.

  • Remove hand-written ‘Num’, ‘Real’, ‘Integral’, ‘Bits’ instances.
  • Derive ‘Bits’ and ‘FiniteBits’ instances.
  • Expose ‘Bit’ constructor directly and remove ‘fromBool’ function.
  • Rename ‘toBool’ to ‘unBit’.

  • Fix bugs in MVector and Vector instances of Bit.
  • Speed up MVector and Vector instances of Bit.
comments powered byDisqus