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

Modulelens-5.3.5Haskell2010

Control.Lens.Internal.Indexed

Internal implementation details for Indexed lens-likes

  • 3 types
  • 2 classes
  • 4 values
  • Packagelens-5.3.5
  • Exports9
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceIndexed.hs

An Indexed Profunctor

1 declaration
newtypenewtype Indexed i a b
#

A function with access to a index. This constructor may be useful when you need to store an Indexable in a container to avoid ImpredicativeTypes.

index :: Indexed i a b -> i -> a -> b

Constructors

Instances27Category, Indexable, Arrow, ArrowApply, ArrowChoice, ArrowLoop, …

Classes

2 declarations
classclass (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), Costrong p, ArrowLoop p, ArrowApply p, ArrowChoice p, Closed p) => Conjoined (p :: Type -> Type -> Type) where
#

This is a Profunctor that is both Corepresentable by f and Representable by g such that f is left adjoint to g. From this you can derive a lot of structure due to the preservation of limits and colimits.

Methods

  • distrib :: Functor f => p a b -> p (f a) (f b)

    Conjoined is strong enough to let us distribute every Conjoined Profunctor over every Haskell Functor. This is effectively a generalization of fmap.

  • conjoined :: (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r

    This permits us to make a decision at an outermost point about whether or not we use an index.

    Ideally any use of this function should be done in such a way so that you compute the same answer, but this cannot be enforced at the type level.

Instances3Conjoined
classclass Conjoined p => Indexable i (p :: Type -> Type -> Type) where
#

This class permits overloading of function application for things that also admit a notion of a key or index.

Methods

  • indexed :: p a b -> i -> a -> b

    Build a function from an indexed function.

Instances2Indexable
  • i ~ j => Indexable i (Indexed j)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Indexable i (->)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed

Indexing

2 declarations
newtypenewtype Indexing (f :: Type -> Type) a
#

Applicative composition of State Int with a Functor, used by Control.Lens.Indexed.indexed.

Constructors

Instances6Functor, Applicative, Contravariant, Apply, Semigroup, Monoid
  • Functor f => Functor (Indexing f)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Applicative f => Applicative (Indexing f)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Contravariant f => Contravariant (Indexing f)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Apply f => Apply (Indexing f)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Semigroup (f a) => Semigroup (Indexing f a)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
  • Monoid (f a) => Monoid (Indexing f a)Defined in lens-5.3.5 · Control.Lens.Internal.Indexed
    Example1 expression
    "cat" ^@.. (folded <> folded)[(0,'c'),(1,'a'),(2,'t'),(0,'c'),(1,'a'),(2,'t')]
    Example1 expression
    "cat" ^@.. indexing (folded <> folded)[(0,'c'),(1,'a'),(2,'t'),(3,'c'),(4,'a'),(5,'t')]
valueindexing
  1. :: Indexable Int p
  2. => (a -> Indexing f b) -> s -> Indexing f t
  3. -> p a (f b)
  4. -> s
  5. -> f t
#

Transform a Control.Lens.Traversal.Traversal into an Control.Lens.Traversal.IndexedTraversal or a Control.Lens.Fold.Fold into an Control.Lens.Fold.IndexedFold, etc.

indexing :: Traversal s t a b -> IndexedTraversal Int s t a b
indexing :: Prism s t a b     -> IndexedTraversal Int s t a b
indexing :: Lens s t a b      -> IndexedLens Int  s t a b
indexing :: Iso s t a b       -> IndexedLens Int s t a b
indexing :: Fold s a          -> IndexedFold Int s a
indexing :: Getter s a        -> IndexedGetter Int s a
indexing :: Indexable Int p => LensLike (Indexing f) s t a b -> Over p f s t a b

64-bit Indexing

2 declarations
newtypenewtype Indexing64 (f :: Type -> Type) a
#

Applicative composition of State Int64 with a Functor, used by Control.Lens.Indexed.indexed64.

Constructors

Instances4Functor, Applicative, Contravariant, Apply
valueindexing64
  1. :: Indexable Int64 p
  2. => (a -> Indexing64 f b) -> s -> Indexing64 f t
  3. -> p a (f b)
  4. -> s
  5. -> f t
#

Transform a Control.Lens.Traversal.Traversal into an Control.Lens.Traversal.IndexedTraversal or a Control.Lens.Fold.Fold into an Control.Lens.Fold.IndexedFold, etc.

This combinator is like indexing except that it handles large traversals and folds gracefully.

indexing64 :: Traversal s t a b -> IndexedTraversal Int64 s t a b
indexing64 :: Prism s t a b     -> IndexedTraversal Int64 s t a b
indexing64 :: Lens s t a b      -> IndexedLens Int64 s t a b
indexing64 :: Iso s t a b       -> IndexedLens Int64 s t a b
indexing64 :: Fold s a          -> IndexedFold Int64 s a
indexing64 :: Getter s a        -> IndexedGetter Int64 s a
indexing64 :: Indexable Int64 p => LensLike (Indexing64 f) s t a b -> Over p f s t a b

Converting to Folds

2 declarations
valuewithIndex
  1. :: (Indexable i p, Functor f)
  2. => p (i, s) (f (j, t))
  3. -> Indexed i s (f t)
#

Fold a container with indices returning both the indices and the values.

The result is only valid to compose in a Traversal, if you don't edit the index as edits to the index have no effect.

Example1 expression
[10, 20, 30] ^.. ifolded . withIndex[(0,10),(1,20),(2,30)]
Example1 expression
[10, 20, 30] ^.. ifolded . withIndex . alongside negated (re _Show)[(0,"10"),(-1,"20"),(-2,"30")]