containers
Assorted concrete container types
| Version on this page: | 0.6.8 |
| LTS Haskell 24.16: | 0.7 |
| Stackage Nightly 2025-10-24: | 0.7 |
| Latest on Hackage: | 0.8 |
containers-0.6.8@sha256:bb2bec1bbc6b39a7c97cd95e056a5698ec45beb5d8feb6caae12af64e4bd823c,2670Module documentation for 0.6.8
- Data
- Data.Containers
- Data.Graph
- Data.IntMap
- Data.IntSet
- Data.Map
- Data.Sequence
- Data.Set
- Data.Tree
- Utils
- Utils.Containers
- Utils.Containers.Internal
- Utils.Containers
This package contains efficient general-purpose implementations of various immutable container types including sets, maps, sequences, trees, and graphs.
For a walkthrough of what this package provides with examples of common operations see the containers introduction.
The declared cost of each operation is either worst-case or amortized, but remains valid even if structures are shared.
Changes
Changelog for containers package
0.6.8
Additions
- Add
Data.IntSet.fromRange. (Soumik Sarkar)
Improvements
- Speed up conversion from monotonic lists to
Sets andMaps. (Soumik Sarkar)
Documentation and other
- Add, improve, and correct documentation. (Niklas Hambüchen, Soumik Sarkar, tomjaguarpaw, Alice Rixte, Tom Smeding)
Other/internal
-
Remove the
stack.yamlfile. It was extremely stale, and its utility was a bit dubious in a GHC boot package. Closes #938. -
Add a bunch of new tests and benchmarks. (Soumik Sarkar)
-
Future-proof test suite against export of
foldl'fromPrelude. (Teo Camarasu)
0.6.7
Additions
-
Add
takeWhileAntitone,dropWhileAntitone, andspanAntitoneforIntMapandIntSet. (Soumik Sarkar) -
Add a
Foldable1instance forData.Tree.
Improvements
-
Speed up splitting functions for
IntSetandIntMap. (Soumik Sarkar) -
Speed up
Foldablemethods forData.Tree. (Soumik Sarkar) -
Speed up
Data.Graph.dfs(Soumik Sarkar) -
Inline a few functions in
Data.Graphto enable list fusion. This immediately improves the performance of thetransposeGandsccfunctions. Mark several othersINLINABLEto allow specialization. (Soumik Sarkar) -
Optimize
Data.Graph.bcc, most notably replacing lists by difference lists to avoid quadratic complexity. (Soumik Sarkar)
Documentation
-
Improve various documentation and documentation formatting (Joseph C. Sible, konsumlamm, Soumik Sarkar, Alberto Fanton)
-
Add and correct time complexity documentation. (Soumik Sarkar)
-
Update
CONTRIBUTING.mdinstructions for building withstackandcabal, and add a note about how to avoid unnecessary recompilations. (Melanie Phoenix)
Miscellaneous/internal
- Remove now-redundant CPP. (Alexandre Esteves)
- Avoid
headandtail. (Bodigrim) - Fix build paths in
gitignore. (Alexandre Esteves) - Add extra implicit dependencies for
DeriveLift. (Matthew Pickering) - Work around
Preludechanges forliftA2. (David Feuer) - Add several property tests and too many benchmarks to count. (Soumik Sarkar)
- Add benchmarks for
Data.Set.powerSet. (jwaldmann) - Improve
Data.Set.powerSetproperty test. (David Feuer) - Fix test name. (Marcin Szamotulski)
- Fix error messages in internal
Data.Setfunctions. (Erik de Castro Lopo)
0.6.6
-
Drop support for GHC versions before 8.0.2.
-
Bump Cabal version for tests, and use
commonclauses to reduce duplication.
New instances
- Add
Liftinstances for use with Template Haskell. Specifically:Seq,ViewL, andViewR(inData.Sequence),Map,Set,IntMap,IntSet,Tree, andSCC(inData.Graph).
0.6.5.1
Bug fixes
-
foldr'andfoldl'forMapandSetare now strict everywhere they should be, and we have detailed tests to make sure they stay that way. (Thanks, coot.) -
The
Ord IntSetinstance, which was broken in 0.6.3.1, has been repaired.
New instance
- We now have
Ord a => Ord (Tree a)(Thanks, Ericson2314.)
Testing fixes
- Thanks to konsumlamm and infinity0 for various bug fixes in the test suite.
0.6.4.1
Bug fixes
- Replace value-forcing variants of
composewith lazy variants.- This brings
composecloser in line with functions likeunionandintersectionwhich don’t evaluate any map values. (Thanks, Simon Jakobi)
- This brings
Additions
-
Add
reverseTopSorttoData.Graph(Thanks, James Parker) -
Expose
traverseMaybeWithKeyfromData.IntMap.{Lazy,Strict}(Thanks, Simon Jakobi)
Other changes
-
Improvements to the testsuite: #663, #662 (Thanks, Bertram Felgenhauer)
-
Fix build with
stack test(Thanks, Simon Jakobi)
0.6.3.1
Bug fixes
-
Fix
traverseandtraverseWithKeyforIntMap, which would previously produce invalidIntMaps when the input contained negative keys (Thanks, Felix Paulusma). -
Fix the traversal order of various functions for
Data.IntMap:traverseWithKey,traverseMaybeWithKey,filterWithKeyA,minimum,maximum,mapAccum,mapAccumWithKey,mapAccumL,mapAccumRWithKey,mergeA(Thanks, Felix Paulusma, Simon Jakobi).
Additions
-
Add
composeforMapandIntMap(Thanks, Alexandre Esteves). -
Add
alterFforSetandIntSet(Thanks, Simon Jakobi). -
Add
Data.IntSet.mapMonotonic(Thanks, Javran Cheng). -
Add
instance Bifoldable Map(Thanks, Joseph C. Sible).
Performance improvements
-
Make
(<*)forData.Sequenceincrementally asymptotically optimal. This finally completes the task, begun in December 2014, of making all theApplicativemethods for sequences asymptotically optimal even when their results are consumed incrementally. Many thanks to Li-Yao Xia and Bertram Felgenhauer for helping to clean up and begin to document this rather tricky code. -
Speed up
fromListand related functions inData.IntSet,Data.IntMapandData.IntMap.Strict(Thanks, Bertram Felgenhauer). -
Use
count{Leading,Trailing}ZerosinData.IntSetinternals (Thanks, Alex Biehl).
Other changes
-
Reduce usage of the
Foresttype synonym inData.Tree(Thanks, David Feuer). -
Address a Core lint warning for
foldToMaybeTree(Thanks, Matthew Pickering). -
Improve documentation (Thanks to Daniel Wagner, Johannes Waldmann, Steve Mao, Gabriel Greif, Jean-Baptiste Mazon, Ziyang Liu, Matt Renaud, Li-Yao Xia).
-
Improvements to the testsuite and benchmarks (Thanks, Bertram Felgenhauer, Simon Jakobi, Johannes Waldmann).
-
Canonicalise
Seq’sMonoidinstance (Thanks, Fumiaki Kinoshita).
0.6.2.1
-
Add
disjointforMapandIntMap(Thanks, Simon Jakobi). -
Fix documentation bugs (Thanks, olligobber).
-
Fix unused imports (Thanks, Ben Gamari).
0.6.1.1
-
Fix Foldable instance for IntMap, which previously placed positively keyed entries before negatively keyed ones for
fold,foldMap, andtraverse. -
Make strict
IntMapmerges strict. -
Make
Data.IntMap.Merge.Stricttactics (exceptpreserveMissing) strict. -
Add a strict
Data.Map.Merge.Strict.preserveMissing'tactic. -
Make
stimesfor sequences work with 0 arguments, and make it more efficient. -
Speed up
cartesianProductforData.Set. -
Speed up
Data.Set.isSubsetOf,Data.Map.isSubmapOf, andData.Set.disjoint. -
Allow inlining for
Data.Sequence.traverseWithIndex, making it faster thansequencecombined withmapWithIndex. -
Produce more concise assembly from
maskW. (Thanks, Mateusz Kowalczyk) -
Use
countLeadingZerosto implementhighestBitMask(Thanks, Dmitry Ivanov) -
Improve documentation. (Thanks to jwaldmann, Yuji Yamamoto, David Sanders, Alec Theriault, Vaibhav Sagar, Boro Sitnikovski, Morten Kolstad, Vados, Benjamin Web, Chris Martin, Alexandre Esteves).
-
Clean up packaging and testing. (Thanks, David Eichmann, Simon Jakobi, Oleg Grenrus, Andreas Klebinger)
0.6.0.1
- Released with GHC 8.6
New functions and class instances
-
Add
Data.Containers.ListUtilsofferingnub-like functions. (Thanks to Gershom Bazerman for starting the process of writing these.) -
Add
GenericandGeneric1instances for keyData.Sequence.Internaltypes:Node,Digit,Elem, andFingerTree.
Death of deprecated functions
The following functions have been disabled. As an experiment in function removal technology, the functions are still temporarily present, but any attempts to use them will result in type errors advising on replacement.
-
Data.IntMap:insertWith',insertWithKey',fold, andfoldWithKey. -
Data.Map:insertWith',insertWithKey',insertLookupWithKey',fold, andfoldWithKey.
The same has been done for the deprecated exports of showTree and
showTreeWith. These function remain available in the internal Debug
modules.
Changes to existing functions
- Generalize the types of
unionsandunionsWith. (Thanks, jwaldmann.)
Performance improvements
-
Speed up folds and
traverseon sequences. (Thanks, Donnacha Oisín Kidney.) -
Speed up
Data.Set.union. (Thanks, Joachim Breitner.) -
Speed up several algorithms in
Data.Grapha bit by using unboxed arrays where appropriate. -
Implement
Data.Graph.indegreedirectly instead of taking the transpose and calculating itsoutdegree. This may not lead to an immediate performance improvement (see GHC Trac #14785) but it should be better eventually.
Other package changes
-
Drop support for GHC versions before 7.6.
-
Improve
Data.Graphdocumentation, and reorganize map and set documentation. -
Remove the
Data.Map.Lazy.MergeandData.Map.Strict.Mergemodules. These were renamed and deprecated almost as soon as they were introduced.
0.5.11
- Released with GHC 8.4.
New functions and class instances
-
Add a
MonadFixinstance forData.Sequence. -
Add a
MonadFixinstance forData.Tree. -
Add
powerSet,cartesianProduct, anddisjointUnionforData.Set. (Thanks, Edward Kmett.) -
Add
disjointforData.SetandData.IntSet. (Thanks, Víctor López Juan.) -
Add
lookupMinandlookupMaxtoData.IntMap. (Thanks, bwroga.) -
Add
unzipandunzipWithtoData.Sequence. Make unzipping build its results in lockstep to avoid certain space leaks. -
Add carefully optimized implementations of
sortOnandunstableSortOntoData.Sequence. (Thanks, Donnacha Oisín Kidney.)
Changes to existing functions and features
-
Make
Data.Sequence.replicateMa synonym forreplicateAfor post-AMPbase. -
Rewrite the
IsStringinstance head for sequences, improving compatibility with the list instance and also improving type inference. We used to haveinstance IsString (Seq Char)Now we commit more eagerly with
instance a ~ Char => IsString (Seq a) -
Make
>>=forData.Treestrict in the result of its second argument; being too lazy here is almost useless, and violates one of the monad identity laws. Specifically,return () >>= \_ -> undefinedshould always beundefined, but this was not the case. -
Harmonize laziness details for
minViewandmaxViewbetweenData.IntMapandData.Map.
Performance improvement
- Speed up both stable and unstable sorting for
Data.Sequenceby (Thanks, Donnacha Oisín Kidney.)
Other changes
-
Update for recent and upcoming GHC and Cabal versions (Thanks, Herbert Valerio Reidel, Simon Jakobi, and Ryan Scott.)
-
Improve external and internal documentation (Thanks, Oleg Grenrus and Benjamin Hodgson.)
-
Add tutorial-style documentation.
-
Add Haddock
@sinceannotations for changes made since version 0.5.4 (Thanks, Simon Jakobi.) -
Add a (very incomplete) test suite for
Data.Tree. -
Add structural validity checks to the test suites for
Data.IntMapandData.IntSet(Thanks to Joachim Breitner for catching an error in a first draft.)
0.5.10.2
-
Released with GHC 8.2.
-
Use
COMPLETEpragmas to declare complete sets of pattern synonyms forData.Sequence. At last! -
Make
Data.IntMap.Strict.traverseWithKeyforce the values before installing them in the result. Previously, this function could be used to produce anIntMapcontaining undefined values. -
Fix strictness bugs in various rewrite rules for
Data.Map.StrictandData.IntMap.Strict. Previously, rules could unintentionally reduce strictness. The most important change in this regard is the elimination of rules rewriting*.Strict.map coercetocoerce. To map a coercion over a structure for free, be sure to use the lazymaporfmap. It is possible to write rules that do a somewhat better job of this, but it turns out to be a bit messy. -
Optimize
Data.IntMap.restrictKeysandData.IntMap.withoutKeys. The semantic fix in 0.5.10.1 left them rather slow in certain cases. -
Speed up
sizeforIntSetandIntMap(thanks, Mike Ledger!). -
Define a custom
liftA2inApplicativeinstances for base 4.10, and useliftA2rather than<*>whenever it may be beneficial. -
Add
liftA2-relatedRULESforData.Sequence. -
Export non-deprecated versions of
showTreeandshowTreeWithfromData.IntMap.Internal.Debug.
0.5.10.1
-
Fix completely incorrect implementations of
Data.IntMap.restrictKeysandData.IntMap.withoutKeys. Make the tests for these actually run. (Thanks to Tom Smalley for reporting this.) -
Fix a minor bug in the
Show1instance ofData.Tree. This produced valid output, but with fewer parentheses thanShow. (Thanks, Ryan Scott.) -
Add
MonadZipinstance forData.Sequence. -
Remove meaningless stability annotations (Thanks, Simon Jakobi.)
0.5.9.2
- Backport bug fixes from 0.5.10.1
0.5.9.1
-
Add
mergeandmergeAforData.IntMap. -
Add instances for
Data.Graph.SCC:Foldable,Traversable,Data,Generic,Generic1,Eq,Eq1,Show,Show1,Read, andRead1. -
Add lifted instances (from
Data.Functor.Classes) forData.Sequence,Data.Map,Data.Set,Data.IntMap, andData.Tree. (Thanks to Oleg Grenrus for doing a lot of this work.) -
Properly deprecate functions in
Data.IntMaplong documented as deprecated. -
Rename several internal modules for clarity. Thanks to esoeylemez for starting this process.
-
Make
Data.Map.fromDistinctAscListandData.Map.fromDistinctDescListmore eager, improving performance. -
Plug space leaks in
Data.Map.Lazy.fromAscListandData.Map.Lazy.fromDescListby manually inlining constant functions. -
Add
lookupMinandlookupMaxtoData.SetandData.Mapas total alternatives tofindMinandfindMax. -
Add
!?toData.Mapas a total alternative to!. -
Avoid using
deleteFindMinanddeleteFindMaxinternally, preferring total functions instead. New implementations of said functions lead to slight performance improvements overall.
0.5.8.2
- Backport bug fixes from 0.5.10.1.
0.5.8.1 Aug 2016
General package changes
-
Remove all attempts to support nhc98 and any versions of GHC before 7.0.
-
Integrate benchmarks with Cabal. (Thanks, Gabriel Gonzalez!)
-
Make Cabal report required extensions properly, and stop using default extensions. Note that we do not report extensions conditionally enabled based on GHC version, as doing so would lead to a maintenance nightmare with no obvious benefits.
-
Use
BangPatternsthroughout to reduce noise. This extension is now required to compilecontainers. -
Improve QuickCheck properties taking arbitrary functions by using
Test.QuickCheck.Function.Funinstead of evilShowinstances for functions. -
Expose several internal modules through Cabal (as requested by Edward Kmett). These remain completely unsupported.
New exports and instances
-
Add
alterF,restrictKeys, andwithoutKeystoData.MapandData.IntMap. -
Add
take,drop,splitAt,takeWhileAntitone,dropWhileAntitone, andspanAntitoneforData.MapandData.Set. Thanks to Cale Gibbard for suggesting these. -
Add
merge,mergeA, and associated merge tactics forData.Map. Many thanks to Cale Gibbard, Ryan Trinkle, and Dan Doel for inspiring the merge idea and helping refine the interface. -
Add
traverseMaybeWithKey,fromDescList,fromDescListWith,fromDescListWithKey, andfromDistinctDescListtoData.Map. -
Add
fromDescListandfromDistinctDescListtoData.Set. -
Add
Empty,:<|, and:|>pattern synonyms forData.Sequence. -
Add
adjust',(!?),lookup,chunksOf,cycleTaking,insertAt,deleteAt,intersperse,foldMapWithIndex, andtraverseWithIndexforData.Sequence. -
Derive
GenericandGeneric1forData.Tree.Tree,Data.Sequence.ViewL, andData.Sequence.ViewR. -
Add
foldTreeforData.Tree. (Thanks, Daniel Wagner!)
Semantic changes
-
Make
Data.Sequence.splitAtstrict in its arguments. Previously, it returned a lazy pair. -
Fix completely erroneous definition of
lengthforData.Sequence.ViewR. -
Make
Data.Map.Strict.traverseWithKeyforce result values before installing them in the new map. -
Make
drawTreehandle newlines better. (Thanks, recursion-ninja!)
Deprecations
-
All functions in
Data.Mapproper that have been documented as deprecated since version 0.5 or before now haveDEPRECATEDpragmas and will actually be removed after another cycle or two. -
Tree printing functions in
Data.Mapintended for library debugging are now deprecated. They will continue to be available for the foreseeable future in an internal module.
Performance changes
-
Substantially speed up
splitAt,zipWith,take,drop,fromList,partition,foldl', andfoldr'forData.Sequence. Special thanks to Lennart Spitzner for digging into the performance problems with previous versions offromListand finding a way to make it really fast. Slightly optimizereplicateA. Stoptraversefrom performing many unnecessaryfmapoperations. -
Most operations in
Data.Sequenceadvertised as taking logarithmic time (including><andadjust) now use their full allotted time to avoid potentially building up chains of thunks in the tree. In general, the only remaining operations that avoid doing more than they really need are the particular bulk creation and transformation functions that really benefit from the extra laziness. There are some situations where this change may slow programs down, but I think having more predictable and usually better performance more than makes up for that. -
Add rewrite rules to fuse
fmapwithreverseforData.Sequence. -
Switch from hedge algorithms to divide-and-conquer algorithms for union, intersection, difference, and merge in both
Data.MapandData.Set. These algorithms are simpler, are known to be asymptotically optimal, and are faster according to our benchmarks. -
Speed up
adjustforData.Map. Allowmapto inline, and define a custom(<$). This considerably improves mapping with a constant function. -
Remove non-essential laziness in
Data.Map.Lazyimplementation. -
Speed up deletion and alteration functions for
Data.IntMap.
0.5.7.1 Dec 2015
-
Planned to bundle with GHC 8.0.1.
-
Add
IsStringinstance toData.Sequence. -
Define
Semigroupinstances forData.Map,Data.Set,Data.IntMap,Data.IntSetandData.Sequence.
0.5.6.2 Dec 2014
-
Bundled with GHC 7.10.1.
-
Add role annotations for
Data.MapandData.Set. -
Add
IsListinstances forData.Map,Data.Set,Data.IntMapandData.IntSet. -
Several performance improvements for
Data.Sequence. -
Add
Data.Sequence.fromFunctionandData.Sequence.fromArray.
0.5.4.0 Jan 2014
-
Bundled with GHC 7.8.1.
-
The
Data.Map.fromListandData.Set.fromListnow use linear-time algorithm if the input is sorted, without need to callfromDistinctAscList. -
Implement indexing operations (
lookupIndex,findIndex,elemAt,deletaAt) forData.Settoo. -
Add
ApplicativeandAlternativeinstances forData.Sequence. -
Add
foldMapWithKeytoData.MapandData.IntMap. -
Implement poly-kinded
Typeable. -
Add
Functorinstance forData.Graph.SCC. -
Add
Data.Map.splitRootandData.Set.splitRoot.
0.5.0.0 May 2012
-
Bundled with GHC 7.6.1.
-
Major improvements since last release:
- a clearer distinction between value-lazy and value-strict containers,
- performance improvements across the board,
- a big internal clean-up, and
- new functions for e.g. merging, updating, and searching containers.
-
While the old
Data.MapandData.IntMapmodules will continue to exist for the foreseeable future, we’ve abandoned the practice of having the strict and lazy versions of each function distinguished by an apostrophe. The distinction is instead made at the module level, by introducing four new modules:- Data.Map.Strict
- Data.Map.Lazy
- Data.IntMap.Strict
- Data.IntMap.Lazy
This split has three benefits:
- It makes the choice between value-strict and value-lazy containers more declarative; you pick once at import time, instead of having to remember to use the strict or lazy versions of a function every time you modify the container.
- It alleviates a common source of performance issues, by forcing the user to think about the strictness properties upfront. For example, using insertWith instead of insertWith’ is a common source of containers-related performance bugs.
- There are fewer functions per module, making it easier to get an overview of each module.
-
Note that the types used in the strict and lazy APIs are the same, so you can still use the same container in a “mixed” manner, if needed.
-
The
Data.IntSetrepresentation changed to store small sets using bits in anWord. Larger sets are stored as a collection of such dense small sets, connected together by a prefix trie.
0.4.2.1 Feb 2012
-
Bundled with GHC 7.4.1.
-
Data.Map now exportsfoldr,foldr’,foldlandfoldl’`. -
Data.Set now exportsfoldr,foldr’,foldlandfoldl’`. -
Data.IntMap now exportsfoldr,foldr’,foldl,foldl’,foldrWithKey,foldrWithKey’,foldlWithKeyandfoldlWithKey’`. -
Data.IntSet now exportsfoldr,foldr’,foldlandfoldl’`. -
Data.Map.foldWithKeyis no longer deprecated, although it is expected to be deprecated again in the future. -
There are now
NFDatainstance forData.Map.Map,Data.Set.Set,Data.IntMap.IntMap,Data.IntSet.IntSetandData.Tree.Tree.
0.4.1.0 Aug 2011
-
Bundled with GHC 7.2.1.
-
Data.Mapnow exports new functionsfoldrWithKey'andfoldlWithKey', which are strict variants offoldrWithKeyandfoldlWithKeyrespectively. -
Data.IntMapnow exports new functionsinsertWith'andinsertWithKey', which are strict variants ofinsertWithandinsertWithKeyrespectively.
0.4.0.0 Nov 2010
-
Bundled with GHC 7.0.1.
-
Strictness is now more consistent, with containers being strict in their elements even in singleton cases.
-
There is a new function
insertLookupWithKey'inData.Map. -
The
foldWithKeyfunction inData.Maphas been deprecated in favour offoldrWithKey.
0.3.0.0 Dec 2009
-
Bundled with GHC 6.12.1.
-
mapAccumRWithKeyhas been added toData.IntMap. -
A
Traversableinstance has been added toData.IntMap.IntMap. -
The types of
Data.IntMap.intersectionWithandData.IntMap.intersectionWithKeyhave been changed fromintersectionWith :: (a -> b -> a) -> IntMap a -> IntMap b -> IntMap aintersectionWithKey :: (Key -> a -> b -> a) -> IntMap a -> IntMap b -> IntMap atointersectionWith :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap cintersectionWithKey :: (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c -
The types of
Data.IntMap.findMinandData.IntMap.findMaxhave been changed fromfindMin :: IntMap a -> afindMax :: IntMap a -> atofindMin :: IntMap a -> (Int,a)findMax :: IntMap a -> (Int,a) -
Data.Mapnow exportsmapAccumRWithKey,foldrWithKey,foldlWithKeyandtoDescList. -
Data.Sequencenow exportsreplicate,replicateA,replicateM,iterateN,unfoldr,unfoldl,scanl,scanl1,scanr,scanr1,tails,inits,takeWhileL,takeWhileR,dropWhileL,dropWhileR,spanl,spanr,breakl,breakr,partition,filter,sort,sortBy,unstableSort,unstableSortBy,elemIndexL,elemIndicesL,elemIndexR,elemIndicesR,findIndexL,findIndicesL,findIndexR,findIndicesR,foldlWithIndex,foldrWithIndex,mapWithIndex,zip,zipWith,zip3,zipWith3,zip4andzipWith4.
0.2.0.0 Nov 2008
-
Bundled with GHC 6.10.1.
-
Various result type now use
Mayberather than allowing anyMonad.
0.1.0.0 Nov 2007
-
Bundled with GHC 6.8.1.
-
Initial split off from GHC base.