HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulehashmap-1.3.3Haskell98

Data.HashMap

Persistent Map based on hashing, which is defined as

  data Map k v = Data.IntMap.IntMap (Some k v)

is an Data.IntMap.IntMap indexed by hash values of keys, containing a value of Some e. That contains either one (k, v) pair or a Map k v with keys of the same hash values.

The interface of a Map is a suitable subset of Data.IntMap.IntMap and can be used as a drop-in replacement of Map.

The complexity of operations is determined by the complexities of Data.IntMap.IntMap and Map operations. See the sources of Map to see which operations from containers package are used.

Contents
  1. Operators
  2. Query
  3. Construction
  4. Insertion
  5. Delete/Update
  6. Combine
  7. Union
  8. Difference
  9. Intersection
  10. Traversal
  11. Map
  12. Fold
  13. Conversion
  14. Lists
  15. Filter
  16. Submap
Synopsis
  • Packagehashmap-1.3.3
  • Exports60
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceHashMap.hs
newtypenewtype Map k v

The abstract type of a Map. Its interface is a suitable subset of Data.IntMap.IntMap.

Instances11Functor, Foldable, Traversable, Eq, Data, Ord, …
typetype HashMap k v = Map k v

Deprecated. HashMap is deprecated. Please use Map instead.

The HashMap is a type synonym for Map for backward compatibility. It is deprecated and will be removed in furture releases.

Operators

value(!) :: (Hashable k, Ord k) => Map k a -> k -> a

Find the value at a key. Calls error when the element can not be found.

Query

Construction

Insertion

valueinsert :: (Hashable k, Ord k) => k -> a -> Map k a -> Map k a

Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value, i.e. insert is equivalent to insertWith const.

valueinsertWith
  1. :: (Hashable k, Ord k)
  2. => a -> a -> a
  3. -> k
  4. -> a
  5. -> Map k a
  6. -> Map k a

Insert with a combining function. insertWith f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f new_value old_value.

valueinsertWithKey
  1. :: (Hashable k, Ord k)
  2. => k -> a -> a -> a
  3. -> k
  4. -> a
  5. -> Map k a
  6. -> Map k a

Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value.

Delete/Update

valuedelete :: (Hashable k, Ord k) => k -> Map k a -> Map k a

Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.

valueadjust :: (Hashable k, Ord k) => (a -> a) -> k -> Map k a -> Map k a

Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.

valueadjustWithKey
  1. :: (Hashable k, Ord k)
  2. => k -> a -> a
  3. -> k
  4. -> Map k a
  5. -> Map k a

Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.

valueupdate :: (Hashable k, Ord k) => (a -> Maybe a) -> k -> Map k a -> Map k a

The expression (update f k map) updates the value x at k (if it is in the map). If (f x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.

valueupdateLookupWithKey
  1. :: (Hashable k, Ord k)
  2. => k -> a -> Maybe a
  3. -> k
  4. -> Map k a
  5. -> (Maybe a, Map k a)

Lookup and update. The function returns original value, if it is updated. This is different behavior than Data.Map.updateLookupWithKey. Returns the original key value if the map entry is deleted.

Combine

Union

valueunionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a

The union of a list of maps, with a combining operation.

Difference

valuedifferenceWithKey
  1. :: Ord k
  2. => k -> a -> b -> Maybe a
  3. -> Map k a
  4. -> Map k b
  5. -> Map k a

Difference with a combining function. When two equal keys are encountered, the combining function is applied to the key and both values. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.

Intersection

Traversal

Map

valuemap :: (a -> b) -> Map k a -> Map k b

Map a function over all values in the map.

valuemapAccum :: (a -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)

The function mapAccum threads an accumulating argument through the map in unspecified order of keys.

Fold

Conversion

valueelems :: Map k a -> [a]

Return all elements of the map in arbitrary order of their keys.

valuekeys :: Map k a -> [k]

Return all keys of the map in arbitrary order.

valueassocs :: Map k a -> [(k, a)]

Return all key/value pairs in the map in arbitrary key order.

Lists

valuetoList :: Map k a -> [(k, a)]

Convert the map to a list of key/value pairs.

Filter

valuepartition :: Ord k => (a -> Bool) -> Map k a -> (Map k a, Map k a)

Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate.

valuepartitionWithKey
  1. :: Ord k
  2. => k -> a -> Bool
  3. -> Map k a
  4. -> (Map k a, Map k a)

Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate.

Submap