lens-3.10: Lenses, Folds and Traversals

Portability | non-portable
Stability | experimental
Maintainer | Edward Kmett <ekmett@gmail.com>
Safe Haskell | Trustworthy

Control.Lens.Internal.Indexed

Contents

- An Indexed Profunctor
- Classes
- Indexing
- 64-bit Indexing

Description

Internal implementation details for `Indexed` lens-likes

Synopsis

- newtype Indexed i a b = Indexed {
  - runIndexed :: i -> a -> b
  }
- class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), ArrowLoop p, ArrowApply p, ArrowChoice p) => Conjoined p where
  - distrib :: Functor f => p a b -> p (f a) (f b)
  - conjoined :: (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
- class Conjoined p => Indexable i p where
  - indexed :: p a b -> i -> a -> b
- newtype Indexing f a = Indexing {
  - runIndexing :: Int -> (Int, f a)
  }
- indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
- newtype Indexing64 f a = Indexing64 {
  - runIndexing64 :: Int64 -> (Int64, f a)
  }
- indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t

# An Indexed Profunctor

newtype Indexed i a b Source

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

Indexed |

Fields

runIndexed :: i -> a -> b

Instances

~ * i j => Indexable i (Indexed j) |
Arrow (Indexed i) |
ArrowChoice (Indexed i) |
ArrowApply (Indexed i) |
ArrowLoop (Indexed i) |
Category (Indexed i) |
Representable (Indexed i) |
Corepresentable (Indexed i) |
Strong (Indexed i) |
Choice (Indexed i) |
Profunctor (Indexed i) |
Conjoined (Indexed i) |
Bizarre (Indexed Int) Mafic |
Sellable (Indexed i) (Molten i) |
Bizarre (Indexed i) (Molten i) |
Monad (Indexed i a) |
Functor (Indexed i a) |
MonadFix (Indexed i a) |
Applicative (Indexed i a) |
Apply (Indexed i a) |
Bind (Indexed i a) |

# Classes

class (Choice p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Strong p, Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), ArrowLoop p, ArrowApply p, ArrowChoice p) => Conjoined p where Source

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)Source

`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) rSource

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.

Instances

Conjoined (->) |
Conjoined (Indexed i) |

class Conjoined p => Indexable i p where Source

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 -> bSource

Build a function from an `indexed` function.

Instances

Indexable i (->) |
~ * i j => Indexable i (Indexed j) |

# Indexing

newtype Indexing f a Source

`Applicative` composition of ``State` `Int`` with a `Functor`, used by `indexed`.

Constructors

Indexing |

Fields

runIndexing :: Int -> (Int, f a)

Instances

Functor f => Functor (Indexing f) |
Applicative f => Applicative (Indexing f) |
Contravariant f => Contravariant (Indexing f) |
Apply f => Apply (Indexing f) |

indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f tSource

Transform a `Traversal` into an `IndexedTraversal` or a `Fold` into an `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 -> Overloading p (->) f s t a b

# 64-bit Indexing

newtype Indexing64 f a Source

`Applicative` composition of ``State` `Int64`` with a `Functor`, used by `indexed64`.

Constructors

Indexing64 |

Fields

runIndexing64 :: Int64 -> (Int64, f a)

Instances

Functor f => Functor (Indexing64 f) |
Applicative f => Applicative (Indexing64 f) |
Contravariant f => Contravariant (Indexing64 f) |
Apply f => Apply (Indexing64 f) |

indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f tSource

Transform a `Traversal` into an `IndexedTraversal` or a `Fold` into an `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 -> Overloading p (->) f s t a b