{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
#if !MIN_VERSION_transformers(0,6,0)
{-# OPTIONS_GHC -Wno-warnings-deprecations #-}
#endif
#include "lens-common.h"
module Control.Lens.Zoom
( Magnified
, Magnify(..)
, Zoom(..)
, Zoomed
) where
import Prelude ()
import Control.Lens.Getter
import Control.Lens.Internal.Prelude
import Control.Lens.Internal.Zoom
import Control.Lens.Type
import Control.Monad
import Control.Monad.Reader as Reader
import Control.Monad.State as State
import Control.Monad.Trans.State.Lazy as Lazy
import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
import Control.Monad.Trans.RWS.Lazy as Lazy
import Control.Monad.Trans.RWS.Strict as Strict
import Control.Monad.Trans.Except
import Control.Monad.Trans.Identity
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Free
#if !MIN_VERSION_transformers(0,6,0)
import Control.Monad.Trans.Error
import Control.Monad.Trans.List
#endif
import Data.Kind
infixr 2 `zoom`, `magnify`
type family Zoomed (m :: Type -> Type) :: Type -> Type -> Type
type instance Zoomed (Strict.StateT s z) = Focusing z
type instance Zoomed (Lazy.StateT s z) = Focusing z
type instance Zoomed (ReaderT e m) = Zoomed m
type instance Zoomed (IdentityT m) = Zoomed m
type instance Zoomed (Strict.RWST r w s z) = FocusingWith w z
type instance Zoomed (Lazy.RWST r w s z) = FocusingWith w z
type instance Zoomed (Strict.WriterT w m) = FocusingPlus w (Zoomed m)
type instance Zoomed (Lazy.WriterT w m) = FocusingPlus w (Zoomed m)
type instance Zoomed (MaybeT m) = FocusingMay (Zoomed m)
type instance Zoomed (ExceptT e m) = FocusingErr e (Zoomed m)
type instance Zoomed (FreeT f m) = FocusingFree f m (Zoomed m)
#if !MIN_VERSION_transformers(0,6,0)
type instance Zoomed (ErrorT e m) = FocusingErr e (Zoomed m)
type instance Zoomed (ListT m) = FocusingOn [] (Zoomed m)
#endif
type family Magnified (m :: Type -> Type) :: Type -> Type -> Type
type instance Magnified (ReaderT b m) = Effect m
type instance Magnified ((->)b) = Const
type instance Magnified (Strict.RWST a w s m) = EffectRWS w s m
type instance Magnified (Lazy.RWST a w s m) = EffectRWS w s m
type instance Magnified (IdentityT m) = Magnified m
class (MonadState s m, MonadState t n) => Zoom m n s t | m -> s, n -> t, m t -> n, n s -> m where
zoom :: LensLike' (Zoomed m c) t s -> m c -> n c
instance Monad z => Zoom (Strict.StateT s z) (Strict.StateT t z) s t where
zoom :: forall c.
LensLike' (Zoomed (StateT s z) c) t s
-> StateT s z c -> StateT t z c
zoom LensLike' (Zoomed (StateT s z) c) t s
l (Strict.StateT s -> z (c, s)
m) = (t -> z (c, t)) -> StateT t z c
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT ((t -> z (c, t)) -> StateT t z c)
-> (t -> z (c, t)) -> StateT t z c
forall a b. (a -> b) -> a -> b
$ Focusing z c t -> z (c, t)
forall (m :: * -> *) s a. Focusing m s a -> m (s, a)
unfocusing (Focusing z c t -> z (c, t))
-> (t -> Focusing z c t) -> t -> z (c, t)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (StateT s z) c) t s
l (z (c, s) -> Focusing z c s
forall (m :: * -> *) s a. m (s, a) -> Focusing m s a
Focusing (z (c, s) -> Focusing z c s)
-> (s -> z (c, s)) -> s -> Focusing z c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> z (c, s)
m)
{-# INLINE zoom #-}
instance Monad z => Zoom (Lazy.StateT s z) (Lazy.StateT t z) s t where
zoom :: forall c.
LensLike' (Zoomed (StateT s z) c) t s
-> StateT s z c -> StateT t z c
zoom LensLike' (Zoomed (StateT s z) c) t s
l (Lazy.StateT s -> z (c, s)
m) = (t -> z (c, t)) -> StateT t z c
forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Lazy.StateT ((t -> z (c, t)) -> StateT t z c)
-> (t -> z (c, t)) -> StateT t z c
forall a b. (a -> b) -> a -> b
$ Focusing z c t -> z (c, t)
forall (m :: * -> *) s a. Focusing m s a -> m (s, a)
unfocusing (Focusing z c t -> z (c, t))
-> (t -> Focusing z c t) -> t -> z (c, t)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (StateT s z) c) t s
l (z (c, s) -> Focusing z c s
forall (m :: * -> *) s a. m (s, a) -> Focusing m s a
Focusing (z (c, s) -> Focusing z c s)
-> (s -> z (c, s)) -> s -> Focusing z c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> z (c, s)
m)
{-# INLINE zoom #-}
instance Zoom m n s t => Zoom (ReaderT e m) (ReaderT e n) s t where
zoom :: forall c.
LensLike' (Zoomed (ReaderT e m) c) t s
-> ReaderT e m c -> ReaderT e n c
zoom LensLike' (Zoomed (ReaderT e m) c) t s
l (ReaderT e -> m c
m) = (e -> n c) -> ReaderT e n c
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT (LensLike' (Zoomed m c) t s -> m c -> n c
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike' (Zoomed m c) t s
LensLike' (Zoomed (ReaderT e m) c) t s
l (m c -> n c) -> (e -> m c) -> e -> n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m c
m)
{-# INLINE zoom #-}
instance Zoom m n s t => Zoom (IdentityT m) (IdentityT n) s t where
zoom :: forall c.
LensLike' (Zoomed (IdentityT m) c) t s
-> IdentityT m c -> IdentityT n c
zoom LensLike' (Zoomed (IdentityT m) c) t s
l (IdentityT m c
m) = n c -> IdentityT n c
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT (LensLike' (Zoomed m c) t s -> m c -> n c
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike' (Zoomed m c) t s
LensLike' (Zoomed (IdentityT m) c) t s
l m c
m)
{-# INLINE zoom #-}
instance (Monoid w, Monad z) => Zoom (Strict.RWST r w s z) (Strict.RWST r w t z) s t where
zoom :: forall c.
LensLike' (Zoomed (RWST r w s z) c) t s
-> RWST r w s z c -> RWST r w t z c
zoom LensLike' (Zoomed (RWST r w s z) c) t s
l (Strict.RWST r -> s -> z (c, s, w)
m) = (r -> t -> z (c, t, w)) -> RWST r w t z c
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST ((r -> t -> z (c, t, w)) -> RWST r w t z c)
-> (r -> t -> z (c, t, w)) -> RWST r w t z c
forall a b. (a -> b) -> a -> b
$ \r
r -> FocusingWith w z c t -> z (c, t, w)
forall w (m :: * -> *) s a. FocusingWith w m s a -> m (s, a, w)
unfocusingWith (FocusingWith w z c t -> z (c, t, w))
-> (t -> FocusingWith w z c t) -> t -> z (c, t, w)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (RWST r w s z) c) t s
l (z (c, s, w) -> FocusingWith w z c s
forall w (m :: * -> *) s a. m (s, a, w) -> FocusingWith w m s a
FocusingWith (z (c, s, w) -> FocusingWith w z c s)
-> (s -> z (c, s, w)) -> s -> FocusingWith w z c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. r -> s -> z (c, s, w)
m r
r)
{-# INLINE zoom #-}
instance (Monoid w, Monad z) => Zoom (Lazy.RWST r w s z) (Lazy.RWST r w t z) s t where
zoom :: forall c.
LensLike' (Zoomed (RWST r w s z) c) t s
-> RWST r w s z c -> RWST r w t z c
zoom LensLike' (Zoomed (RWST r w s z) c) t s
l (Lazy.RWST r -> s -> z (c, s, w)
m) = (r -> t -> z (c, t, w)) -> RWST r w t z c
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST ((r -> t -> z (c, t, w)) -> RWST r w t z c)
-> (r -> t -> z (c, t, w)) -> RWST r w t z c
forall a b. (a -> b) -> a -> b
$ \r
r -> FocusingWith w z c t -> z (c, t, w)
forall w (m :: * -> *) s a. FocusingWith w m s a -> m (s, a, w)
unfocusingWith (FocusingWith w z c t -> z (c, t, w))
-> (t -> FocusingWith w z c t) -> t -> z (c, t, w)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (RWST r w s z) c) t s
l (z (c, s, w) -> FocusingWith w z c s
forall w (m :: * -> *) s a. m (s, a, w) -> FocusingWith w m s a
FocusingWith (z (c, s, w) -> FocusingWith w z c s)
-> (s -> z (c, s, w)) -> s -> FocusingWith w z c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. r -> s -> z (c, s, w)
m r
r)
{-# INLINE zoom #-}
instance (Monoid w, Zoom m n s t) => Zoom (Strict.WriterT w m) (Strict.WriterT w n) s t where
zoom :: forall c.
LensLike' (Zoomed (WriterT w m) c) t s
-> WriterT w m c -> WriterT w n c
zoom LensLike' (Zoomed (WriterT w m) c) t s
l = n (c, w) -> WriterT w n c
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT (n (c, w) -> WriterT w n c)
-> (WriterT w m c -> n (c, w)) -> WriterT w m c -> WriterT w n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike' (Zoomed m (c, w)) t s -> m (c, w) -> n (c, w)
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom (\s -> Zoomed m (c, w) s
afb -> FocusingPlus w (Zoomed m) c t -> Zoomed m (c, w) t
forall w (k :: * -> * -> *) s a. FocusingPlus w k s a -> k (s, w) a
unfocusingPlus (FocusingPlus w (Zoomed m) c t -> Zoomed m (c, w) t)
-> (t -> FocusingPlus w (Zoomed m) c t) -> t -> Zoomed m (c, w) t
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (WriterT w m) c) t s
l (Zoomed m (c, w) s -> FocusingPlus w (Zoomed m) c s
forall w (k :: * -> * -> *) s a. k (s, w) a -> FocusingPlus w k s a
FocusingPlus (Zoomed m (c, w) s -> FocusingPlus w (Zoomed m) c s)
-> (s -> Zoomed m (c, w) s) -> s -> FocusingPlus w (Zoomed m) c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> Zoomed m (c, w) s
afb)) (m (c, w) -> n (c, w))
-> (WriterT w m c -> m (c, w)) -> WriterT w m c -> n (c, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m c -> m (c, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
Strict.runWriterT
{-# INLINE zoom #-}
instance (Monoid w, Zoom m n s t) => Zoom (Lazy.WriterT w m) (Lazy.WriterT w n) s t where
zoom :: forall c.
LensLike' (Zoomed (WriterT w m) c) t s
-> WriterT w m c -> WriterT w n c
zoom LensLike' (Zoomed (WriterT w m) c) t s
l = n (c, w) -> WriterT w n c
forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Lazy.WriterT (n (c, w) -> WriterT w n c)
-> (WriterT w m c -> n (c, w)) -> WriterT w m c -> WriterT w n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike' (Zoomed m (c, w)) t s -> m (c, w) -> n (c, w)
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom (\s -> Zoomed m (c, w) s
afb -> FocusingPlus w (Zoomed m) c t -> Zoomed m (c, w) t
forall w (k :: * -> * -> *) s a. FocusingPlus w k s a -> k (s, w) a
unfocusingPlus (FocusingPlus w (Zoomed m) c t -> Zoomed m (c, w) t)
-> (t -> FocusingPlus w (Zoomed m) c t) -> t -> Zoomed m (c, w) t
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (WriterT w m) c) t s
l (Zoomed m (c, w) s -> FocusingPlus w (Zoomed m) c s
forall w (k :: * -> * -> *) s a. k (s, w) a -> FocusingPlus w k s a
FocusingPlus (Zoomed m (c, w) s -> FocusingPlus w (Zoomed m) c s)
-> (s -> Zoomed m (c, w) s) -> s -> FocusingPlus w (Zoomed m) c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> Zoomed m (c, w) s
afb)) (m (c, w) -> n (c, w))
-> (WriterT w m c -> m (c, w)) -> WriterT w m c -> n (c, w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterT w m c -> m (c, w)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
Lazy.runWriterT
{-# INLINE zoom #-}
instance Zoom m n s t => Zoom (MaybeT m) (MaybeT n) s t where
zoom :: forall c.
LensLike' (Zoomed (MaybeT m) c) t s -> MaybeT m c -> MaybeT n c
zoom LensLike' (Zoomed (MaybeT m) c) t s
l = n (Maybe c) -> MaybeT n c
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (n (Maybe c) -> MaybeT n c)
-> (MaybeT m c -> n (Maybe c)) -> MaybeT m c -> MaybeT n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (May c -> Maybe c) -> n (May c) -> n (Maybe c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM May c -> Maybe c
forall a. May a -> Maybe a
getMay (n (May c) -> n (Maybe c))
-> (MaybeT m c -> n (May c)) -> MaybeT m c -> n (Maybe c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike' (Zoomed m (May c)) t s -> m (May c) -> n (May c)
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom (\s -> Zoomed m (May c) s
afb -> FocusingMay (Zoomed m) c t -> Zoomed m (May c) t
forall (k :: * -> * -> *) s a. FocusingMay k s a -> k (May s) a
unfocusingMay (FocusingMay (Zoomed m) c t -> Zoomed m (May c) t)
-> (t -> FocusingMay (Zoomed m) c t) -> t -> Zoomed m (May c) t
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (MaybeT m) c) t s
l (Zoomed m (May c) s -> FocusingMay (Zoomed m) c s
forall (k :: * -> * -> *) s a. k (May s) a -> FocusingMay k s a
FocusingMay (Zoomed m (May c) s -> FocusingMay (Zoomed m) c s)
-> (s -> Zoomed m (May c) s) -> s -> FocusingMay (Zoomed m) c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> Zoomed m (May c) s
afb)) (m (May c) -> n (May c))
-> (MaybeT m c -> m (May c)) -> MaybeT m c -> n (May c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe c -> May c) -> m (Maybe c) -> m (May c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Maybe c -> May c
forall a. Maybe a -> May a
May (m (Maybe c) -> m (May c))
-> (MaybeT m c -> m (Maybe c)) -> MaybeT m c -> m (May c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeT m c -> m (Maybe c)
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT
{-# INLINE zoom #-}
instance Zoom m n s t => Zoom (ExceptT e m) (ExceptT e n) s t where
zoom :: forall c.
LensLike' (Zoomed (ExceptT e m) c) t s
-> ExceptT e m c -> ExceptT e n c
zoom LensLike' (Zoomed (ExceptT e m) c) t s
l = n (Either e c) -> ExceptT e n c
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (n (Either e c) -> ExceptT e n c)
-> (ExceptT e m c -> n (Either e c))
-> ExceptT e m c
-> ExceptT e n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Err e c -> Either e c) -> n (Err e c) -> n (Either e c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Err e c -> Either e c
forall e a. Err e a -> Either e a
getErr (n (Err e c) -> n (Either e c))
-> (ExceptT e m c -> n (Err e c))
-> ExceptT e m c
-> n (Either e c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike' (Zoomed m (Err e c)) t s -> m (Err e c) -> n (Err e c)
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom (\s -> Zoomed m (Err e c) s
afb -> FocusingErr e (Zoomed m) c t -> Zoomed m (Err e c) t
forall e (k :: * -> * -> *) s a.
FocusingErr e k s a -> k (Err e s) a
unfocusingErr (FocusingErr e (Zoomed m) c t -> Zoomed m (Err e c) t)
-> (t -> FocusingErr e (Zoomed m) c t) -> t -> Zoomed m (Err e c) t
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (ExceptT e m) c) t s
l (Zoomed m (Err e c) s -> FocusingErr e (Zoomed m) c s
forall e (k :: * -> * -> *) s a.
k (Err e s) a -> FocusingErr e k s a
FocusingErr (Zoomed m (Err e c) s -> FocusingErr e (Zoomed m) c s)
-> (s -> Zoomed m (Err e c) s) -> s -> FocusingErr e (Zoomed m) c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> Zoomed m (Err e c) s
afb)) (m (Err e c) -> n (Err e c))
-> (ExceptT e m c -> m (Err e c)) -> ExceptT e m c -> n (Err e c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either e c -> Err e c) -> m (Either e c) -> m (Err e c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Either e c -> Err e c
forall e a. Either e a -> Err e a
Err (m (Either e c) -> m (Err e c))
-> (ExceptT e m c -> m (Either e c))
-> ExceptT e m c
-> m (Err e c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT e m c -> m (Either e c)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
{-# INLINE zoom #-}
instance (Functor f, Zoom m n s t) => Zoom (FreeT f m) (FreeT f n) s t where
zoom :: forall c.
LensLike' (Zoomed (FreeT f m) c) t s -> FreeT f m c -> FreeT f n c
zoom LensLike' (Zoomed (FreeT f m) c) t s
l = n (FreeF f c (FreeT f n c)) -> FreeT f n c
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
FreeT (n (FreeF f c (FreeT f n c)) -> FreeT f n c)
-> (FreeT f m c -> n (FreeF f c (FreeT f n c)))
-> FreeT f m c
-> FreeT f n c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Freed f m c -> FreeF f c (FreeT f n c))
-> n (Freed f m c) -> n (FreeF f c (FreeT f n c))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((FreeT f m c -> FreeT f n c)
-> FreeF f c (FreeT f m c) -> FreeF f c (FreeT f n c)
forall a b. (a -> b) -> FreeF f c a -> FreeF f c b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (LensLike' (Zoomed (FreeT f m) c) t s -> FreeT f m c -> FreeT f n c
forall c.
LensLike' (Zoomed (FreeT f m) c) t s -> FreeT f m c -> FreeT f n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike' (Zoomed (FreeT f m) c) t s
l) (FreeF f c (FreeT f m c) -> FreeF f c (FreeT f n c))
-> (Freed f m c -> FreeF f c (FreeT f m c))
-> Freed f m c
-> FreeF f c (FreeT f n c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Freed f m c -> FreeF f c (FreeT f m c)
forall (f :: * -> *) (m :: * -> *) a.
Freed f m a -> FreeF f a (FreeT f m a)
getFreed) (n (Freed f m c) -> n (FreeF f c (FreeT f n c)))
-> (FreeT f m c -> n (Freed f m c))
-> FreeT f m c
-> n (FreeF f c (FreeT f n c))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike' (Zoomed m (Freed f m c)) t s
-> m (Freed f m c) -> n (Freed f m c)
forall c. LensLike' (Zoomed m c) t s -> m c -> n c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom (\s -> Zoomed m (Freed f m c) s
afb -> FocusingFree f m (Zoomed m) c t -> Zoomed m (Freed f m c) t
forall (f :: * -> *) (m :: * -> *) (k :: * -> * -> *) s a.
FocusingFree f m k s a -> k (Freed f m s) a
unfocusingFree (FocusingFree f m (Zoomed m) c t -> Zoomed m (Freed f m c) t)
-> (t -> FocusingFree f m (Zoomed m) c t)
-> t
-> Zoomed m (Freed f m c) t
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike' (Zoomed (FreeT f m) c) t s
l (Zoomed m (Freed f m c) s -> FocusingFree f m (Zoomed m) c s
forall (f :: * -> *) (m :: * -> *) (k :: * -> * -> *) s a.
k (Freed f m s) a -> FocusingFree f m k s a
FocusingFree (Zoomed m (Freed f m c) s -> FocusingFree f m (Zoomed m) c s)
-> (s -> Zoomed m (Freed f m c) s)
-> s
-> FocusingFree f m (Zoomed m) c s
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. s -> Zoomed m (Freed f m c) s
afb)) (m (Freed f m c) -> n (Freed f m c))
-> (FreeT f m c -> m (Freed f m c))
-> FreeT f m c
-> n (Freed f m c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FreeF f c (FreeT f m c) -> Freed f m c)
-> m (FreeF f c (FreeT f m c)) -> m (Freed f m c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM FreeF f c (FreeT f m c) -> Freed f m c
forall (f :: * -> *) (m :: * -> *) a.
FreeF f a (FreeT f m a) -> Freed f m a
Freed (m (FreeF f c (FreeT f m c)) -> m (Freed f m c))
-> (FreeT f m c -> m (FreeF f c (FreeT f m c)))
-> FreeT f m c
-> m (Freed f m c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FreeT f m c -> m (FreeF f c (FreeT f m c))
forall (f :: * -> *) (m :: * -> *) a.
FreeT f m a -> m (FreeF f a (FreeT f m a))
runFreeT
#if !MIN_VERSION_transformers(0,6,0) && !MIN_VERSION_mtl(2,3,0)
instance (Error e, Zoom m n s t) => Zoom (ErrorT e m) (ErrorT e n) s t where
zoom l = ErrorT . liftM getErr . zoom (\afb -> unfocusingErr #. l (FocusingErr #. afb)) . liftM Err . runErrorT
{-# INLINE zoom #-}
instance Zoom m n s t => Zoom (ListT m) (ListT n) s t where
zoom l = ListT . zoom (\afb -> unfocusingOn . l (FocusingOn . afb)) . runListT
{-# INLINE zoom #-}
#endif
class (Magnified m ~ Magnified n, MonadReader b m, MonadReader a n) => Magnify m n b a | m -> b, n -> a, m a -> n, n b -> m where
magnify :: ((Functor (Magnified m c), Contravariant (Magnified m c))
=> LensLike' (Magnified m c) a b)
-> m c -> n c
instance Monad m => Magnify (ReaderT b m) (ReaderT a m) b a where
magnify :: forall c.
((Functor (Magnified (ReaderT b m) c),
Contravariant (Magnified (ReaderT b m) c)) =>
LensLike' (Magnified (ReaderT b m) c) a b)
-> ReaderT b m c -> ReaderT a m c
magnify (Functor (Magnified (ReaderT b m) c),
Contravariant (Magnified (ReaderT b m) c)) =>
LensLike' (Magnified (ReaderT b m) c) a b
l (ReaderT b -> m c
m) = (a -> m c) -> ReaderT a m c
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((a -> m c) -> ReaderT a m c) -> (a -> m c) -> ReaderT a m c
forall a b. (a -> b) -> a -> b
$ Effect m c a -> m c
forall (m :: * -> *) r a. Effect m r a -> m r
getEffect (Effect m c a -> m c) -> (a -> Effect m c a) -> a -> m c
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (Functor (Magnified (ReaderT b m) c),
Contravariant (Magnified (ReaderT b m) c)) =>
LensLike' (Magnified (ReaderT b m) c) a b
LensLike' (Magnified (ReaderT b m) c) a b
l (m c -> Effect m c b
forall (m :: * -> *) r a. m r -> Effect m r a
Effect (m c -> Effect m c b) -> (b -> m c) -> b -> Effect m c b
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. b -> m c
m)
{-# INLINE magnify #-}
instance Magnify ((->) b) ((->) a) b a where
magnify :: forall c.
((Functor (Magnified ((->) b) c),
Contravariant (Magnified ((->) b) c)) =>
LensLike' (Magnified ((->) b) c) a b)
-> (b -> c) -> a -> c
magnify (Functor (Magnified ((->) b) c),
Contravariant (Magnified ((->) b) c)) =>
LensLike' (Magnified ((->) b) c) a b
l = LensLike' (Const c) a b -> (b -> c) -> a -> c
forall s (m :: * -> *) r a.
MonadReader s m =>
LensLike' (Const r) s a -> (a -> r) -> m r
views (Functor (Magnified ((->) b) c),
Contravariant (Magnified ((->) b) c)) =>
LensLike' (Magnified ((->) b) c) a b
LensLike' (Const c) a b
LensLike' (Magnified ((->) b) c) a b
l
{-# INLINE magnify #-}
instance (Monad m, Monoid w) => Magnify (Strict.RWST b w s m) (Strict.RWST a w s m) b a where
magnify :: forall c.
((Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b)
-> RWST b w s m c -> RWST a w s m c
magnify (Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b
l (Strict.RWST b -> s -> m (c, s, w)
m) = (a -> s -> m (c, s, w)) -> RWST a w s m c
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST ((a -> s -> m (c, s, w)) -> RWST a w s m c)
-> (a -> s -> m (c, s, w)) -> RWST a w s m c
forall a b. (a -> b) -> a -> b
$ EffectRWS w s m c a -> s -> m (c, s, w)
forall w st (m :: * -> *) s a.
EffectRWS w st m s a -> st -> m (s, st, w)
getEffectRWS (EffectRWS w s m c a -> s -> m (c, s, w))
-> (a -> EffectRWS w s m c a) -> a -> s -> m (c, s, w)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b
LensLike' (Magnified (RWST b w s m) c) a b
l ((s -> m (c, s, w)) -> EffectRWS w s m c b
forall w st (m :: * -> *) s a.
(st -> m (s, st, w)) -> EffectRWS w st m s a
EffectRWS ((s -> m (c, s, w)) -> EffectRWS w s m c b)
-> (b -> s -> m (c, s, w)) -> b -> EffectRWS w s m c b
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. b -> s -> m (c, s, w)
m)
{-# INLINE magnify #-}
instance (Monad m, Monoid w) => Magnify (Lazy.RWST b w s m) (Lazy.RWST a w s m) b a where
magnify :: forall c.
((Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b)
-> RWST b w s m c -> RWST a w s m c
magnify (Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b
l (Lazy.RWST b -> s -> m (c, s, w)
m) = (a -> s -> m (c, s, w)) -> RWST a w s m c
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Lazy.RWST ((a -> s -> m (c, s, w)) -> RWST a w s m c)
-> (a -> s -> m (c, s, w)) -> RWST a w s m c
forall a b. (a -> b) -> a -> b
$ EffectRWS w s m c a -> s -> m (c, s, w)
forall w st (m :: * -> *) s a.
EffectRWS w st m s a -> st -> m (s, st, w)
getEffectRWS (EffectRWS w s m c a -> s -> m (c, s, w))
-> (a -> EffectRWS w s m c a) -> a -> s -> m (c, s, w)
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (Functor (Magnified (RWST b w s m) c),
Contravariant (Magnified (RWST b w s m) c)) =>
LensLike' (Magnified (RWST b w s m) c) a b
LensLike' (Magnified (RWST b w s m) c) a b
l ((s -> m (c, s, w)) -> EffectRWS w s m c b
forall w st (m :: * -> *) s a.
(st -> m (s, st, w)) -> EffectRWS w st m s a
EffectRWS ((s -> m (c, s, w)) -> EffectRWS w s m c b)
-> (b -> s -> m (c, s, w)) -> b -> EffectRWS w s m c b
forall a b c (q :: * -> * -> *).
Coercible c b =>
q b c -> (a -> b) -> a -> c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. b -> s -> m (c, s, w)
m)
{-# INLINE magnify #-}
instance Magnify m n b a => Magnify (IdentityT m) (IdentityT n) b a where
magnify :: forall c.
((Functor (Magnified (IdentityT m) c),
Contravariant (Magnified (IdentityT m) c)) =>
LensLike' (Magnified (IdentityT m) c) a b)
-> IdentityT m c -> IdentityT n c
magnify (Functor (Magnified (IdentityT m) c),
Contravariant (Magnified (IdentityT m) c)) =>
LensLike' (Magnified (IdentityT m) c) a b
l (IdentityT m c
m) = n c -> IdentityT n c
forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT (((Functor (Magnified m c), Contravariant (Magnified m c)) =>
LensLike' (Magnified m c) a b)
-> m c -> n c
forall c.
((Functor (Magnified m c), Contravariant (Magnified m c)) =>
LensLike' (Magnified m c) a b)
-> m c -> n c
forall (m :: * -> *) (n :: * -> *) b a c.
Magnify m n b a =>
((Functor (Magnified m c), Contravariant (Magnified m c)) =>
LensLike' (Magnified m c) a b)
-> m c -> n c
magnify (Functor (Magnified m c), Contravariant (Magnified m c)) =>
LensLike' (Magnified m c) a b
(Functor (Magnified (IdentityT m) c),
Contravariant (Magnified (IdentityT m) c)) =>
LensLike' (Magnified (IdentityT m) c) a b
LensLike' (Magnified m c) a b
LensLike' (Magnified (IdentityT m) c) a b
l m c
m)
{-# INLINE magnify #-}