optics-core-0.1

Safe HaskellNone
LanguageHaskell2010

Optics.Optic

Synopsis

Documentation

data Optic (k :: OpticKind) is s t a b #

Wrapper newtype for the whole family of vaguely lens-like things.

The first type parameter k identifies the particular flavour (e.g. A_Lens or A_Traversal).

The type parameters s and t represent the "big" structure, whereas a and b represent the "small" structure.

TODO: explain indices

type Optic' k is s a = Optic k is s s a a #

Common special case of Optic where source and target types are equal.

Here, we need only one "big" and one "small" type. For lenses, this means that in the restricted form we cannot do type-changing updates.

type OpticKind = OpticKind_ -> Type #

class Is k l #

Subtyping relationship between flavours of optics.

An instance of Is k l represents that any Optic k can be used as an Optic l. For example, we have an Is A_Lens A_Traversal instance, but not Is A_Traversal A_Lens.

This class needs instances for all possible combinations of tags.

Minimal complete definition

implies

Instances
Is k k #

Every flavour of optic can be used as itself.

Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy k k p -> (Constraints k p -> r) -> Constraints k p -> r

(TypeError ((ShowType k :<>: Text " cannot be used as ") :<>: ShowType l) :: Constraint) => Is k l #

Overlappable instance for a custom type error.

Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy k l p -> (Constraints k p -> r) -> Constraints l p -> r

Is A_LensyReview A_Review # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_LensyReview A_Review p -> (Constraints A_LensyReview p -> r) -> Constraints A_Review p -> r

Is An_AffineFold A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_AffineFold A_Fold p -> (Constraints An_AffineFold p -> r) -> Constraints A_Fold p -> r

Is A_Getter A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Getter A_Fold p -> (Constraints A_Getter p -> r) -> Constraints A_Fold p -> r

Is A_Getter An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Getter An_AffineFold p -> (Constraints A_Getter p -> r) -> Constraints An_AffineFold p -> r

Is A_PrismaticGetter A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_PrismaticGetter A_Fold p -> (Constraints A_PrismaticGetter p -> r) -> Constraints A_Fold p -> r

Is A_PrismaticGetter An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_PrismaticGetter An_AffineFold p -> (Constraints A_PrismaticGetter p -> r) -> Constraints An_AffineFold p -> r

Is A_PrismaticGetter A_Getter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_PrismaticGetter A_Getter p -> (Constraints A_PrismaticGetter p -> r) -> Constraints A_Getter p -> r

Is A_Traversal A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Traversal A_Fold p -> (Constraints A_Traversal p -> r) -> Constraints A_Fold p -> r

Is A_Traversal A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Traversal A_Setter p -> (Constraints A_Traversal p -> r) -> Constraints A_Setter p -> r

Is An_AffineTraversal A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_AffineTraversal A_Fold p -> (Constraints An_AffineTraversal p -> r) -> Constraints A_Fold p -> r

Is An_AffineTraversal An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_AffineTraversal An_AffineFold p -> (Constraints An_AffineTraversal p -> r) -> Constraints An_AffineFold p -> r

Is An_AffineTraversal A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_AffineTraversal A_Setter p -> (Constraints An_AffineTraversal p -> r) -> Constraints A_Setter p -> r

Is An_AffineTraversal A_Traversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_AffineTraversal A_Traversal p -> (Constraints An_AffineTraversal p -> r) -> Constraints A_Traversal p -> r

Is A_Prism A_Review # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism A_Review p -> (Constraints A_Prism p -> r) -> Constraints A_Review p -> r

Is A_Prism A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism A_Fold p -> (Constraints A_Prism p -> r) -> Constraints A_Fold p -> r

Is A_Prism An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism An_AffineFold p -> (Constraints A_Prism p -> r) -> Constraints An_AffineFold p -> r

Is A_Prism A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism A_Setter p -> (Constraints A_Prism p -> r) -> Constraints A_Setter p -> r

Is A_Prism A_Traversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism A_Traversal p -> (Constraints A_Prism p -> r) -> Constraints A_Traversal p -> r

Is A_Prism An_AffineTraversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Prism An_AffineTraversal p -> (Constraints A_Prism p -> r) -> Constraints An_AffineTraversal p -> r

