HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduleghc-10.0.0.20260917GHC2024

GHC.Types.Unique.DFM

  • 1 type
  • 53 values

Unique-keyed deterministic mappings

1 declaration
datadata UniqDFM (key :: k) ele
#

Type of unique deterministic finite maps

The key is just here to keep us honest. It's always safe to use a single type as key. If two types don't overlap in their uniques it's also safe to index the same map at multiple key types. But this is very much discouraged.

Instances7Functor, Foldable, Traversable, TrieMap, Data, Outputable, …

Manipulating those mappings

valueupsertUDFM
  1. :: Uniquable key
  2. => (Maybe elt -> elt)

    How to adjust the element

  3. -> UniqDFM key elt
  4. -> key

    key of the element to adjust

  5. -> UniqDFM key elt

    New element at key and modified UniqDFM

#

The expression (upsertUDFM f map k) updates the value at k or inserts a new value if k is absent.

Updating an existing entry keeps its original tag, so its position in deterministic iteration order is unchanged and does not depend on update order.

valuealterUDFM
  1. :: Uniquable key
  2. => (Maybe elt -> Maybe elt)

    How to adjust the element

  3. -> UniqDFM key elt
  4. -> key

    key of the element to adjust

  5. -> UniqDFM key elt

    New element at key and modified UniqDFM

#

The expression (alterUDFM f map k) alters value x at k, or absence thereof. alterUDFM can be used to insert, delete, or update a value in UniqDFM. Use addToUDFM, delFromUDFM or adjustUDFM when possible, they are more efficient. Updating an existing key keeps its position in the deterministic iteration order.

alterUDFM is non-strict in k.

valuealterUDFM_L
  1. :: Uniquable key
  2. => (Maybe elt -> Maybe elt)

    How to adjust the element

  3. -> UniqDFM key elt
  4. -> key

    key of the element to adjust

  5. -> (Maybe elt, UniqDFM key elt)

    New element at key and modified UniqDFM

#

The expression (alterUDFM_L f map k) alters value x at k, or absence thereof and returns the new element at k if there is any. alterUDFM_L can be used to insert, delete, or update a value in UniqDFM. Use addToUDFM, delFromUDFM or adjustUDFM when possible, they are more efficient. Updating an existing key keeps its position in the deterministic iteration order.

Note, alterUDFM_L is strict in k.

valuemapUDFM :: (elt1 -> elt2) -> UniqDFM key elt1 -> UniqDFM key elt2
#

Map a function over every value in a UniqDFM

valuefoldUDFM :: (elt -> a -> a) -> a -> UniqDFM key elt -> a
#

Performs a deterministic fold over the UniqDFM. It's O(n log n) while the corresponding function on UniqFM is O(n).

valuepprUDFM
  1. :: UniqDFM key a

    The things to be pretty printed

  2. -> ([a] -> SDoc)

    The pretty printing function to use on the elements

  3. -> SDoc

    SDoc where the things have been pretty printed

#
valueudfmToList :: UniqDFM key elt -> [(Unique, elt)]
#

Converts UniqDFM to a list, with elements in deterministic order. It's O(n log n) while the corresponding function on UniqFM is O(n).

valuenonDetStrictFoldUDFM :: (elt -> a -> a) -> a -> UniqDFM key elt -> a
#

Performs a nondeterministic strict fold over the UniqDFM. It's O(n), same as the corresponding function on UniqFM. If you use this please provide a justification why it doesn't introduce nondeterminism.

valueunsafeCastUDFMKey :: UniqDFM key1 elt -> UniqDFM key2 elt
#

Cast the key domain of a UniqFM.

As long as the domains don't overlap in their uniques this is safe.