HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduledependent-map-0.4.0.0Haskell98

Data.Dependent.Map.Lens

Some functions for using lenses with DMap.

  • 2 values

At

1 declaration
valuedmat
  1. :: (GCompare k2, Functor f)
  2. => k2 v
  3. -> Maybe (g v) -> f (Maybe (g v))
  4. -> DMap k2 g
  5. -> f (DMap k2 g)
#

These functions have been specialised for use with DMap but without any of the specific lens types used so that we have compatibility without needing the dependency just for these functions.

This is equivalent to the at Lens' from Control.Lens.At:

type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t

at :: Index m -> Lens' m (Maybe (IxValue m))

So the type of dmat is equivalent to:

dmat :: GCompare k => Lens' (DMap k f) (Maybe (f v))
Example1 expression
DMap.fromList [AInt :=> Identity 33, AFloat :=> Identity 3.5] & dmat AString ?~ "Hat"DMap.fromList [AString :=> Identity "Hat", AInt :=> Identity 33, AFloat :=> Identity 3.5]
Example1 expression
DMap.fromList [AString :=> Identity "Shoe", AInt :=> Identity 33, AFloat :=> Identity 3.5] ^? dmat AFloatJust (AFloat :=> 3.5)

Ix

1 declaration
valuedmix
  1. :: (GCompare k2, Applicative f)
  2. => k2 v
  3. -> g v -> f (g v)
  4. -> DMap k2 g
  5. -> f (DMap k2 g)
#

This is equivalent to the ix Traversal' from Control.Lens.At:

type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t

ix :: Index m -> Traversal' m (IxValue m)

So the type of dmix is equivalent to:

dmix :: GCompare k => k v -> Traversal' (DMap k f) (f v)

NB: Setting the value of this Traversal will only set the value in dmix if it is already present.

If you want to be able to insert missing values, you want dmat.

Example1 expression
DMap.fromList [AString :=> Identity "Shoe", AInt :=> Identity 33, AFloat :=> Identity 3.5] & dmix AInt %~ fDMap.fromList [AString :=> Identity "Shoe", AInt :=> Identity (f 33), AFloat :=> Identity 3.5]
Example1 expression
DMap.fromList [AString :=> Identity "Shoe", AInt :=> Identity 33, AFloat :=> Identity 3.5] & dmix AString .~ "Hat"DMap.fromList [AString :=> Identity "Hat", AInt :=> Identity 33, AFloat :=> Identity 3.5]
Example1 expression
DMap.fromList [AString :=> Identity "Shoe", AInt :=> Identity 33, AFloat :=> Identity 3.5] ^? dmix AFloatJust (AFloat :=> 3.5)
Example1 expression
DMap.fromList [AString :=> Identity "Shoe", AFloat :=> Identity 3.5] ^? dmix AIntNothing