bitwise-enum: Bitwise operations on bounded enumerations

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]


Bitwise operations on bounded enumerations.

Constant-time sets using bit flags.
Constant-time lookup memoization for functions on enumerated types.

[Skip to Readme]


Versions,,,, 1.0.0,,,,,,,
Change log
Dependencies aeson (>=0.11 && <2.2), array (>=0.5.1 && <0.6), base (>=4.5 && <5), deepseq (>=1.1 && <1.5), mono-traversable (>=1.0.12 && <1.1), vector (>=0.11 && <0.13) [details]
License BSD-3-Clause
Author Joshua Booth <>
Maintainer Joshua Booth <>
Category Data, Data Structures, Foreign
Home page
Bug tracker
Source repo head: git clone
Uploaded by jnbooth at 2022-06-17T20:07:49Z


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for bitwise-enum-

[back to package description]


Efficient sets over bounded enumerations, using bitwise operations based on containers and EdisonCore. All operations apart from folds are constant-time. In many cases, the compiler may use constant folding to optimize EnumSets away entirely. For example, in the following code:

import Data.Enum.Set as E

data Foo = A | B | C | D | E | F | G | H deriving (Bounded, Enum, Eq, Ord)

instance E.AsEnumSet Foo

addFoos :: E.EnumSet Foo -> E.EnumSet Foo
addFoos = E.delete A . E.insert B

bar :: E.EnumSet Foo
bar = addFoos $ E.fromFoldable [A, C, E]

barHasA :: Bool
barHasA = E.member A bar

With -O or -O2 , bar will compile to GHC.Types.W# 22## and barHasA will compile to GHC.Types.False.

By default, Words are used as the representation. Other representations may be chosen in the class instance:

{-# LANGUAGE TypeFamilies #-}

import Data.Enum.Set as E
import Data.Word (Word64)

data Foo = A | B | C | D | E | F | G | H deriving (Bounded, Enum, Eq, Ord, Show)

instance E.AsEnumSet Foo where
    type EnumSetRep Foo = Word64