| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Optics
Description
The user-facing optics vocabulary, in one import.
- Build optics with
iso,lens,monLens,prism,affineTraversal,grate,glass,powerGrate,cotraversal,kaleidoscope,algebraicLens,classifyingLens,tracer,traversed,traversal(aTraversalfrom its van-Laarhoven / profunctor-class form),toandunto. These produceProstrong-flavored optics (Iso,Lens,Prism,Traversal, ...), which support subtyping: any optic can be used directly wherever a weaker flavor is needed (aLensis aGetter, aSetter, aFold, ...), checked by the flavor superclass lattice.MonoidalTraversalis built from its van-Laarhoven form withfromPTraversal. Only the three read-/write-only flavors (Setter,Fold,AffineFold) have no builder of their own -- reach them byconvertfrom a stronger optic (or%-composition, asaffineTraversaldoes with aLensand aPrism). - Eliminate optics with exactly one canonical eliminator per flavor:
view(aGetter),review(aReview),preview(anAffineFold),matching(anAffineTraversal),over(aSetter),foldMapOf(aFold),traverseOf(aTraversal),monTraverseOf(aMonoidalTraversal),powerGrateOf(aPowerGrate),cotraverseOf(aCotraversal),kaleidoscopeOfandzipWithOf(aKaleidoscope),classifyOf(anAlgebraicLens) andtracerOf(aTracer) run the optic, whilewithIso,withLens,withMonLens,withPrism,withGrateandwithGlassrecover its two legs. Operator shorthands ((^.),(#),(^?),set,(%~),(.~),unfold) abbreviate the common ones. All of these are encoding-agnostic. - The library's structural isos (e.g.
associator) live in a second, profunctor-class-flavored encoding (PIso); every consumer above accepts those as-is too, so this distinction rarely matters. When it does — converting between the encodings, van Laarhoven interop, writing flavor-generic code — import Proarrow.Optic and its submodules directly.
The full subtyping lattice (flavor superclass edges, weakest optics at the top).
Dotted nodes are one-sided flavors, whose methods never mention the second witness; dashed
nodes are indexed by a monad and so have no edge to Iso:
Synopsis
- type Optic (c :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j) = Optic_ ('OPT a b :: OPTIC j k c) ('OPT s t :: OPTIC j k c)
- type Optic' (c :: (j +-> j) -> Constraint) (s :: j) (a :: j) = Optic c s s a a
- type Iso (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (IsoFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Iso' (s :: k) (a :: k) = Iso s s a a
- type Lens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (LensFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Lens' (s :: k) (a :: k) = Lens s s a a
- type MonoidalLens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (MonLensFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type MonoidalLens' (s :: k) (a :: k) = MonoidalLens s s a a
- type Prism (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Prism' (s :: k) (a :: k) = Prism s s a a
- type AffineTraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (AffineTravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type AffineTraversal' (s :: k) (a :: k) = AffineTraversal s s a a
- type Traversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Traversal' (s :: k) (a :: k) = Traversal s s a a
- type MonoidalTraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type MonoidalTraversal' (s :: k) (a :: k) = MonoidalTraversal s s a a
- type PTraversal (s :: j) (t :: j) (a :: j) (b :: j) = Optic (StrongDistributiveProfunctor :: (j +-> j) -> Constraint) s t a b
- type PTraversal' (s :: j) (a :: j) = PTraversal s s a a
- type PTraversalFull (s :: j) (t :: j) (a :: j) (b :: j) = Optic ((StrongDistributiveProfunctor :: (j +-> j) -> Constraint) :&&: Strong (ProdAction :: j -> (PROD j, j) -> Type)) s t a b
- type Setter (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (SetterFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Setter' (s :: k) (a :: k) = Setter s s a a
- type Getter (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (GetterFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b
- type Review (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (Flip (GetterFl :: (j +-> j) -> (k +-> k) -> Constraint))) s t a b
- type AffineFold (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b
- type Fold (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (FoldFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b
- type Grate (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (GrateFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Grate' (s :: k) (a :: k) = Grate s s a a
- type Glass (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (GlassFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Glass' (s :: k) (a :: k) = Glass s s a a
- type PowerGrate (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type PowerGrate' (s :: k) (a :: k) = PowerGrate s s a a
- type Cotraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (CotravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Cotraversal' (s :: k) (a :: k) = Cotraversal s s a a
- type Kaleidoscope (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Kaleidoscope' (s :: k) (a :: k) = Kaleidoscope s s a a
- type AlgebraicLens (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (AlgLensFl m)) s t a b
- type ClassifyingLens (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (ClassifyFl l)) s t a b
- type Tracer (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Tracer' (s :: k) (a :: k) = Tracer s s a a
- iso :: forall {j} {k} (c :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k) => (s ~> a) -> (b ~> t) -> Optic c s t a b
- lens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (HasBinaryProducts k, Ob b) => (s ~> a) -> ((s && b) ~> t) -> Lens s t a b
- monLens :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Comonoid m, Ob a, Ob b) => (s ~> (m ** a)) -> ((m ** b) ~> t) -> MonoidalLens s t a b
- prism :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => (b ~> t) -> (s ~> (t || a)) -> Prism s t a b
- affineTraversal :: forall {k} (s :: k) (t :: k) (x :: k) (y :: k) (a :: k) (b :: k). CategoryOf k => Lens s t x y -> Prism x y a b -> AffineTraversal s t a b
- grate :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Closed k, SymMonoidal k, HasCoproducts k, Comonoid (s ~~> a), Ob s, Ob a, Ob b) => (((s ~~> a) ~~> b) ~> t) -> Grate s t a b
- glass :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CCC k, Ob s, Ob a, Ob b) => ((s && ((s ~~> a) ~~> b)) ~> t) -> Glass s t a b
- powerGrate :: forall {k} (n :: Nat) (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, KnownNat n, Ob a, Ob b) => (s ~> Tensor n a) -> (Tensor n b ~> t) -> PowerGrate s t a b
- cotraversal :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Cotraversal s t a b
- kaleidoscope :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Kaleidoscope s t a b
- algebraicLens :: forall {k} (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra m (m % s), Comonoid (m % s), Comonoid s, OplaxMonoidalRep m, Ob a, Ob b) => (s ~> a) -> (((m % s) ** b) ~> t) -> AlgebraicLens m s t a b
- classifyingLens :: forall {k} (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra l (l % s), Monoid (l % s), Comonoid (l % s), Comonoid s, OplaxMonoidalRep l, SymMonoidal k, HasCoproducts k, Ob a, Ob b) => (s ~> a) -> (((l % s) ** b) ~> t) -> ClassifyingLens l s t a b
- tracer :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (TracedMonoidal k, Ob m, Ob s, Ob t, Ob a, Ob b) => ((m ** s) ~> a) -> (b ~> (m ** t)) -> Tracer s t a b
- traversed :: forall {k} (t :: k +-> k) (a :: k) (b :: k). (Bicartesian k, Traversable t, Representable t, Ob a, Ob b) => Traversal (t % a) (t % b) a b
- traversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k, HasProducts k, Ob a, Ob b, Ob s, Ob t) => (forall (r :: k +-> k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => r a b -> r s t) -> Traversal s t a b
- to :: forall {k} {j} (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf k, CategoryOf j, Ob b, Ob t) => (s ~> a) -> Getter s t a b
- unto :: forall {k} {j} (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf k, CategoryOf j, Ob s, Ob a) => (b ~> t) -> Review s t a b
- re :: forall {j} {k} (a :: j) (b :: k) (c :: (k +-> j) -> Constraint) (coc :: (j +-> k) -> Constraint) (s :: j) (t :: k). (Ob a, Ob b, ReversibleOptic c coc) => Optic c s t a b -> Optic coc b a t s
- view :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, (Ob a, Ob b) => c (ExOptic (GetterFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> s ~> a
- review :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, (Ob a, Ob b) => c (ExOptic (Flip (GetterFl :: (j +-> j) -> (k +-> k) -> Constraint)) a b)) => Optic c s t a b -> b ~> t
- preview :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (Bicartesian k, CategoryOf j, (Ob a, Ob b) => c (ExOptic (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> s ~> (a || (TerminalObject :: k))
- matching :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (Bicartesian k, (Ob a, Ob b) => c (ExOptic (AffineTravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> s ~> (t || a)
- over :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (CategoryOf k, (Ob a, Ob b) => c (ExOptic (SetterFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (a ~> b) -> s ~> t
- foldMapOf :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (m :: k) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, Ob m, Monoid m, (Ob a, Ob b) => c (ExOptic (FoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> (a ~> m) -> s ~> m
- traverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, Strong (ProdAction :: k -> (PROD k, k) -> Type) p, (Ob a, Ob b) => c (ExOptic (TravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t
- monTraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, (Ob a, Ob b) => c (ExOptic (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t
- powerGrateOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, MonoidalProfunctor r, (Ob a, Ob b) => c (ExOptic (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t
- cotraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Cotraversable r, (Ob a, Ob b) => c (ExOptic (CotravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t
- kaleidoscopeOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Kaleidoscopic r, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t
- zipWithOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (Monoidal k, Ob a, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((a ** a) ~> b) -> (s ** s) ~> t
- classifyOf :: forall {k} (m :: k +-> k) (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (OplaxMonoidalRep m, Comonoid a, (Ob a, Ob b) => c (ExOptic (AlgLensFl m) a b)) => Optic c s t a b -> ((m % s) ** b) ~> t
- tracerOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, Costrong (Tensor :: k -> (k, k) -> Type) r, c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t
- withIso :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, (Ob a, Ob b) => c (Yo a ('OP b))) => Optic c s t a b -> ((s ~> a) -> (b ~> t) -> r) -> r
- withLens :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryProducts k, (Ob a, Ob b) => c (ExOptic (LensFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((s ~> a) -> ((s && b) ~> t) -> r) -> r
- withMonLens :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (SymMonoidal k, (Ob a, Ob b) => c (ExOptic (MonLensFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (forall (m :: k). Ob m => ComonoidOn m -> (s ~> (m ** a)) -> ((m ** b) ~> t) -> r) -> r
- withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (ExOptic (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((b ~> t) -> (s ~> (t || a)) -> r) -> r
- withGrate :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Closed k, SymMonoidal k, (Ob a, Ob b) => c (ExOptic (GrateFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t) -> r) -> r
- withGlass :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CCC k, (Ob a, Ob b) => c (ExOptic (GlassFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (((s && ((s ~~> a) ~~> b)) ~> t) -> r) -> r
- (^.) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (GetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => s -> Optic c s t a b -> a
- (#) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (Flip (GetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint)) a b) => Optic c s t a b -> b -> t
- (^?) :: forall s t a b (c :: (Type -> Type -> Type) -> Constraint). c (ExOptic (AffineFoldFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => s -> Optic c s t a b -> Maybe a
- (.?) :: forall f (c :: (Type -> Type -> Type) -> Constraint) s t a b. (Monad f, Functor f, c (ExOptic (AlgLensFl (Star f)) a b)) => Optic c s t a b -> b -> f s -> t
- set :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> b -> s -> t
- (%~) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> (a -> b) -> s -> t
- (.~) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> b -> s -> t
- unfold :: forall {k} (c :: (OPPOSITE k -> OPPOSITE k -> Type) -> Constraint) (cm :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Comonoid cm, Ob cm, forall (p :: OPPOSITE k +-> OPPOSITE k). c p => c (Op (UnOp p)), (Ob a, Ob b) => c (ExOptic (FoldFl :: (OPPOSITE k +-> OPPOSITE k) -> (OPPOSITE k +-> OPPOSITE k) -> Constraint) ('OP b) ('OP a))) => Optic (OpConstraint c) s t a b -> (cm ~> b) -> cm ~> t
- (%) :: forall {j} {k} (c1 :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j) (c2 :: (j +-> k) -> Constraint) (c :: k) (d :: j). Optic c1 s t a b -> Optic c2 a b c d -> Optic (c1 :&&: c2) s t c d
- convert :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (w :: FLAVOR j k) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, Flavor w, (Ob a, Ob b) => c (ExOptic w a b)) => Optic c s t a b -> Optic (Prostrong w) s t a b
- class (Monad m, Ob a) => Algebra (m :: k +-> k) (a :: k) where
- toPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => MonoidalTraversal s t a b -> PTraversal s t a b
- toPTraversalFull :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => Traversal s t a b -> PTraversalFull s t a b
- fromPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k) => PTraversal s t a b -> MonoidalTraversal s t a b
Optic kinds
type Optic (c :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j) = Optic_ ('OPT a b :: OPTIC j k c) ('OPT s t :: OPTIC j k c) Source Github #
type Iso (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (IsoFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Lens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (LensFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type MonoidalLens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (MonLensFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type MonoidalLens' (s :: k) (a :: k) = MonoidalLens s s a a Source Github #
type Prism (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type AffineTraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (AffineTravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type AffineTraversal' (s :: k) (a :: k) = AffineTraversal s s a a Source Github #
type Traversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Traversal' (s :: k) (a :: k) = Traversal s s a a Source Github #
type MonoidalTraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type MonoidalTraversal' (s :: k) (a :: k) = MonoidalTraversal s s a a Source Github #
type PTraversal (s :: j) (t :: j) (a :: j) (b :: j) = Optic (StrongDistributiveProfunctor :: (j +-> j) -> Constraint) s t a b Source Github #
A traversal in the profunctor-class-flavored encoding (cf. PIso), used by
the GHC.Generics combinators below. Equivalent to Traversal via toPTraversal and
fromPTraversal.
type PTraversal' (s :: j) (a :: j) = PTraversal s s a a Source Github #
type PTraversalFull (s :: j) (t :: j) (a :: j) (b :: j) = Optic ((StrongDistributiveProfunctor :: (j +-> j) -> Constraint) :&&: Strong (ProdAction :: j -> (PROD j, j) -> Type)) s t a b Source Github #
A full traversal in the profunctor-class encoding: distributes any profunctor carrying both
distributive strength and product strength -- exactly the constraint travP demands. This is
the Traversal analog of PTraversal, which drops the product strength (all it needs for a
MonoidalTraversal). Equivalent to Traversal via toPTraversalFull and traversal.
type Setter (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (SetterFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Getter (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (GetterFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b Source Github #
type Review (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (Flip (GetterFl :: (j +-> j) -> (k +-> k) -> Constraint))) s t a b Source Github #
type AffineFold (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b Source Github #
type Fold (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (FoldFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b Source Github #
type Grate (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (GrateFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Glass (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (GlassFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type PowerGrate (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type PowerGrate' (s :: k) (a :: k) = PowerGrate s s a a Source Github #
type Cotraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (CotravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Cotraversal' (s :: k) (a :: k) = Cotraversal s s a a Source Github #
type Kaleidoscope (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Kaleidoscope' (s :: k) (a :: k) = Kaleidoscope s s a a Source Github #
type AlgebraicLens (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (AlgLensFl m)) s t a b Source Github #
An algebraic lens: like a Lens, but put is allowed to combine
information monadically -- get :: s ~> a, put :: m % s ** b ~> t -- rather than only ever
seeing the last s.
type ClassifyingLens (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (ClassifyFl l)) s t a b Source Github #
type Tracer (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
Building optics
iso :: forall {j} {k} (c :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k) => (s ~> a) -> (b ~> t) -> Optic c s t a b Source Github #
Create an isomorphism from two arrows, at any optic constraint. Note that this doesn't enforce that the arrows are actually inverses!
The same iso builds a Iso, a PIso, a
PTraversal, ... depending on the type it is used at; since c is
only determined by the use site, bind the result with a type signature.
lens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (HasBinaryProducts k, Ob b) => (s ~> a) -> ((s && b) ~> t) -> Lens s t a b Source Github #
monLens :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Comonoid m, Ob a, Ob b) => (s ~> (m ** a)) -> ((m ** b) ~> t) -> MonoidalLens s t a b Source Github #
Build a monoidal lens from its two legs and a chosen comonoidal residual m.
prism :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => (b ~> t) -> (s ~> (t || a)) -> Prism s t a b Source Github #
affineTraversal :: forall {k} (s :: k) (t :: k) (x :: k) (y :: k) (a :: k) (b :: k). CategoryOf k => Lens s t x y -> Prism x y a b -> AffineTraversal s t a b Source Github #
Build an AffineTraversal by composing a Lens with a Prism: focus a field with the lens,
then match a case of that field with the prism. There is no from-legs builder for a bare affine
traversal (its witness only ever arises by composition), so this is the design-aligned way to
make one -- the same idiom the test suite uses.convert (l % p)
grate :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Closed k, SymMonoidal k, HasCoproducts k, Comonoid (s ~~> a), Ob s, Ob a, Ob b) => (((s ~~> a) ~~> b) ~> t) -> Grate s t a b Source Github #
The canonical/atomic grate constructor: the residual is the self-referential s ~~> a
(the "logarithm" of the get side), whose own get-map m ~> (s ~~> a) trivializes to id once
m is fixed to be exactly s ~~> a. That residual must be a comonoid; in a
CopyDiscard category every object is.
glass :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CCC k, Ob s, Ob a, Ob b) => ((s && ((s ~~> a) ~~> b)) ~> t) -> Glass s t a b Source Github #
Build a glass from its single leg. The residuals are the whole source and the "logarithm"
s ~~> a, so the witness is the lens witness at s composed with the grate witness at s ~~> a.
powerGrate :: forall {k} (n :: Nat) (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, KnownNat n, Ob a, Ob b) => (s ~> Tensor n a) -> (Tensor n b ~> t) -> PowerGrate s t a b Source Github #
Build an n-ary power grate from a tensor-power decomposition of s and recomposition
of t.
cotraversal :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Cotraversal s t a b Source Github #
Build a cotraversal from its legs through an applicative functor, given as a representable
StrongDistributiveProfunctor p.
kaleidoscope :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Kaleidoscope s t a b Source Github #
Build a kaleidoscope from the same legs.
algebraicLens :: forall {k} (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra m (m % s), Comonoid (m % s), Comonoid s, OplaxMonoidalRep m, Ob a, Ob b) => (s ~> a) -> (((m % s) ** b) ~> t) -> AlgebraicLens m s t a b Source Github #
Build an algebraic lens from get and a monadic put; the residual is the free algebra
m % s itself (which must be a comonoid, as must s to be kept alongside its focus).
classifyingLens :: forall {k} (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra l (l % s), Monoid (l % s), Comonoid (l % s), Comonoid s, OplaxMonoidalRep l, SymMonoidal k, HasCoproducts k, Ob a, Ob b) => (s ~> a) -> (((l % s) ** b) ~> t) -> ClassifyingLens l s t a b Source Github #
Build a classifying lens from get and a classify :: l % s ** b ~> t; the residual is the
free algebra l % s, e.g. the list of sources.
tracer :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (TracedMonoidal k, Ob m, Ob s, Ob t, Ob a, Ob b) => ((m ** s) ~> a) -> (b ~> (m ** t)) -> Tracer s t a b Source Github #
Build a tracer from its two legs and a chosen residual m: m ** s ~> a decomposes the source
(given the residual), b ~> m ** t rebuilds the target and produces the residual to feed back.
traversed :: forall {k} (t :: k +-> k) (a :: k) (b :: k). (Bicartesian k, Traversable t, Representable t, Ob a, Ob b) => Traversal (t % a) (t % b) a b Source Github #
Build a traversal from a Traversable (representable) functor t: it focuses every element
the functor holds. This is the one weak-flavor builder that is genuinely primitive -- a
Traversables traversal is not reachable by convert from any single stronger optic. The
witness is t itself paired with (see RepCostar tTravFl above); the two legs are the
representable universal and the identity repUnivRepCostar.
traversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k, HasProducts k, Ob a, Ob b, Ob s, Ob t) => (forall (r :: k +-> k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => r a b -> r s t) -> Traversal s t a b Source Github #
Build a Traversal from its van-Laarhoven / profunctor-class form, by instantiating the
rank-2 function at the generic carrier (a ExOptic TravFl a bStrongDistributiveProfunctor
and , unlike Strong ProdAction, since ExOptic MonTravFl a bTravFl contains the
product-lens witness). The Traversal analog of fromPTraversal.
to :: forall {k} {j} (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf k, CategoryOf j, Ob b, Ob t) => (s ~> a) -> Getter s t a b Source Github #
unto :: forall {k} {j} (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf k, CategoryOf j, Ob s, Ob a) => (b ~> t) -> Review s t a b Source Github #
re :: forall {j} {k} (a :: j) (b :: k) (c :: (k +-> j) -> Constraint) (coc :: (j +-> k) -> Constraint) (s :: j) (t :: k). (Ob a, Ob b, ReversibleOptic c coc) => Optic c s t a b -> Optic coc b a t s Source Github #
Eliminating optics
Exactly one eliminator per flavor: view, review, preview, over, foldMapOf,
traverseOf, monTraverseOf, powerGrateOf, cotraverseOf, kaleidoscopeOf, zipWithOf,
classifyOf and tracerOf run the optic; withIso, withLens,
withMonLens, withPrism and withGrate recover its two legs.
view :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, (Ob a, Ob b) => c (ExOptic (GetterFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> s ~> a Source Github #
review :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, (Ob a, Ob b) => c (ExOptic (Flip (GetterFl :: (j +-> j) -> (k +-> k) -> Constraint)) a b)) => Optic c s t a b -> b ~> t Source Github #
Review through any optic that can act as a review, in either encoding: getP on the flipped
witness pair.
preview :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (Bicartesian k, CategoryOf j, (Ob a, Ob b) => c (ExOptic (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> s ~> (a || (TerminalObject :: k)) Source Github #
Preview through any optic that can act as an affine fold, in either encoding: run it at its
witness pair (ExOptic AffineFoldFl, via withLegs) and apply previewP.
matching :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (Bicartesian k, (Ob a, Ob b) => c (ExOptic (AffineTravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> s ~> (t || a) Source Github #
Match through any optic that can act as an affine traversal, in either encoding: returns the
focus () when it matches, or a reconstructed rgtt () when it does not. This is the
lftAffineTraversal eliminator, refining preview (which forgets t).
Runs the optic at its witness pair (ExOptic AffineTravFl, via withLegs) and applies
affineMatch.
over :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (CategoryOf k, (Ob a, Ob b) => c (ExOptic (SetterFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (a ~> b) -> s ~> t Source Github #
foldMapOf :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (m :: k) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, Ob m, Monoid m, (Ob a, Ob b) => c (ExOptic (FoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> (a ~> m) -> s ~> m Source Github #
traverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, Strong (ProdAction :: k -> (PROD k, k) -> Type) p, (Ob a, Ob b) => c (ExOptic (TravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t Source Github #
Traverse: distribute any StrongDistributiveProfunctor -- not merely a Star f (the
Hask van-Laarhoven shape) -- through any optic that is at least a Traversal. Works for an
arbitrary profunctor carrier by handing it to travP, rather than relying on a per-carrier
bridge (which could only ever cover specific carrier heads).Prostrong w p
The optic is accepted in any encoding: the constraint asks the optic's class to hold for the
generic carrier , which a ExOptic TravFl a bProstrong-flavored optic discharges via
forall p q. w p q => , a Sub TravFl p q(%)-composite one conjunct at a time, and a profunctor-class one
(PTraversalFull) through the carrier's by-generator instances.
monTraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, (Ob a, Ob b) => c (ExOptic (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t Source Github #
Like traverseOf, but for a MonoidalTraversal -- distributes any StrongDistributiveProfunctor
with no product-strength requirement on the carrier. Every non-lens traversal (prism,
Traversable functor, ...) is a monoidal traversal, so this accepts carriers like
that are tensor-strong but not product-strong.Writer w
Accepts any encoding (cf. traverseOf): a PTraversal works directly,
as does a (%)-composite.
powerGrateOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, MonoidalProfunctor r, (Ob a, Ob b) => c (ExOptic (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #
Distribute any MonoidalProfunctor through a power grate (or any stronger optic). At the
hom ( this is ~>)over; at an applicative the foci are
combined through Star ff.
Accepts any encoding (cf. traverseOf), including (%)-composites.
cotraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Cotraversable r, (Ob a, Ob b) => c (ExOptic (CotravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #
Pass a Cotraversable carrier through a cotraversal (or any stronger optic, in any encoding,
(%)-composites included).
kaleidoscopeOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Kaleidoscopic r, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #
Act on a Kaleidoscopic carrier through a kaleidoscope (or any stronger optic, in any
encoding, (%)-composites included). At this is the literature's
aggregation operator Costar []>-: from [a] -> b to [s] -> t.
zipWithOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (Monoidal k, Ob a, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((a ** a) ~> b) -> (s ** s) ~> t Source Github #
Zip two sources through a Kaleidoscope (or any stronger optic, a
Grate in particular, in any encoding): combine the foci pairwise. This is
kaleidoscopeOf at the carrier , the costar of the binary tensor power --
a binary combination RepCostar (Pow 2)(a ** a) ~> b of foci, which the optic's applicative lifts by liftA2.
classifyOf :: forall {k} (m :: k +-> k) (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (OplaxMonoidalRep m, Comonoid a, (Ob a, Ob b) => c (ExOptic (AlgLensFl m) a b)) => Optic c s t a b -> ((m % s) ** b) ~> t Source Github #
Classify a monadic computation of s's through an AlgebraicLens (or any stronger optic,
in any encoding), given a replacement focus b -- generalizing "set" to combine every s the
computation might produce (via its residual's Algebra) rather than only ever seeing the last one.
The focus a is discarded under the monad, hence must be a comonoid.
tracerOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, Costrong (Tensor :: k -> (k, k) -> Type) r, c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #
Distribute any Costrong profunctor through a tracer (or any stronger optic). At the hom this
is over, computing the feedback loop through the residual.
Accepts any encoding (cf. traverseOf): a PTracer works directly, as
does a (%)-composite.
withIso :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, (Ob a, Ob b) => c (Yo a ('OP b))) => Optic c s t a b -> ((s ~> a) -> (b ~> t) -> r) -> r Source Github #
withLens :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryProducts k, (Ob a, Ob b) => c (ExOptic (LensFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((s ~> a) -> ((s && b) ~> t) -> r) -> r Source Github #
withMonLens :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (SymMonoidal k, (Ob a, Ob b) => c (ExOptic (MonLensFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (forall (m :: k). Ob m => ComonoidOn m -> (s ~> (m ** a)) -> ((m ** b) ~> t) -> r) -> r Source Github #
Eliminate any optic that is at least an iso and at most a monoidal lens to its two legs,
recovering the existential residual m together with its comonoid structure: run it at its
witness pair (ExOptic MonLensFl, via withLegs) and read the legs off with withMonLensP.
withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (ExOptic (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((b ~> t) -> (s ~> (t || a)) -> r) -> r Source Github #
withGrate :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Closed k, SymMonoidal k, (Ob a, Ob b) => c (ExOptic (GrateFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t) -> r) -> r Source Github #
withGlass :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CCC k, (Ob a, Ob b) => c (ExOptic (GlassFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (((s && ((s ~~> a) ~~> b)) ~> t) -> r) -> r Source Github #
Eliminate any glass-flavored optic (a lens, a grate, or a composite of both, in either encoding) to its single leg.
Operators and shorthands
(^.) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (GetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => s -> Optic c s t a b -> a infixl 8 Source Github #
View the focus of a concrete, Type-level optic.
(#) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (Flip (GetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint)) a b) => Optic c s t a b -> b -> t infixr 8 Source Github #
Review through a concrete, Type-level optic.
(^?) :: forall s t a b (c :: (Type -> Type -> Type) -> Constraint). c (ExOptic (AffineFoldFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => s -> Optic c s t a b -> Maybe a infixl 8 Source Github #
Preview the focus of a concrete, Type-level optic (a getter that might not match).
(.?) :: forall f (c :: (Type -> Type -> Type) -> Constraint) s t a b. (Monad f, Functor f, c (ExOptic (AlgLensFl (Star f)) a b)) => Optic c s t a b -> b -> f s -> t infixl 8 Source Github #
classifyOf for a Haskell monad, curried: optic .? b $ fs.
set :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> b -> s -> t Source Github #
Named version of (.~).
(%~) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> (a -> b) -> s -> t infixl 8 Source Github #
Apply a function through a concrete, Type-level Setter.
(.~) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => Optic c s t a b -> b -> s -> t infixl 8 Source Github #
Replace the focus/foci of a concrete, Type-level Setter with a constant value.
unfold :: forall {k} (c :: (OPPOSITE k -> OPPOSITE k -> Type) -> Constraint) (cm :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Comonoid cm, Ob cm, forall (p :: OPPOSITE k +-> OPPOSITE k). c p => c (Op (UnOp p)), (Ob a, Ob b) => c (ExOptic (FoldFl :: (OPPOSITE k +-> OPPOSITE k) -> (OPPOSITE k +-> OPPOSITE k) -> Constraint) ('OP b) ('OP a))) => Optic (OpConstraint c) s t a b -> (cm ~> b) -> cm ~> t Source Github #
Composing and converting optics
(%) :: forall {j} {k} (c1 :: (j +-> k) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j) (c2 :: (j +-> k) -> Constraint) (c :: k) (d :: j). Optic c1 s t a b -> Optic c2 a b c d -> Optic (c1 :&&: c2) s t c d infixl 9 Source Github #
Compose two optics, of any (possibly different) flavors or encodings. The composite's constraint
is the conjunction :&&:, so the composite is automatically usable at exactly the meet of the two
flavors' capabilities: a lens composed with a prism previews, folds, traverses and sets, but
no longer views or reviews. Use convert to name the composite at a single flavor for
storage, e.g. .convert (l % p) :: AffineTraversal s t a b
convert :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (w :: FLAVOR j k) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, Flavor w, (Ob a, Ob b) => c (ExOptic w a b)) => Optic c s t a b -> Optic (Prostrong w) s t a b Source Github #
Convert an optic to a chosen flavor w, by running it at its existential encoding
and wrapping the resulting witness pair back around the carrier: this works for
any input encoding. A ExOptic w a bProstrong-flavored optic converts along the subtyping lattice (via the
bridge instance of ExOptic; an invalid conversion fails with Could not deduce (w p q) for the
missing superclass), a :&&:-composite converts when both conjuncts do, and a
profunctor-class-flavored optic converts when has an instance of its class -- which
it does for every class whose generating witnesses ExOptic w a bw contains (cf. fromPIso,
fromPTraversal, fromPTracer).
Consumers accept any sufficiently strong optic directly, so this is rarely needed to use an
optic; but constructors and % return their exact type monomorphically, so it is the way to
store an optic at a weaker type, e.g. convert (.lens f g) ::
Traversal' s a
class (Monad m, Ob a) => Algebra (m :: k +-> k) (a :: k) where Source Github #
An Eilenberg-Moore algebra for the monad m -- a representable Promonad on k, acting as
the functor m (Proarrow.Promonad): a structure map % -m % a ~> a, coherent with the
monad's unit and multiplication. The free algebras m % s are the ones an algebraic lens is
built from (algebraicLens).
There are deliberately no instances for the unit or for products of algebras, and there cannot be:
Unit and ( are type families, which may not head an instance. That is why **)withAlgP
passes the structure map as a value -- the composition instance pairs two algebras with
unparRep and the identity witness supplies the unit one with unpar0Rep, neither needing an
Algebra instance. A witness pair whose residual is the unit is the identity optic up to the
unitors, so nothing is lost.
toPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => MonoidalTraversal s t a b -> PTraversal s t a b Source Github #
Half of the equivalence between the two traversal encodings: eliminate the existential
witnesses with travP at the caller's profunctor.
toPTraversalFull :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => Traversal s t a b -> PTraversalFull s t a b Source Github #
Eliminate a Traversal to its profunctor-class form (the analog of toPTraversal): run travP
at the caller's profunctor.
fromPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k) => PTraversal s t a b -> MonoidalTraversal s t a b Source Github #
The other half of the equivalence between the encodings: instantiate the
profunctor-class-flavored traversal at the generic carrier , which is
an SDP by the by-generator instances above. Because its tensor strength comes from the
tensor-action witness ExOptic MonTravFl a b (not a product lens), this needs no
Rep (ActionAt Tensor _)Cartesian (tensor = product), only CopyDiscard (a discard a Mat~> Unit for the residual) -- which is
exactly what the coproduct-prism witness already demanded -- enabling e.g. the biproduct
categories and FinRel (but not LINEAR, which cannot discard). A Traversal is
recovered for free wherever one is needed, since MonTravFl@ is a subflavor of TravFl.