transformers-lift (empty) → 0.1.0.0
raw patch · 9 files changed
+550/−0 lines, 9 filesdep +basedep +transformerssetup-changed
Dependencies added: base, transformers
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- src/Control/Monad/Trans/Lift/CallCC.hs +110/−0
- src/Control/Monad/Trans/Lift/Catch.hs +82/−0
- src/Control/Monad/Trans/Lift/Listen.hs +86/−0
- src/Control/Monad/Trans/Lift/Local.hs +86/−0
- src/Control/Monad/Trans/Lift/Pass.hs +87/−0
- src/Control/Monad/Trans/Lift/StT.hs +32/−0
- transformers-lift.cabal +35/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Index Int++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Index Int nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Control/Monad/Trans/Lift/CallCC.hs view
@@ -0,0 +1,110 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+-- | Lifting the @callCC@ operation.+module Control.Monad.Trans.Lift.CallCC+ ( LiftCallCC(..)+ , CallCC+ , defaultLiftCallCC+ , defaultLiftCallCC'+ , module Control.Monad.Trans.Class+ ) where++#if __GLASGOW_HASKELL__ < 710+import Data.Monoid+#endif++import Control.Monad.Signatures+import Control.Monad.Trans.Class++import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.List as L+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++import Control.Monad.Trans.Lift.StT++-- | The class of monad transformers capable of lifting 'callCC'.+class MonadTrans t => LiftCallCC t where+ -- | Lift the @callCC@ operation.+ -- Should satisfy the uniformity property+ --+ -- * @'lift' (f k) = f' ('lift' . k) => 'lift' (cf f) = 'liftCallCC' cf f'@+ --+ liftCallCC :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b++ -- | Lift the @callCC@ operation.+ -- This is an alternative version of 'liftCallCC' included for historical+ -- reasons. It has a different lifting behavior for the @StateT@ and @RWST@+ -- monad transformers. Matches what @mtl@ does but doesn't satisfy the+ -- uniformity property.+ liftCallCC' :: Monad m => CallCC m (StT t a) (StT t b) -> CallCC (t m) a b+ liftCallCC' = liftCallCC++-- | Default definition for the 'liftCallCC' method.+defaultLiftCallCC+ :: (Monad m, LiftCallCC n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> CallCC m (StT n a) (StT n b)+ -> CallCC (t m) a b+defaultLiftCallCC t unT callCC f+ = t $ liftCallCC callCC (\g -> (unT . f) (t . g))++-- | Default definition for the 'liftCallCC'' method.+defaultLiftCallCC'+ :: (Monad m, LiftCallCC n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> CallCC m (StT n a) (StT n b)+ -> CallCC (t m) a b+defaultLiftCallCC' t unT callCC f+ = t $ liftCallCC' callCC (\g -> (unT . f) (t . g))++instance LiftCallCC (E.ExceptT e) where+ liftCallCC = E.liftCallCC++instance LiftCallCC I.IdentityT where+ liftCallCC = I.liftCallCC++instance LiftCallCC L.ListT where+ liftCallCC = L.liftCallCC++instance LiftCallCC M.MaybeT where+ liftCallCC = M.liftCallCC++instance LiftCallCC (R.ReaderT r) where+ liftCallCC = R.liftCallCC++instance Monoid w => LiftCallCC (W.Lazy.WriterT w) where+ liftCallCC = W.Lazy.liftCallCC++instance Monoid w => LiftCallCC (W.Strict.WriterT w) where+ liftCallCC = W.Strict.liftCallCC++instance Monoid w => LiftCallCC (RWS.Lazy.RWST r w s) where+ liftCallCC = RWS.Lazy.liftCallCC+ liftCallCC' = RWS.Lazy.liftCallCC'++instance Monoid w => LiftCallCC (RWS.Strict.RWST r w s) where+ liftCallCC = RWS.Strict.liftCallCC+ liftCallCC' = RWS.Strict.liftCallCC'++instance LiftCallCC (S.Lazy.StateT s) where+ liftCallCC = S.Lazy.liftCallCC+ liftCallCC' = S.Lazy.liftCallCC'++instance LiftCallCC (S.Strict.StateT s) where+ liftCallCC = S.Strict.liftCallCC+ liftCallCC' = S.Strict.liftCallCC'+
+ src/Control/Monad/Trans/Lift/Catch.hs view
@@ -0,0 +1,82 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+-- | Lifting the @catch@ operation.+module Control.Monad.Trans.Lift.Catch+ ( LiftCatch(..)+ , Catch+ , defaultLiftCatch+ , module Control.Monad.Trans.Class+ ) where++#if __GLASGOW_HASKELL__ < 710+import Data.Monoid+#endif++import Control.Monad.Signatures+import Control.Monad.Trans.Class++import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.List as L+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++import Control.Monad.Trans.Lift.StT++-- | The class of monad transformers capable of lifting 'catch'.+class MonadTrans t => LiftCatch t where+ -- | Lift the @catch@ operation.+ -- Should satisfy the uniformity property+ --+ -- * @'lift' (cf m f) = 'liftCatch' ('lift' . cf) ('lift' f)@+ --+ liftCatch :: Monad m => Catch e m (StT t a) -> Catch e (t m) a++-- | Default definition for the 'liftCatch' method.+defaultLiftCatch+ :: (Monad m, LiftCatch n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> Catch e m (StT n a) -> Catch e (t m) a+defaultLiftCatch t unT f m h = t $ liftCatch f (unT m) (unT . h)++instance LiftCatch (E.ExceptT e) where+ liftCatch f m h = E.ExceptT $ f (E.runExceptT m) (E.runExceptT . h)++instance LiftCatch I.IdentityT where+ liftCatch = I.liftCatch++instance LiftCatch L.ListT where+ liftCatch = L.liftCatch++instance LiftCatch M.MaybeT where+ liftCatch = M.liftCatch++instance LiftCatch (R.ReaderT r) where+ liftCatch = R.liftCatch++instance Monoid w => LiftCatch (RWS.Lazy.RWST r w s) where+ liftCatch = RWS.Lazy.liftCatch++instance Monoid w => LiftCatch (RWS.Strict.RWST r w s) where+ liftCatch = RWS.Strict.liftCatch++instance LiftCatch (S.Lazy.StateT s) where+ liftCatch = S.Lazy.liftCatch++instance LiftCatch (S.Strict.StateT s) where+ liftCatch = S.Strict.liftCatch++instance Monoid w => LiftCatch (W.Lazy.WriterT w) where+ liftCatch = W.Lazy.liftCatch++instance Monoid w => LiftCatch (W.Strict.WriterT w) where+ liftCatch = W.Strict.liftCatch
+ src/Control/Monad/Trans/Lift/Listen.hs view
@@ -0,0 +1,86 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+-- | Lifting the @listen@ operation.+module Control.Monad.Trans.Lift.Listen+ ( LiftListen(..)+ , Listen+ , defaultLiftListen+ , module Control.Monad.Trans.Class+ ) where++#if __GLASGOW_HASKELL__ < 710+import Data.Monoid+#endif++import Control.Monad.Signatures+import Control.Monad.Trans.Class++import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++import Control.Monad.Trans.Lift.StT++-- | The class of monad transformers capable of lifting 'listen'.+class MonadTrans t => LiftListen t where+ -- | Lift the @listen@ operation.+ -- Should satisfy the uniformity property+ --+ -- * @'lift' . 'liftListen' = 'liftListen' . 'lift'@+ --+ liftListen :: Monad m => Listen w m (StT t a) -> Listen w (t m) a++-- | Default definition for the `liftListen` method.+defaultLiftListen+ :: (Monad m, LiftListen n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> Listen w m (StT n a) -> Listen w (t m) a+defaultLiftListen t unT listen m = t $ liftListen listen (unT m)++instance LiftListen (E.ExceptT e) where+ liftListen = E.liftListen++instance LiftListen I.IdentityT where+ liftListen = I.mapIdentityT++instance LiftListen M.MaybeT where+ liftListen = M.liftListen++instance LiftListen (R.ReaderT r) where+ liftListen = R.mapReaderT++instance LiftListen (S.Lazy.StateT s) where+ liftListen = S.Lazy.liftListen++instance LiftListen (S.Strict.StateT s) where+ liftListen = S.Strict.liftListen++instance Monoid w' => LiftListen (RWS.Lazy.RWST r w' s) where+ liftListen listen m = RWS.Lazy.RWST $ \r s -> do+ ~((a, w', s'), w) <- listen (RWS.Lazy.runRWST m r s)+ return ((a, w), w', s')++instance Monoid w' => LiftListen (RWS.Strict.RWST r w' s) where+ liftListen listen m = RWS.Strict.RWST $ \r s -> do+ ((a, w', s'), w) <- listen (RWS.Strict.runRWST m r s)+ return ((a, w), w', s')++instance Monoid w' => LiftListen (W.Lazy.WriterT w') where+ liftListen listen m = W.Lazy.WriterT $ do+ ~((a, w'), w) <- listen (W.Lazy.runWriterT m)+ return ((a, w), w')++instance Monoid w' => LiftListen (W.Strict.WriterT w') where+ liftListen listen m = W.Strict.WriterT $ do+ ((a, w'), w) <- listen (W.Strict.runWriterT m)+ return ((a, w), w')
+ src/Control/Monad/Trans/Lift/Local.hs view
@@ -0,0 +1,86 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+-- | Lifting the 'local' operation.+module Control.Monad.Trans.Lift.Local+ ( LiftLocal(..)+ , Local+ , defaultLiftLocal+ , module Control.Monad.Trans.Class+ ) where++#if __GLASGOW_HASKELL__ < 710+import Data.Monoid+#endif++import Control.Monad.Trans.Class++import qualified Control.Monad.Trans.Cont as C+import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.List as L+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++-- | Signature of the @local@ operation,+-- introduced in "Control.Monad.Trans.Reader".+type Local r m a = (r -> r) -> m a -> m a++-- | The class of monad transformers capable of lifting 'local'.+class MonadTrans t => LiftLocal t where+ -- | Lift the 'local' operation.+ liftLocal :: Monad m => m r -> (forall a . Local r m a)+ -> (forall a . Local r (t m) a)++-- | Default definition for the 'liftLocal' method.+defaultLiftLocal+ :: (Monad m, LiftLocal n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> m r+ -> (forall a . Local r m a)+ -> (forall a . Local r (t m) a)+defaultLiftLocal t unT a l f = t . liftLocal a l f . unT++instance LiftLocal (C.ContT r) where+ liftLocal a l f = C.liftLocal a l f++instance LiftLocal (E.ExceptT e) where+ liftLocal _ l f = E.mapExceptT (l f)++instance LiftLocal I.IdentityT where+ liftLocal _ l f = I.mapIdentityT (l f)++instance LiftLocal L.ListT where+ liftLocal _ l f = L.mapListT (l f)++instance LiftLocal M.MaybeT where+ liftLocal _ l f = M.mapMaybeT (l f)++instance LiftLocal (R.ReaderT r) where+ liftLocal _ l f = R.mapReaderT (l f)++instance Monoid w => LiftLocal (RWS.Lazy.RWST r w s) where+ liftLocal _ l f = RWS.Lazy.mapRWST (l f)++instance Monoid w => LiftLocal (RWS.Strict.RWST r w s) where+ liftLocal _ l f = RWS.Strict.mapRWST (l f)++instance LiftLocal (S.Lazy.StateT s) where+ liftLocal _ l f = S.Lazy.mapStateT (l f)++instance LiftLocal (S.Strict.StateT s) where+ liftLocal _ l f = S.Strict.mapStateT (l f)++instance Monoid w => LiftLocal (W.Lazy.WriterT w) where+ liftLocal _ l f = W.Lazy.mapWriterT (l f)++instance Monoid w => LiftLocal (W.Strict.WriterT w) where+ liftLocal _ l f = W.Strict.mapWriterT (l f)
+ src/Control/Monad/Trans/Lift/Pass.hs view
@@ -0,0 +1,87 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+-- | Lifting the 'pass' operation.+module Control.Monad.Trans.Lift.Pass+ ( LiftPass(..)+ , Pass+ , defaultLiftPass+ , module Control.Monad.Trans.Class+ ) where++#if __GLASGOW_HASKELL__ < 710+import Data.Monoid+#endif++import Control.Monad.Signatures+import Control.Monad.Trans.Class++import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++import Control.Monad.Trans.Lift.StT++-- | The class of monad transformers capable of lifting 'pass'.+class MonadTrans t => LiftPass t where+ -- | Lift the 'pass' operation.+ -- Should satisfy the uniformity property+ --+ -- * @'lift' . 'liftPass' = 'liftPass' . 'lift'@+ --+ liftPass :: Monad m => Pass w m (StT t a) -> Pass w (t m) a++-- | Default definition for the 'liftPass' method.+defaultLiftPass+ :: (Monad m, LiftPass n)+ => (forall x . n m x -> t m x)+ -- ^ Monad constructor+ -> (forall o x . t o x -> n o x)+ -- ^ Monad deconstructor+ -> Pass w m (StT n a)+ -> Pass w (t m) a+defaultLiftPass t unT pass m = t $ liftPass pass (unT m)++instance LiftPass (E.ExceptT e) where+ liftPass = E.liftPass++instance LiftPass I.IdentityT where+ liftPass = I.mapIdentityT++instance LiftPass M.MaybeT where+ liftPass = M.liftPass++instance LiftPass (R.ReaderT r) where+ liftPass = R.mapReaderT++instance LiftPass (S.Lazy.StateT s) where+ liftPass = S.Lazy.liftPass++instance LiftPass (S.Strict.StateT s) where+ liftPass = S.Strict.liftPass++instance Monoid w' => LiftPass (RWS.Lazy.RWST r w' s) where+ liftPass pass m = RWS.Lazy.RWST $ \r s -> pass $ do+ ~((a, f), w', s') <- RWS.Lazy.runRWST m r s+ return ((a, w', s'), f)++instance Monoid w' => LiftPass (RWS.Strict.RWST r w' s) where+ liftPass pass m = RWS.Strict.RWST $ \r s -> pass $ do+ ((a, f), w', s') <- RWS.Strict.runRWST m r s+ return ((a, w', s'), f)++instance Monoid w' => LiftPass (W.Lazy.WriterT w') where+ liftPass pass m = W.Lazy.WriterT $ pass $ do+ ~((a, f), w') <- W.Lazy.runWriterT m+ return ((a, w'), f)++instance Monoid w' => LiftPass (W.Strict.WriterT w') where+ liftPass pass m = W.Strict.WriterT $ pass $ do+ ((a, f), w') <- W.Strict.runWriterT m+ return ((a, w'), f)
+ src/Control/Monad/Trans/Lift/StT.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE KindSignatures #-}+-- | The 'StT' type family.+module Control.Monad.Trans.Lift.StT (StT) where++import qualified Control.Monad.Trans.Except as E+import qualified Control.Monad.Trans.Identity as I+import qualified Control.Monad.Trans.List as L+import qualified Control.Monad.Trans.Maybe as M+import qualified Control.Monad.Trans.Reader as R+import qualified Control.Monad.Trans.RWS.Lazy as RWS.Lazy+import qualified Control.Monad.Trans.RWS.Strict as RWS.Strict+import qualified Control.Monad.Trans.State.Lazy as S.Lazy+import qualified Control.Monad.Trans.State.Strict as S.Strict+import qualified Control.Monad.Trans.Writer.Lazy as W.Lazy+import qualified Control.Monad.Trans.Writer.Strict as W.Strict++-- | Internal state of a monad transformer.+-- Same as @StT@ from the @monad-control@ package.+type family StT (t :: (* -> *) -> (* -> *)) (a :: *) :: *++type instance StT (E.ExceptT e) a = Either e a+type instance StT I.IdentityT a = a+type instance StT L.ListT a = [a]+type instance StT M.MaybeT a = Maybe a+type instance StT (R.ReaderT r) a = a+type instance StT (RWS.Lazy.RWST r w s) a = (a, s, w)+type instance StT (RWS.Strict.RWST r w s) a = (a, s, w)+type instance StT (S.Lazy.StateT s) a = (a, s)+type instance StT (S.Strict.StateT s) a = (a, s)+type instance StT (W.Strict.WriterT w) a = (a, w)+type instance StT (W.Lazy.WriterT w) a = (a, w)
+ transformers-lift.cabal view
@@ -0,0 +1,35 @@+name: transformers-lift+version: 0.1.0.0+synopsis: Ad-hoc type classes for lifting+description:+ This simple and lightweight library provides type classes+ for lifting monad transformer operations.++license: BSD3+license-file: LICENSE+author: Index Int+maintainer: Index Int <vlad.z.4096@gmail.com>+category: Control+bug-reports: https://github.com/int-index/transformers-lift/issues+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Control.Monad.Trans.Lift.Local+ Control.Monad.Trans.Lift.CallCC+ Control.Monad.Trans.Lift.Catch+ Control.Monad.Trans.Lift.Listen+ Control.Monad.Trans.Lift.Pass+ Control.Monad.Trans.Lift.StT++ build-depends: base >=4.6 && <4.9+ , transformers >= 0.4.2++ default-language: Haskell2010+ other-extensions: CPP+ RankNTypes+ TypeFamilies+ KindSignatures++ hs-source-dirs: src+ ghc-options: -Wall