Map

Finite Maps (lazy interface)

This module re-exports the value lazy Data.Map.Lazy API. The Map k v type represents a finite map (sometimes called a dictionary) from keys of type k to values of type v. A Map is strict in its keys but lazy in its values. The functions in Data.Map.Strict are careful to force values before installing them in a Map. This is usually more efficient in cases where laziness is not essential. The functions in this module do not do so. When deciding if this is the correct data structure to use, consider:
  • If you are using Int keys, you will get much better performance for most operations using Data.IntMap.Lazy.
  • If you don't care about ordering, consider using Data.HashMap.Lazy from the unordered-containers package instead.
For a walkthrough of the most commonly used functions see the maps introduction. This module is intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.
import Data.Map (Map)
import qualified Data.Map as Map
Note that the implementation is generally left-biased. Functions that take two maps as arguments and combine them, such as union and intersection, prefer the values in the first argument to those in the second.

Warning

The size of a Map must not exceed maxBound :: Int. Violation of this condition is not detected and if the size limit is exceeded, its behaviour is undefined.

Implementation

The implementation of Map is based on size balanced binary trees (or trees of bounded balance) as described by: Bounds for union, intersection, and difference are as given by

Performance information

The time complexity is given for each operation in big-O notation, with <math> referring to the number of entries in the map. Operations like lookup, insert, and delete take <math> time. Binary set operations like union and intersection take <math> time, where <math> and <math> are the sizes of the smaller and larger input maps respectively.
A Map from keys k to values a.
A Map from keys k to values a. The Semigroup operation for Map is union, which prefers values from the left operand. If m1 maps a key k to a value a1, and m2 maps the same key to a different value a2, then their union m1 <> m2 maps k to a1.
Invariant preserving version of Map from the containers packages, suitable for use with Uniplate. Use toMap to construct values, and fromMap to deconstruct values.
Contains implementation of polymorphic type classes for data types Set and Map.
Strict Map. Import as:
import qualified RIO.Map as Map
This module does not export any partial or unchecked functions. For those, see RIO.Map.Partial and RIO.Map.Unchecked
Instances to convert between Map and association list. Copyright (C) 2009-2011 John Goerzen jgoerzen@complete.org All rights reserved. For license and copyright information, see the file LICENSE
Map type used to represent records and unions
A Map that remembers the original ordering of keys This is primarily used so that formatting preserves field order This is done primarily to avoid a dependency on insert-ordered-containers and also to improve performance
Hash-table, based on STM-specialized Hash Array Mapped Trie.
A Map from keys k to values a. The Semigroup operation for Map is union, which prefers values from the left operand. If m1 maps a key k to a value a1, and m2 maps the same key to a different value a2, then their union m1 <> m2 maps k to a1.
Type-level fmap for type-level functors. Note: this name clashes with Map from containers. FMap is provided as a synonym to avoid this.

Example

>>> data Example where Ex :: a -> Example  -- Hide the type of examples to avoid brittleness in different GHC versions

>>> data AddMul :: Nat -> Nat -> Exp Nat

>>> type instance Eval (AddMul x y) = (x TL.+ y) TL.* (x TL.+ y)

>>> :kind! Ex (Eval (Map (AddMul 2) '[0, 1, 2, 3, 4]) :: [Nat])
Ex (Eval (Map (AddMul 2) '[0, 1, 2, 3, 4]) :: [Nat]) :: Example
= Ex [4, 9, 16, 25, 36]
TOML-specific combinators for converting between TOML and Haskell Map-like data types. There are two way to represent map-like structures with the tomland library.
  • Map structure with the key and value represented as key-value pairs:
    foo = [ {myKey = "name", myVal = 42} , {myKey =
    "otherName", myVal = 100} ] 
  • Map structure as a table with the TOML key as the map key:
    [foo] name = 42 otherName = 100 
You can find both types of the codecs in this module for different map-like structures. See the following table for the heads up: TODO: table Note: in case of the missing key on the TOML side an empty map structure is returned.
Map a type level function over a Row.
This module defines finite maps where the key and value types are parameterized by an arbitrary kind. Some code was adapted from containers.
Lists of pairs representing maps. The Listable tiers enumeration will not have repeated maps.
> take 6 (list :: [Map Nat Nat])
[Map [],Map [(0,0)],Map [(0,1)],Map [(1,0)],Map [(0,2)],Map [(1,1)]]