Is A_Lens A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens A_Fold p -> (Constraints A_Lens p -> r) -> Constraints A_Fold p -> r

Is A_Lens An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens An_AffineFold p -> (Constraints A_Lens p -> r) -> Constraints An_AffineFold p -> r

Is A_Lens A_Getter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens A_Getter p -> (Constraints A_Lens p -> r) -> Constraints A_Getter p -> r

Is A_Lens A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens A_Setter p -> (Constraints A_Lens p -> r) -> Constraints A_Setter p -> r

Is A_Lens A_Traversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens A_Traversal p -> (Constraints A_Lens p -> r) -> Constraints A_Traversal p -> r

Is A_Lens An_AffineTraversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy A_Lens An_AffineTraversal p -> (Constraints A_Lens p -> r) -> Constraints An_AffineTraversal p -> r

Is An_Iso A_Review # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Review p -> (Constraints An_Iso p -> r) -> Constraints A_Review p -> r

Is An_Iso A_LensyReview # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_LensyReview p -> (Constraints An_Iso p -> r) -> Constraints A_LensyReview p -> r

Is An_Iso A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Fold p -> (Constraints An_Iso p -> r) -> Constraints A_Fold p -> r

Is An_Iso An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso An_AffineFold p -> (Constraints An_Iso p -> r) -> Constraints An_AffineFold p -> r

Is An_Iso A_Getter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Getter p -> (Constraints An_Iso p -> r) -> Constraints A_Getter p -> r

Is An_Iso A_PrismaticGetter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_PrismaticGetter p -> (Constraints An_Iso p -> r) -> Constraints A_PrismaticGetter p -> r

Is An_Iso A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Setter p -> (Constraints An_Iso p -> r) -> Constraints A_Setter p -> r

Is An_Iso A_Traversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Traversal p -> (Constraints An_Iso p -> r) -> Constraints A_Traversal p -> r

Is An_Iso An_AffineTraversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso An_AffineTraversal p -> (Constraints An_Iso p -> r) -> Constraints An_AffineTraversal p -> r

Is An_Iso A_Prism # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Prism p -> (Constraints An_Iso p -> r) -> Constraints A_Prism p -> r

Is An_Iso A_Lens # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Iso A_Lens p -> (Constraints An_Iso p -> r) -> Constraints A_Lens p -> r

Is An_Equality A_Review # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Review p -> (Constraints An_Equality p -> r) -> Constraints A_Review p -> r

Is An_Equality A_LensyReview # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_LensyReview p -> (Constraints An_Equality p -> r) -> Constraints A_LensyReview p -> r

Is An_Equality A_Fold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Fold p -> (Constraints An_Equality p -> r) -> Constraints A_Fold p -> r

Is An_Equality An_AffineFold # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality An_AffineFold p -> (Constraints An_Equality p -> r) -> Constraints An_AffineFold p -> r

Is An_Equality A_Getter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Getter p -> (Constraints An_Equality p -> r) -> Constraints A_Getter p -> r

Is An_Equality A_PrismaticGetter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_PrismaticGetter p -> (Constraints An_Equality p -> r) -> Constraints A_PrismaticGetter p -> r

Is An_Equality A_Setter # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Setter p -> (Constraints An_Equality p -> r) -> Constraints A_Setter p -> r

Is An_Equality A_Traversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Traversal p -> (Constraints An_Equality p -> r) -> Constraints A_Traversal p -> r

Is An_Equality An_AffineTraversal # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality An_AffineTraversal p -> (Constraints An_Equality p -> r) -> Constraints An_AffineTraversal p -> r

Is An_Equality A_Prism # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Prism p -> (Constraints An_Equality p -> r) -> Constraints A_Prism p -> r

Is An_Equality A_Lens # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality A_Lens p -> (Constraints An_Equality p -> r) -> Constraints A_Lens p -> r

Is An_Equality An_Iso # 
Instance details

Defined in Optics.Internal.Optic.Subtyping

Methods

implies :: proxy An_Equality An_Iso p -> (Constraints An_Equality p -> r) -> Constraints An_Iso p -> r

