Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Optic (k :: OpticKind) is s t a b
- type Optic' k is s a = Optic k is s s a a
- type OpticKind = OpticKind_ -> Type
- class Is k l
- 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
- type family Join (k :: OpticKind) (l :: OpticKind) :: OpticKind where ...
- (%) :: (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
- (%%) :: 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
- class Append (xs :: [Type]) (ys :: [Type]) (zs :: [Type]) | xs ys -> zs, zs xs -> ys
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.
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.
implies
Instances
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)
.
(%) :: (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 # | |
Defined in Optics.Internal.Optic.TypeLevel | |
Append xs ys zs => Append (x ': xs) ys (x ': zs) # | |
Defined in Optics.Internal.Optic.TypeLevel |