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

Moduleghc-9.10.3GHC2021

GHC.Types.Unique.FM

  • 2 types
  • 75 values
  • Packageghc-9.10.3
  • Exports77
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceFM.hs

Unique-keyed mappings

2 declarations
newtypenewtype UniqFM (key :: k) ele
#

A finite map from uniques of one type to elements in another type.

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.

Instances6Functor, Eq, Data, Semigroup, Monoid, Outputable
newtypenewtype NonDetUniqFM (key :: k) ele
#

A wrapper around UniqFM with the sole purpose of informing call sites that the provided Foldable and Traversable instances are nondeterministic. If you use this please provide a justification why it doesn't introduce nondeterminism. See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM to learn about determinism.

Constructors

Instances3Functor, Foldable, Traversable
  • Functor (NonDetUniqFM key)Defined in ghc-9.10.3 · GHC.Types.Unique.FM
  • Foldable (NonDetUniqFM key)Defined in ghc-9.10.3 · GHC.Types.Unique.FM

    Inherently nondeterministic. If you use this please provide a justification why it doesn't introduce nondeterminism. See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM to learn about determinism.

  • Traversable (NonDetUniqFM key)Defined in ghc-9.10.3 · GHC.Types.Unique.FM

    Inherently nondeterministic. If you use this please provide a justification why it doesn't introduce nondeterminism. See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM to learn about determinism.

Manipulating those mappings

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

    old -> new -> result

  3. -> UniqFM key elt

    old

  4. -> key
  5. -> elt

    new

  6. -> UniqFM key elt

    result Arguments of combining function of M.insertWith and addToUFM_C are flipped.

#
valueaddToUFM_L
  1. :: Uniquable key
  2. => (key -> elt -> elt -> elt)

    key,old,new

  3. -> key
  4. -> elt
  5. -> UniqFM key elt
  6. -> (Maybe elt, UniqFM key elt)

    old, result

#

Add an element, returns previous lookup result and new map. If old element doesn't exist, add the passed element directly, otherwise compute the element to add using the passed function.

valueaddListToUFM_C
  1. :: Uniquable key
  2. => elt -> elt -> elt
  3. -> UniqFM key elt
  4. -> [(key, elt)]
  5. -> UniqFM key elt
#

Add elements to the map, combining existing values with inserted ones using the given function.

valueplusUFM_CD
  1. :: elta -> eltb -> eltc
  2. -> UniqFM key elta
  3. -> elta
  4. -> UniqFM key eltb
  5. -> eltb
  6. -> UniqFM key eltc
#

`plusUFM_CD f m1 d1 m2 d2` merges the maps using f as the combinding function and d1 resp. d2 as the default value if there is no entry in m1 reps. m2. The domain is the union of the domains of m1 and m2.

IMPORTANT NOTE: This function strictly applies the modification function and forces the result unlike most the other functions in this module.

Representative example:

plusUFM_CD f {A: 1, B: 2} 23 {B: 3, C: 4} 42
   == {A: f 1 42, B: f 2 3, C: f 23 4 }
valueplusUFM_CD2
  1. :: Maybe elta -> Maybe eltb -> eltc
  2. -> UniqFM key elta
  3. -> UniqFM key eltb
  4. -> UniqFM key eltc
#

`plusUFM_CD2 f m1 m2` merges the maps using f as the combining function. Unlike plusUFM_CD, a missing value is not defaulted: it is instead passed as Nothing to f. f can never have both its arguments be Nothing.

IMPORTANT NOTE: This function strictly applies the modification function and forces the result.

`plusUFM_CD2 f m1 m2` is the same as `plusUFM_CD f (mapUFM Just m1) Nothing (mapUFM Just m2) Nothing`.

valueminusUFM_C
  1. :: elt1 -> elt2 -> Maybe elt1
  2. -> UniqFM key elt1
  3. -> UniqFM key elt2
  4. -> UniqFM key elt1
#

minusUFC_C f map1 map2 returns map1, except that every mapping key |-> value1 in map1 that shares a key with a mapping key |-> value2 in map2 is altered by f: value1 is replaced by f value1 value2, where Just means that the new value is used and Nothing means that the mapping is deleted.

valuediffUFM :: Eq a => UniqFM key a -> UniqFM key a -> UniqFM key (Edit a)
#

Computes the diff of two UniqFMs in terms of Edits. Equal points will not be present in the result map at all.

valuenonDetFoldUFM :: (elt -> a -> a) -> a -> UniqFM key elt -> a
#

Fold over a UniqFM.

Non-deterministic, unless the folding function is commutative (i.e. a1 f ( a2 f b ) == a2 f ( a1 f b ) for all a1, a2, b).

valuenonDetStrictFoldUFM_DirectlyM
  1. :: Monad m
  2. => Unique -> b -> elt -> m b
  3. -> b
  4. -> UniqFM key elt
  5. -> m b
#

In essence foldM See Note [Deterministic UniqFM] to learn about nondeterminism. If you use this please provide a justification why it doesn't introduce nondeterminism.

valueunsafeCastUFMKey :: UniqFM key1 elt -> UniqFM key2 elt
#

Cast the key domain of a UniqFM.

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

valuepprUFM
  1. :: UniqFM 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

#

Pretty-print a non-deterministic set. The order of variables is non-deterministic and for pretty-printing that shouldn't be a problem. Having this function helps contain the non-determinism created with nonDetEltsUFM.

valuepprUFMWithKeys
  1. :: UniqFM key a

    The things to be pretty printed

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

    The pretty printing function to use on the elements

  3. -> SDoc

    SDoc where the things have been pretty printed

#

Pretty-print a non-deterministic set. The order of variables is non-deterministic and for pretty-printing that shouldn't be a problem. Having this function helps contain the non-determinism created with nonDetUFMToList.

valuepluralUFM :: UniqFM key a -> SDoc
#

Determines the pluralisation suffix appropriate for the length of a set in the same way that plural from Outputable does for lists.