Îõ³h$<ô;5À      !"#$%&'()*+,-./0123456789:;<=>?Bas van Dijk, Anders KaseorgBSD3#Bas van Dijk Safe >ÀÁÂÄÉÔ×Ù:ó monad-controlA function like  that runs a monad transformer t in its base monad b. It is used in . monad-control7Handy type synonym that composes the monadic states of t and m.It can be used to define the  for new  instances. monad-controlA function that runs a m8 computation on the monadic state that was captured by A  RunInBase m4 function yields a computation in the base monad of m$ that returns the monadic state of m/. This state can later be used to restore the m computation using .Example type equalities:  RunInBase (@ m) b ~ forall a. @ m a -> b ( m a) RunInBase (A" m) b ~ forall a. A m a -> b ( m (B a)) RunInBase (C e m) b ~ forall a. D e => C e m a -> b ( m (E e a)) RunInBase (F! e m) b ~ forall a. F e m a -> b ( m (E e a)) RunInBase (G# m) b ~ forall a. G m a -> b ( m [a]) RunInBase (H! r m) b ~ forall a. H m a -> b ( m a) RunInBase (I" s m) b ~ forall a. I s m a -> b ( m (a, s)) RunInBase (J w m) b ~ forall a. K w => J w m a -> b ( m (a, w)) RunInBase (L r w s m) b ~ forall a. K w => L r w s m a -> b ( m (a, s, w)) For a transformed base monad m ~ t b, 'RunInBase m b' ~   t. monad-controlWriting instancesThe usual way to write a 5 instance for a transformer stack over a base monad B is to write an instance MonadBaseControl B B for the base monad, and MonadTransControl T" instances for every transformer T. Instances for $ are then simply implemented using , , . monad-controlMonadic state that m adds to the base monad b.'For all base (non-transformed) monads,  StM m a ~ a: StM M a ~ a StM B a ~ a StM (E8 e) a ~ a StM [] a ~ a StM ((->) r) a ~ a StM N a ~ a StM O a ~ a StM (P s) a ~ a If m is a transformed monad, m ~ t b, * is the monadic state of the transformer t (given by its   from  ). For a transformer stack,  is defined recursively: StM (@ m) a ~  @ m a ~ StM m a StM (A m) a ~  A m a ~ StM m (B a) StM (C e m) a ~  C m a ~ D e => StM m (E e a) StM (F e m) a ~  F m a ~ StM m (E e a) StM (G m) a ~  G m a ~ StM m [a] StM (H r m) a ~  H m a ~ StM m a StM (I s m) a ~  I m a ~ StM m (a, s) StM (J w m) a ~  J m a ~ K w => StM m (a, w) StM (L r w s m) a ~  L m a ~ K w => StM m (a, s, w)  monad-control liftBaseWith is similar to liftIO and liftBase? in that it lifts a base computation to the constructed monad.-Instances should satisfy similar laws as the MonadIO and Q laws: (liftBaseWith (\_ -> return a) = return a ÜliftBaseWith (\_ -> m >>= f) = liftBaseWith (\_ -> m) >>= (\a -> liftBaseWith (\_ -> f a))As  ,https://stackoverflow.com/a/58106822/1477667Li-yao Xia explains , parametricity guarantees that f  $0 liftBaseWith q = liftBaseWith $ runInBase -> f  $ q runInBaseThe difference with liftBase. is that before lifting the base computation  liftBaseWith captures the state of m0. It then provides the base computation with a  function that allows running m7 computations in the base monad on the captured state: ÷withFileLifted :: MonadBaseControl IO m => FilePath -> IOMode -> (Handle -> m a) -> m a withFileLifted file mode action = liftBaseWith (\runInBase -> withFile file mode (runInBase . action)) >>= restoreM -- = control $ \runInBase -> withFile file mode (runInBase . action) -- = liftBaseOp (withFile file mode) action 1 is usually not implemented directly, but using . monad-control Construct a m' computation from the monadic state of m that is returned from a  function.Instances should satisfy: 9liftBaseWith (\runInBase -> runInBase m) >>= restoreM = m1 is usually not implemented directly, but using . monad-controlA function like   that runs a monad transformer t% which wraps the monad transformers n and n'. This is used in . monad-controlA function like   that runs a monad transformer t$ which wraps the monad transformer t'. This is used in .  monad-control)A function that runs a transformed monad t n, on the monadic state that was captured by  A Run t" function yields a computation in n$ that returns the monadic state of t,. This state can later be used to restore a t computation using  .Example type equalities: Run @ ~ forall n b. R n => @ n b -> n b Run A ~ forall n b. R n => A n b -> n (B b) Run (C e) ~ forall n b. (R n, D e) => C e n b -> n (E e b) Run (F e) ~ forall n b. R n => F e n b -> n (E e b) Run G ~ forall n b. R n => G n b -> n [b] Run (H r) ~ forall n b. R n => H r n b -> n b Run (I s) ~ forall n b. R n => I s n b -> n (a, s) Run (J w) ~ forall n b. (R n, K w) => J w n b -> n (a, w) Run (L r w s) ~ forall n b. (R n, K w) => L r w s n b -> n (a, s, w) &This type is usually satisfied by the run function of a transformer: flip S :: r -> Run (H r) flip T :: s -> Run (I s) U :: Run A  monad-controlThe MonadTransControl% type class is a stronger version of V: Instances of V know how to lift› actions in the base monad to the transformed monad. These lifted actions, however, are completely unaware of the monadic state added by the transformer. ç instances are aware of the monadic state of the transformer and allow to save and restore this state.„This allows to lift functions that have a monad transformer in both positive and negative position. Take, for example, the function ;withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r V0 instances can only lift the return type of the withFile function: –withFileLifted :: MonadTrans t => FilePath -> IOMode -> (Handle -> IO r) -> t IO r withFileLifted file mode action = lift (withFile file mode action)  However, V is not powerful enough to make withFileLifted! accept a function that returns t IOâ. The reason is that we need to take away the transformer layer in order to pass the function to withFile.   allows us to do this: ÛwithFileLifted' :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r withFileLifted' file mode action = liftWith (\run -> withFile file mode (run . action)) >>= restoreT . return  monad-controlMonadic state of t.ÃThe monadic state of a monad transformer is the result type of its run function, e.g.: S :: H r m a -> r -> m a   (H r) a ~ a T :: I s m a -> s -> m (a, s)   (I s) a ~ (a, s) U :: A m a -> m (B a)   A a ~ B a Provided type instances: StT @ a ~ a StT A a ~ B a StT (C e) a ~ D e => E e a StT (F e) a ~ E e a StT G a ~ [a] StT (H r) a ~ a StT (I s) a ~ (a, s) StT (J w) a ~ K w => (a, w) StT (L r w s) a ~ K w => (a, s, w)  monad-controlliftWith is similar to liftÒ in that it lifts a computation from the argument monad to the constructed monad.-Instances should satisfy similar laws as the V laws: $liftWith (\_ -> return a) = return a ÐliftWith (\_ -> m >>= f) = liftWith (\_ -> m) >>= (\a -> liftWith (\_ -> f a))The difference with lift is that before lifting the m computation liftWith captures the state of t. It then provides the m computation with a   function that allows running t n computations in n (for all n) on the captured state, e.g. ÙwithFileLifted :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r withFileLifted file mode action = liftWith (\run -> withFile file mode (run . action)) >>= restoreT . return If the Run function is ignored, liftWith coincides with lift: lift f = liftWith (\_ -> f)Implementations use the  ( function associated with a transformer:  liftWith :: R m => ((R n => H r n b -> n b) -> m a) -> H r m a liftWith f = H (\r -> f (\action -> S action r)) liftWith :: R m => ((R n => I s n b -> n (b, s)) -> m a) -> I s m a liftWith f = I (\s -> W (\x -> (x, s)) (f (\action -> T action s))) liftWith :: R m => ((R n => A n b -> n (B b)) -> m a) -> A m a liftWith f = A (W Just (f U))  monad-control Construct a t' computation from the monadic state of t that is returned from a   function.Instances should satisfy: 2liftWith (\run -> run t) >>= restoreT . return = trestoreTÊ is usually implemented through the constructor of the monad transformer: H :: (r -> m a) -> H! r m a restoreT :: m a -> H r m a restoreT action = H { runReaderT = X action } I :: (s -> m (a, s)) -> I& s m a restoreT :: m (a, s) -> I s m a restoreT action = I { runStateT = X action } A :: m (B a) -> A m a restoreT :: m (B a) -> A m a restoreT action = A action Example type signatures:  restoreT :: R$ m => m a -> @ m a restoreT :: R m => m (B a) -> A m a restoreT :: (R m, D e) => m (E e a) -> C e m a restoreT :: R m => m (E e a) -> F e m a restoreT :: R$ m => m [a] -> G m a restoreT :: R$ m => m a -> H r m a restoreT :: R$ m => m (a, s) -> I s m a restoreT :: (R m, K w) => m (a, w) -> J w m a restoreT :: (R m, K w) => m (a, s, w) -> L r w s m a  monad-controlDefault definition for the   method. monad-controlDefault definition for the   method. monad-controlDefault definition for the   method. monad-controlDefault definition for the   method for double  . monad-controlDefault definition for the  method.Note that it composes a   of t with a  of m to give a  of t m: defaultLiftBaseWith = \f ->  ) $ \run -> Å $ \runInBase -> f $ runInBase . run  monad-controlDefault definition for the  method. Note that: defaultRestoreM =   .  monad-controlAn often used composition:  control f =  f >>= Example: ­liftedBracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c liftedBracket acquire release action = control $ \runInBase -> bracket (runInBase acquire) (\saved -> runInBase (restoreM saved >>= release)) (\saved -> runInBase (restoreM saved >>= action))  monad-control?Lift a computation and restore the monadic state immediately:  controlT f =   f >>=   . return. monad-controlåEmbed a transformer function as an function in the base monad returning a mutated transformer state. monad-controlPerforms the same function as =, but discards transformer state from the embedded function. monad-control*Capture the current state of a transformer monad-control.Capture the current state above the base monad monad-control liftBaseOp is a particular application of 1 that allows lifting control operations of type: ((a -> b c) -> b c)to: ( b m => (a -> m c) -> m c) For example: "liftBaseOp alloca :: (Storable a,  M m) => (Ptr a -> m c) -> m c monad-control liftBaseOp_ is a particular application of 1 that allows lifting control operations of type:  (b a -> b a)to: ( b m => m a -> m a) For example: liftBaseOp_ mask_ ::  M m => m a -> m a monad-controlliftBaseDiscard is a particular application of 1 that allows lifting control operations of type:  (b () -> b a)to: ( b m => m () -> m a)*Note that, while the argument computation m ()< has access to the captured state, all its side-effects in mÇ are discarded. It is run only for its side-effects in the base monad b. For example: liftBaseDiscard forkIO ::  M m => m () -> m ThreadId monad-controlliftBaseOpDiscard is a particular application of 1 that allows lifting control operations of type: ((a -> b ()) -> b c)to: ( b m => (a -> m ()) -> m c)*Note that, while the argument computation m ()< has access to the captured state, all its side-effects in mÇ are discarded. It is run only for its side-effects in the base monad b. For example: )liftBaseDiscard (runServer addr port) ::  M m => m () -> m () monad-controlTransform an action in t m; using a transformer that operates on the underlying monad m monad-controlMonad constructor monad-controlMonad deconstructor monad-controlMonad constructor monad-controlMonad constructor monad-controlMonad deconstructor monad-controlMonad constructor monad-control  Ù      !"#$%&'()*+,-./0123456789:;<=>?@ABCDBEFGHIBJKBJLGMNBOPBQRBSTBUVBWXGYZB[\]^_G`aGbcGdefghGYiBSjBUkBElBmnGYoGYpñ*monad-control-1.0.3-6wpM75EwXct7SHHIosTOLbControl.Monad.Trans.ControlRunInBaseDefault ComposeSt RunInBaseMonadBaseControlStM liftBaseWithrestoreM RunDefault2 RunDefaultRunMonadTransControlStTliftWithrestoreTdefaultLiftWithdefaultRestoreTdefaultLiftWith2defaultRestoreT2defaultLiftBaseWithdefaultRestoreMcontrolcontrolTembedembed_captureTcaptureM liftBaseOp liftBaseOp_liftBaseDiscardliftBaseOpDiscard liftThrough$fMonadTransControlRWST$fMonadTransControlRWST0$fMonadTransControlWriterT$fMonadTransControlWriterT0$fMonadTransControlStateT$fMonadTransControlStateT0$fMonadTransControlReaderT$fMonadTransControlListT$fMonadTransControlExceptT$fMonadTransControlErrorT$fMonadTransControlMaybeT$fMonadTransControlIdentityT$fMonadBaseControlSTST$fMonadBaseControlSTST0$fMonadBaseControlSTMSTM"$fMonadBaseControlIdentityIdentity$fMonadBaseControl->->$fMonadBaseControl[][]$fMonadBaseControlEitherEither$fMonadBaseControlMaybeMaybe$fMonadBaseControlIOIO$fMonadBaseControlbRWST$fMonadBaseControlbRWST0$fMonadBaseControlbWriterT$fMonadBaseControlbWriterT0$fMonadBaseControlbErrorT$fMonadBaseControlbExceptT$fMonadBaseControlbStateT$fMonadBaseControlbStateT0$fMonadBaseControlbReaderT$fMonadBaseControlbListT$fMonadBaseControlbMaybeT$fMonadBaseControlbIdentityTtransformers-0.5.6.2Control.Monad.Trans.Identity IdentityTControl.Monad.Trans.MaybeMaybeTbase GHC.MaybeMaybeControl.Monad.Trans.ErrorErrorTError Data.EitherEitherControl.Monad.Trans.ExceptExceptTControl.Monad.Trans.ListListTControl.Monad.Trans.ReaderReaderTControl.Monad.Trans.State.LazyStateTControl.Monad.Trans.Writer.LazyWriterTGHC.BaseMonoidControl.Monad.Trans.RWS.LazyRWSTghc-prim GHC.TypesIOData.Functor.IdentityIdentity GHC.Conc.SyncSTMControl.Monad.ST.Lazy.ImpST0transformers-base-0.4.5.2-JMMpTiK7VYJ18vq9iLMLmJControl.Monad.Base MonadBaseMonad runReaderT runStateT runMaybeTControl.Monad.Trans.Class MonadTransliftMconst