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

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.

  • 2 types
  • 58 values
  • 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

2 declarations
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

6 declarations
valuesize :: Map k a -> Int
#

Number of elements in the map.

Construction

2 declarations

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.

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

The expression (update f k map) updates the value x at k (if it is in the map). If (f k 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

0 declarations

Union

valueunion :: Ord k => Map k a -> Map k a -> Map k a
#

The (left-biased) union of two maps. It prefers the first map when duplicate keys are encountered, i.e. (union == unionWith const).

valueunionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
#

The union with a combining function.

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

0 declarations

Map

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

Map a function over all values in the map.

valuemapWithKey :: (k -> 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.

valuemapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
#

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

Fold

valuefold :: (a -> b -> b) -> b -> Map k a -> b
#

Fold the values in the map, such that fold f z == foldr f z . elems.

Conversion

4 declarations
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.

valuefromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a
#

Create a map from a list of key/value pairs with a combining function.

valuefromListWithKey
  1. :: (Hashable k, Ord k)
  2. => k -> a -> a -> a
  3. -> [(k, a)]
  4. -> Map k a
#

Build a map from a list of key/value pairs with a combining function.

Filter

8 declarations
valuefilter :: Ord k => (a -> Bool) -> Map k a -> Map k a
#

Filter all values that satisfy some predicate.

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

4 declarations
valueisProperSubmapOfBy
  1. :: Ord k
  2. => a -> b -> Bool
  3. -> Map k a
  4. -> Map k b
  5. -> Bool
#

Is this a proper submap? (ie. a submap but not equal). The expression (isProperSubmapOfBy f m1 m2) returns True when m1 and m2 are not equal, all keys in m1 are in m2, and when f returns True when applied to their respective values.