From 78abc6f016304bbe9d97c8110f211412f49e0101 Mon Sep 17 00:00:00 2001 From: Packit Date: Sep 25 2020 16:32:26 +0000 Subject: ghc-transformers-base-0.4.4 base --- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9d51261 --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2011, Mikhail Vorozhtsov, Bas van Dijk +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. + diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/src/Control/Monad/Base.hs b/src/Control/Monad/Base.hs new file mode 100644 index 0000000..ac0c886 --- /dev/null +++ b/src/Control/Monad/Base.hs @@ -0,0 +1,114 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE UnicodeSyntax #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE FunctionalDependencies #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE UndecidableInstances #-} + +#if MIN_VERSION_base(4,4,0) +{-# LANGUAGE Safe #-} +#endif + +#if MIN_VERSION_transformers(0,4,0) +-- Hide warnings for the deprecated ErrorT transformer: +{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} +#endif + +module Control.Monad.Base + ( MonadBase(..) + , liftBaseDefault + ) where + +import Data.Monoid +import Data.Functor.Identity +import Control.Applicative (Applicative(..)) +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 +import Control.Monad.Trans.Except +#if !MIN_VERSION_base(4,4,0) && HS_TRANSFORMERS_BASE__ORPHANS +import Control.Monad (ap) +import qualified Control.Monad.ST.Lazy as L +import qualified Control.Monad.ST.Strict as S +#endif +#if MIN_VERSION_base(4,4,0) +import qualified Control.Monad.ST.Lazy.Safe as L +import qualified Control.Monad.ST.Safe as S +#endif +import Control.Monad.STM (STM) + +class (Applicative b, Applicative m, Monad b, Monad m) + ⇒ MonadBase b m | m → b where + -- | Lift a computation from the base monad + liftBase ∷ b α → m α + +#define BASE(M) \ +instance MonadBase (M) (M) where liftBase = id + +BASE(IO) +BASE(Maybe) +BASE(Either e) +BASE([]) +BASE((→) r) +BASE(Identity) + +BASE(STM) + +#if !MIN_VERSION_base(4,4,0) && HS_TRANSFORMERS_BASE__ORPHANS +instance Applicative (L.ST s) where + pure = return + (<*>) = ap + +instance Applicative (S.ST s) where + pure = return + (<*>) = ap + +BASE(L.ST s) +BASE(S.ST s) +#endif + +#if MIN_VERSION_base(4,4,0) +BASE(L.ST s) +BASE(S.ST s) +#endif + +#undef BASE + +-- | Can be used as a default implementation for 'liftBase'. +-- +-- Note that: @liftBaseDefault = 'lift' . 'liftBase'@ +liftBaseDefault ∷ (MonadTrans t, MonadBase b m) ⇒ b α → t m α +liftBaseDefault = lift . liftBase + +#define TRANS(T) \ +instance (MonadBase b m) ⇒ MonadBase b (T m) where liftBase = liftBaseDefault + +TRANS(IdentityT) +TRANS(MaybeT) +TRANS(ListT) +TRANS(ReaderT r) +TRANS(L.StateT s) +TRANS(S.StateT s) +TRANS(ContT r) +TRANS(ExceptT e) +#undef TRANS + +#define TRANS_CTX(CTX, T) \ +instance (CTX, MonadBase b m) ⇒ MonadBase b (T m) where liftBase = liftBaseDefault + +TRANS_CTX(Monoid w, L.WriterT w) +TRANS_CTX(Monoid w, S.WriterT w) +TRANS_CTX(Monoid w, L.RWST r w s) +TRANS_CTX(Monoid w, S.RWST r w s) +TRANS_CTX(Error e, ErrorT e) +#undef TRANS_CTX diff --git a/transformers-base.cabal b/transformers-base.cabal new file mode 100644 index 0000000..130a943 --- /dev/null +++ b/transformers-base.cabal @@ -0,0 +1,48 @@ +Name: transformers-base +Version: 0.4.4 +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 , + Bas van Dijk +Maintainer: Mikhail Vorozhtsov +Copyright: + 2011 Mikhail Vorozhtsov , + Bas van Dijk +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 + +Flag OrphanInstances + Description: + Declare orphan Applicative instances for lazy and strict ST if needed + Default: True + +Library + Build-Depends: + base >= 3 && < 5, + stm >= 2.3, + transformers >= 0.2, + transformers-compat >= 0.2 + Hs-Source-Dirs: src + GHC-Options: -Wall + if flag(OrphanInstances) + CPP-Options: -DHS_TRANSFORMERS_BASE__ORPHANS=1 + else + CPP-Options: -DHS_TRANSFORMERS_BASE__ORPHANS=0 + Exposed-Modules: + Control.Monad.Base