sub :: forall k l is s t a b. Is k l => Optic k is s t a b -> Optic l is s t a b #

Explicit cast from one optic flavour to another.

This is the identity function, modulo some constraint jiggery-pokery.

TODO: add a graph

type family Join (k :: OpticKind) (l :: OpticKind) :: OpticKind where ... #

Computes the least upper bound of two optics flavours.

Join k l represents the least upper bound of an Optic k and an Optic l. This means in particular that composition of an Optic k and an Optic k will yield an Optic (Join k l).

Equations

Join An_Equality An_Iso = An_Iso 
Join An_Equality A_LensyReview = A_LensyReview 
Join An_Equality A_PrismaticGetter = A_PrismaticGetter 
Join An_Equality A_Prism = A_Prism 
Join An_Equality A_Review = A_Review 
Join An_Equality A_Lens = A_Lens 
Join An_Equality A_Getter = A_Getter 
Join An_Equality An_AffineTraversal = An_AffineTraversal 
Join An_Equality An_AffineFold = An_AffineFold 
Join An_Equality A_Traversal = A_Traversal 
Join An_Equality A_Fold = A_Fold 
Join An_Equality A_Setter = A_Setter 
Join An_Iso An_Equality = An_Iso 
Join An_Iso A_LensyReview = A_LensyReview 
Join An_Iso A_PrismaticGetter = A_PrismaticGetter 
Join An_Iso A_Prism = A_Prism 
Join An_Iso A_Review = A_Review 
Join An_Iso A_Lens = A_Lens 
Join An_Iso A_Getter = A_Getter 
Join An_Iso An_AffineTraversal = An_AffineTraversal 
Join An_Iso An_AffineFold = An_AffineFold 
Join An_Iso A_Traversal = A_Traversal 
Join An_Iso A_Fold = A_Fold 
Join An_Iso A_Setter = A_Setter 
Join A_LensyReview An_Equality = A_LensyReview 
Join A_LensyReview An_Iso = A_LensyReview 
Join A_LensyReview A_Prism = A_Review 
Join A_LensyReview A_Review = A_Review 
Join A_PrismaticGetter An_Equality = A_PrismaticGetter 
Join A_PrismaticGetter An_Iso = A_PrismaticGetter 
Join A_PrismaticGetter A_Prism = An_AffineFold 
Join A_PrismaticGetter A_Lens = A_Getter 
Join A_PrismaticGetter A_Getter = A_Getter 
Join A_PrismaticGetter An_AffineTraversal = An_AffineFold 
Join A_PrismaticGetter An_AffineFold = An_AffineFold 
Join A_PrismaticGetter A_Traversal = A_Fold 
Join A_PrismaticGetter A_Fold = A_Fold 
Join A_Prism An_Equality = A_Prism 
Join A_Prism An_Iso = A_Prism 
Join A_Prism A_LensyReview = A_Review 
Join A_Prism A_PrismaticGetter = An_AffineFold 
Join A_Prism A_Review = A_Review 
Join A_Prism A_Lens = An_AffineTraversal 
Join A_Prism A_Getter = An_AffineFold 
Join A_Prism An_AffineTraversal = An_AffineTraversal 
Join A_Prism An_AffineFold = An_AffineFold 
Join A_Prism A_Traversal = A_Traversal 
Join A_Prism A_Fold = A_Fold 
Join A_Prism A_Setter = A_Setter 
Join A_Review An_Equality = A_Review 
Join A_Review An_Iso = A_Review 
Join A_Review A_LensyReview = A_Review 
Join A_Review A_Prism = A_Review 
Join A_Lens An_Equality = A_Lens 
Join A_Lens An_Iso = A_Lens 
Join A_Lens A_PrismaticGetter = A_Getter 
Join A_Lens A_Prism = An_AffineTraversal 
Join A_Lens A_Getter = A_Getter 
Join A_Lens An_AffineTraversal = An_AffineTraversal 
Join A_Lens An_AffineFold = An_AffineFold 
Join A_Lens A_Traversal = A_Traversal 
Join A_Lens A_Fold = A_Fold 
Join A_Lens A_Setter = A_Setter 
Join A_Getter An_Equality = A_Getter 
Join A_Getter An_Iso = A_Getter 
Join A_Getter A_PrismaticGetter = A_Getter 
Join A_Getter A_Prism = An_AffineFold 
Join A_Getter A_Lens = A_Getter 
Join A_Getter An_AffineTraversal = An_AffineFold 
Join A_Getter An_AffineFold = An_AffineFold 
Join A_Getter A_Traversal = A_Fold 
Join A_Getter A_Fold = A_Fold 
Join An_AffineTraversal An_Equality = An_AffineTraversal 
Join An_AffineTraversal An_Iso = An_AffineTraversal 
Join An_AffineTraversal A_PrismaticGetter = An_AffineFold 
Join An_AffineTraversal A_Prism = An_AffineTraversal 
Join An_AffineTraversal A_Lens = An_AffineTraversal 
Join An_AffineTraversal A_Getter = An_AffineFold 
Join An_AffineTraversal An_AffineFold = An_AffineFold 
Join An_AffineTraversal A_Traversal = A_Traversal 
Join An_AffineTraversal A_Fold = A_Fold 
Join An_AffineTraversal A_Setter = A_Setter 
Join An_AffineFold An_Equality = An_AffineFold 
Join An_AffineFold An_Iso = An_AffineFold 
Join An_AffineFold A_PrismaticGetter = An_AffineFold 
Join An_AffineFold A_Prism = An_AffineFold 
Join An_AffineFold A_Lens = An_AffineFold 
Join An_AffineFold A_Getter = An_AffineFold 
Join An_AffineFold An_AffineTraversal = An_AffineFold 
Join An_AffineFold A_Traversal = A_Fold 
Join An_AffineFold A_Fold = A_Fold 
Join A_Traversal An_Equality = A_Traversal 
Join A_Traversal An_Iso = A_Traversal 
Join A_Traversal A_PrismaticGetter = A_Fold 
Join A_Traversal A_Prism = A_Traversal 
Join A_Traversal A_Lens = A_Traversal 
Join A_Traversal A_Getter = A_Fold 
Join A_Traversal An_AffineTraversal = A_Traversal 
Join A_Traversal An_AffineFold = A_Fold 
Join A_Traversal A_Fold = A_Fold 
Join A_Traversal A_Setter = A_Setter 
Join A_Fold An_Equality = A_Fold 
Join A_Fold An_Iso = A_Fold 
Join A_Fold A_PrismaticGetter = A_Fold 
Join A_Fold A_Prism = A_Fold 
Join A_Fold A_Lens = A_Fold 
Join A_Fold A_Getter = A_Fold 
Join A_Fold An_AffineTraversal = A_Fold 
Join A_Fold An_AffineFold = A_Fold 
Join A_Fold A_Traversal = A_Fold 
Join A_Setter An_Equality = A_Setter 
Join A_Setter An_Iso = A_Setter 
Join A_Setter A_Prism = A_Setter 
Join A_Setter A_Lens = A_Setter 
Join A_Setter An_AffineTraversal = A_Setter 
Join A_Setter A_Traversal = A_Setter 
Join k k = k 
Join k l = TypeError ((ShowType k :<>: Text " cannot be composed with ") :<>: ShowType l) 

(%) :: (Is k m, Is l m, m ~ Join k l, Append is js ks) => Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b #

Compose two optics of compatible flavours.

Returns an optic of the appropriate supertype.

(%%) :: forall k is js ks s t u v a b. Append is js ks => Optic k is s t u v -> Optic k js u v a b -> Optic k ks s t a b #

Compose two optics of the same flavour.

class Append (xs :: [Type]) (ys :: [Type]) (zs :: [Type]) | xs ys -> zs, zs xs -> ys #

AppendProof is a very simple class which provides a witness

foldr f (foldr f init xs) ys = foldr f init (ys ++ xs)
   where f = (->)

However, Append is unsafe variant of AppendProof, i.e. doesn't provide the witness; only calculates and restricts the arguments.

Instances
Append ([] :: [Type]) ys ys # 
Instance details

Defined in Optics.Internal.Optic.TypeLevel

Append xs ys zs => Append (x ': xs) ys (x ': zs) # 
Instance details

Defined in Optics.Internal.Optic.TypeLevel