Browse files

Initial commit.

  • Loading branch information...
0 parents commit c3f20845dad00f72de254933df2c2ea9d339474f @mvv committed Jul 20, 2011
Showing with 148 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +27 −0 LICENSE
  3. +14 −0 README.md
  4. +2 −0 Setup.hs
  5. +67 −0 src/Control/Monad/Base.hs
  6. +34 −0 transformers-base.cabal
4 .gitignore
@@ -0,0 +1,4 @@
+cabal-dev
+dist
+.*
+*~
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2011, Mikhail Vorozhtsov
+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 names of the copyright owners nor the names of the
+ 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.
+
14 README.md
@@ -0,0 +1,14 @@
+Transformers-Base
+===========
+This package provides a straightforward port of [monadLib][monadLib]'s BaseM
+typeclass to [transformers][transformers].
+
+[monadLib]: http://hackage.haskell.org/package/monadLib
+[transformers]: http://hackage.haskell.org/package/transformers
+
+Installation
+------------
+The usual:
+
+ $ cabal install
+
2 Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
67 src/Control/Monad/Base.hs
@@ -0,0 +1,67 @@
+{-# LANGUAGE UnicodeSyntax #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FunctionalDependencies #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE UndecidableInstances #-}
+
+module Control.Monad.Base (
+ MonadBase(..)
+ ) where
+
+import Data.Monoid
+import Data.Functor.Identity
+import Control.Applicative
+import qualified Control.Monad.ST.Lazy as L
+import qualified Control.Monad.ST.Strict as S
+import Control.Monad.Trans.Class
+import Control.Monad.Trans.Identity
+import Control.Monad.Trans.Maybe
+import Control.Monad.Trans.List
+import Control.Monad.Trans.Reader
+import qualified Control.Monad.Trans.Writer.Lazy as L
+import qualified Control.Monad.Trans.Writer.Strict as S
+import qualified Control.Monad.Trans.State.Lazy as L
+import qualified Control.Monad.Trans.State.Strict as S
+import qualified Control.Monad.Trans.RWS.Lazy as L
+import qualified Control.Monad.Trans.RWS.Strict as S
+import Control.Monad.Trans.Error
+import Control.Monad.Trans.Cont
+
+class (Applicative μ, Monad μ,
+ Applicative η, Monad η) ⇒ MonadBase μ η | μ → η where
+ -- | Lift a computation from the base monad
+ liftBase η α μ α
+
+instance MonadBase IO IO where liftBase = id
+instance MonadBase Identity Identity where liftBase = id
+instance MonadBase Maybe Maybe where liftBase = id
+instance MonadBase (Either e) (Either e) where liftBase = id
+instance MonadBase [] [] where liftBase = id
+instance MonadBase (L.ST s) (L.ST s) where liftBase = id
+instance MonadBase (S.ST s) (S.ST s) where liftBase = id
+
+instance MonadBase μ η ⇒ MonadBase (IdentityT μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (MaybeT μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (ListT μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (ReaderT r μ) η where
+ liftBase = lift . liftBase
+instance (Monoid w, MonadBase μ η) ⇒ MonadBase (L.WriterT w μ) η where
+ liftBase = lift . liftBase
+instance (Monoid w, MonadBase μ η) ⇒ MonadBase (S.WriterT w μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (L.StateT s μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (S.StateT s μ) η where
+ liftBase = lift . liftBase
+instance (Monoid w, MonadBase μ η) ⇒ MonadBase (L.RWST r w s μ) η where
+ liftBase = lift . liftBase
+instance (Monoid w, MonadBase μ η) ⇒ MonadBase (S.RWST r w s μ) η where
+ liftBase = lift . liftBase
+instance (Error e, MonadBase μ η) ⇒ MonadBase (ErrorT e μ) η where
+ liftBase = lift . liftBase
+instance MonadBase μ η ⇒ MonadBase (ContT r μ) η where
+ liftBase = lift . liftBase
+
34 transformers-base.cabal
@@ -0,0 +1,34 @@
+Name: transformers-base
+Version: 0.1
+Category: Control
+Stability: experimental
+Synopsis: Lift computations from the bottom of a transformer stack
+Description:
+ This package provides a straightforward port of @monadLib@'s BaseM
+ typeclass to @transformers@.
+
+Homepage: https://github.com/mvv/transformers-base
+Bug-Reports: https://github.com/mvv/transformers-base/issues
+
+Author: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>
+Maintainer: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>
+Copyright: 2011 Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>
+License: BSD3
+License-File: LICENSE
+
+Cabal-Version: >= 1.6.0
+Build-Type: Simple
+
+Source-Repository head
+ Type: git
+ Location: https://github.com/mvv/transformers-base.git
+
+Library
+ Build-Depends:
+ base >= 4.3 && < 5,
+ transformers >= 0.2
+ Hs-Source-Dirs: src
+ GHC-Options: -Wall
+ Exposed-Modules:
+ Control.Monad.Base
+

0 comments on commit c3f2084

Please sign in to comment.