module Lens.Family.Clone
( cloneAdapter, cloneLens, cloneGrate, cloneTraversal, cloneSetter, cloneResetter, cloneGetter, cloneFold
, AnAdapter, AnAdapter'
, ALens, ALens'
, ATraversal, ATraversal'
, AGetter, AGetter'
, AFold, AFold'
, PStore, PKleeneStore
, LensLike, LensLike', GrateLike, GrateLike', FoldLike, FoldLike', AGrate, ASetter, AResetter
, Phantom, Identical
) where
import Lens.Family.Unchecked
import Lens.Family
data PStore i j a = PStore (j -> a) i
instance Functor (PStore i j) where
fmap :: forall a b. (a -> b) -> PStore i j a -> PStore i j b
fmap a -> b
f (PStore j -> a
g i
i) = (j -> b) -> i -> PStore i j b
forall i j a. (j -> a) -> i -> PStore i j a
PStore (a -> b
f (a -> b) -> (j -> a) -> j -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. j -> a
g) i
i
type AnAdapter s t a b = AdapterLike (PStore (s -> a) b) ((->) s) s t a b
type AnAdapter' s a = AdapterLike' (PStore (s -> a) a) ((->) s) s a
cloneAdapter :: (Functor f, Functor g) => AnAdapter s t a b -> AdapterLike f g s t a b
cloneAdapter :: forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnAdapter s t a b -> AdapterLike f g s t a b
cloneAdapter AnAdapter s t a b
univ = (s -> a) -> (b -> t) -> AdapterLike f g s t a b
forall (f :: * -> *) (g :: * -> *) s a b t.
(Functor f, Functor g) =>
(s -> a) -> (b -> t) -> AdapterLike f g s t a b
adapter s -> a
yin b -> t
yang
where
PStore b -> t
yang s -> a
yin = AnAdapter s t a b
univ ((b -> b) -> (s -> a) -> PStore (s -> a) b b
forall i j a. (j -> a) -> i -> PStore i j a
PStore b -> b
forall a. a -> a
id) s -> s
forall a. a -> a
id
type ALens s t a b = LensLike (PStore a b) s t a b
type ALens' s a = LensLike' (PStore a a) s a
cloneLens :: Functor f => ALens s t a b -> LensLike f s t a b
cloneLens :: forall (f :: * -> *) s t a b.
Functor f =>
ALens s t a b -> LensLike f s t a b
cloneLens ALens s t a b
univ a -> f b
f = (a -> f b) -> PStore a b t -> f t
forall (f :: * -> *) a b t.
Functor f =>
(a -> f b) -> PStore a b t -> f t
experiment a -> f b
f (PStore a b t -> f t) -> (s -> PStore a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ALens s t a b
univ ((b -> b) -> a -> PStore a b b
forall i j a. (j -> a) -> i -> PStore i j a
PStore b -> b
forall a. a -> a
id)
experiment :: Functor f => (a -> f b) -> PStore a b t -> f t
experiment :: forall (f :: * -> *) a b t.
Functor f =>
(a -> f b) -> PStore a b t -> f t
experiment a -> f b
f (PStore b -> t
g a
a) = b -> t
g (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a
data PKleeneStore i j a = Unit a
| Battery (PKleeneStore i j (j -> a)) i
instance Functor (PKleeneStore i j) where
fmap :: forall a b. (a -> b) -> PKleeneStore i j a -> PKleeneStore i j b
fmap a -> b
f (Unit a
a) = b -> PKleeneStore i j b
forall i j a. a -> PKleeneStore i j a
Unit (a -> b
f a
a)
fmap a -> b
f (Battery PKleeneStore i j (j -> a)
g i
i) = PKleeneStore i j (j -> b) -> i -> PKleeneStore i j b
forall i j a. PKleeneStore i j (j -> a) -> i -> PKleeneStore i j a
Battery (((j -> a) -> j -> b)
-> PKleeneStore i j (j -> a) -> PKleeneStore i j (j -> b)
forall a b. (a -> b) -> PKleeneStore i j a -> PKleeneStore i j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> b
f (a -> b) -> (j -> a) -> j -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) PKleeneStore i j (j -> a)
g) i
i
instance Applicative (PKleeneStore i j) where
pure :: forall a. a -> PKleeneStore i j a
pure = a -> PKleeneStore i j a
forall i j a. a -> PKleeneStore i j a
Unit
Unit a -> b
f <*> :: forall a b.
PKleeneStore i j (a -> b)
-> PKleeneStore i j a -> PKleeneStore i j b
<*> PKleeneStore i j a
a = a -> b
f (a -> b) -> PKleeneStore i j a -> PKleeneStore i j b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PKleeneStore i j a
a
Battery PKleeneStore i j (j -> a -> b)
f i
b <*> PKleeneStore i j a
a = PKleeneStore i j (j -> b) -> i -> PKleeneStore i j b
forall i j a. PKleeneStore i j (j -> a) -> i -> PKleeneStore i j a
Battery ((j -> a -> b) -> a -> j -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((j -> a -> b) -> a -> j -> b)
-> PKleeneStore i j (j -> a -> b) -> PKleeneStore i j (a -> j -> b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PKleeneStore i j (j -> a -> b)
f PKleeneStore i j (a -> j -> b)
-> PKleeneStore i j a -> PKleeneStore i j (j -> b)
forall a b.
PKleeneStore i j (a -> b)
-> PKleeneStore i j a -> PKleeneStore i j b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PKleeneStore i j a
a) i
b
type ATraversal s t a b = LensLike (PKleeneStore a b) s t a b
type ATraversal' s a = LensLike' (PKleeneStore a a) s a
cloneTraversal :: Applicative f => ATraversal s t a b -> LensLike f s t a b
cloneTraversal :: forall (f :: * -> *) s t a b.
Applicative f =>
ATraversal s t a b -> LensLike f s t a b
cloneTraversal ATraversal s t a b
univ a -> f b
f = (a -> f b) -> PKleeneStore a b t -> f t
forall (f :: * -> *) a b t.
Applicative f =>
(a -> f b) -> PKleeneStore a b t -> f t
research a -> f b
f (PKleeneStore a b t -> f t)
-> (s -> PKleeneStore a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ATraversal s t a b
univ (PKleeneStore a b (b -> b) -> a -> PKleeneStore a b b
forall i j a. PKleeneStore i j (j -> a) -> i -> PKleeneStore i j a
Battery ((b -> b) -> PKleeneStore a b (b -> b)
forall i j a. a -> PKleeneStore i j a
Unit b -> b
forall a. a -> a
id))
research :: Applicative f => (a -> f b) -> PKleeneStore a b t -> f t
research :: forall (f :: * -> *) a b t.
Applicative f =>
(a -> f b) -> PKleeneStore a b t -> f t
research a -> f b
_ (Unit t
a) = t -> f t
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure t
a
research a -> f b
f (Battery PKleeneStore a b (b -> t)
g a
b) = (a -> f b) -> PKleeneStore a b (b -> t) -> f (b -> t)
forall (f :: * -> *) a b t.
Applicative f =>
(a -> f b) -> PKleeneStore a b t -> f t
research a -> f b
f PKleeneStore a b (b -> t)
g f (b -> t) -> f b -> f t
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
b
cloneSetter :: Identical f => ASetter s t a b -> LensLike f s t a b
cloneSetter :: forall (f :: * -> *) s t a b.
Identical f =>
ASetter s t a b -> LensLike f s t a b
cloneSetter = ((a -> b) -> s -> t) -> LensLike f s t a b
forall (f :: * -> *) a b s t.
Identical f =>
((a -> b) -> s -> t) -> LensLike f s t a b
setting (((a -> b) -> s -> t) -> LensLike f s t a b)
-> (ASetter s t a b -> (a -> b) -> s -> t)
-> ASetter s t a b
-> LensLike f s t a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter s t a b -> (a -> b) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over
type AFold s t a b = FoldLike [a] s t a b
type AFold' s a = FoldLike' [a] s a
cloneFold :: (Phantom f, Applicative f) => AFold s t a b -> LensLike f s t a b
cloneFold :: forall (f :: * -> *) s t a b.
(Phantom f, Applicative f) =>
AFold s t a b -> LensLike f s t a b
cloneFold AFold s t a b
univ = (s -> [a]) -> LensLike f s t a b
forall (g :: * -> *) (f :: * -> *) s a t b.
(Foldable g, Phantom f, Applicative f) =>
(s -> g a) -> LensLike f s t a b
folding (AFold s t a b -> s -> [a]
forall a s t b. FoldLike [a] s t a b -> s -> [a]
toListOf AFold s t a b
univ)
cloneResetter :: Identical f => AResetter s t a b -> GrateLike f s t a b
cloneResetter :: forall (f :: * -> *) s t a b.
Identical f =>
AResetter s t a b -> GrateLike f s t a b
cloneResetter = ((a -> b) -> s -> t) -> GrateLike f s t a b
forall (g :: * -> *) a b s t.
Identical g =>
((a -> b) -> s -> t) -> GrateLike g s t a b
resetting (((a -> b) -> s -> t) -> GrateLike f s t a b)
-> (AResetter s t a b -> (a -> b) -> s -> t)
-> AResetter s t a b
-> GrateLike f s t a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AResetter s t a b -> (a -> b) -> s -> t
forall s t a b. AResetter s t a b -> (a -> b) -> s -> t
under
type AGetter s t a b = FoldLike a s t a b
type AGetter' s a = FoldLike' a s a
cloneGetter :: Phantom f => AGetter s t a b -> LensLike f s t a b
cloneGetter :: forall (f :: * -> *) s t a b.
Phantom f =>
AGetter s t a b -> LensLike f s t a b
cloneGetter AGetter s t a b
univ = (s -> a) -> LensLike f s t a b
forall (f :: * -> *) s a t b.
Phantom f =>
(s -> a) -> LensLike f s t a b
to (AGetter s t a b -> s -> a
forall a s t b. FoldLike a s t a b -> s -> a
view AGetter s t a b
univ)
cloneGrate :: Functor g => AGrate s t a b -> GrateLike g s t a b
cloneGrate :: forall (g :: * -> *) s t a b.
Functor g =>
AGrate s t a b -> GrateLike g s t a b
cloneGrate = (((s -> a) -> b) -> t) -> GrateLike g s t a b
forall (g :: * -> *) s a b t.
Functor g =>
(((s -> a) -> b) -> t) -> GrateLike g s t a b
grate ((((s -> a) -> b) -> t) -> GrateLike g s t a b)
-> (AGrate s t a b -> ((s -> a) -> b) -> t)
-> AGrate s t a b
-> GrateLike g s t a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AGrate s t a b -> ((s -> a) -> b) -> t
forall s t a b. AGrate s t a b -> ((s -> a) -> b) -> t
degrating