mmorph 1.1.2 → 1.2.2
raw patch · 5 files changed
Files
- CHANGELOG.md +36/−0
- LICENSE +2/−2
- mmorph.cabal +15/−11
- src/Control/Monad/Morph.hs +11/−22
- src/Control/Monad/Trans/Compose.hs +44/−70
CHANGELOG.md view
@@ -1,3 +1,39 @@+1.2.1++- `MFunctor` and `MMonad` instances for `AccumT`++1.2.0++* BREAKING CHANGE: Remove instances for `ErrorT` and `ListT`+ * These types are deprecated++1.1.5++* Fix build failures on GHC 8.4 and 8.6+* Add support for safe Haskell+ * Specifically, this marks the `Control.Monad.Trans.Compose` module as+ `Trustworthy`+ * The change in 1.1.4 to use `GeneralizedNewtypeDeriving` meant that the+ `Control.Monad.Trans.Compose` module was no longer inferred as safe+* Restore `Traversable` instance removed by mistake in 1.1.4++1.1.4 (Blacklisted)++* Unintentional removal of `Traversable` instance for `ComposeT`+ * This missing instance is restored in 1.1.5+ * This is the reason why the 1.1.4 release is blacklisted+* Fix `MonadFail`-related code to work for GHCJS+* The `MonadRWS` instance for `ComposeT` has a more flexible constraint+ * The constraint is now+ `MonadReader r (f (g m)), MonadWriter w (f (g m)), MonadState s (f (g m))`+ instead of `MonadRWS r w s (f g m)`+ * This loosening of the constraint is backwards-compatible++1.1.3++* Add an `MFunctor` instance for `ComposeT` for GHC >= 8.6+* Add GHC 8.8 support+ 1.1.2 * Conditionally disable `Polykinds` to support older versions of GHC
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013, Gabriel Gonzalez+Copyright (c) 2013, Gabriella Gonzalez All rights reserved. Redistribution and use in source and binary forms, with or without modification,@@ -9,7 +9,7 @@ * 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 Gabriel Gonzalez nor the names of other contributors may+* Neither the name of Gabriella Gonzalez nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
mmorph.cabal view
@@ -1,13 +1,13 @@ Name: mmorph-Version: 1.1.2-Cabal-Version: >= 1.8.0.2+Version: 1.2.2+Cabal-Version: >= 1.10 Build-Type: Simple License: BSD3 License-File: LICENSE-Copyright: 2013 Gabriel Gonzalez-Author: Gabriel Gonzalez-Maintainer: Gabriel439@gmail.com-Bug-Reports: https://github.com/Gabriel439/Haskell-MMorph-Library/issues+Copyright: 2013 Gabriella Gonzalez+Author: Gabriella Gonzalez+Maintainer: GenuineGabriella@gmail.com+Bug-Reports: https://github.com/Gabriella439/Haskell-MMorph-Library/issues Synopsis: Monad morphisms Description: This library provides monad morphism utilities, most commonly used for manipulating monad transformer stacks.@@ -15,14 +15,18 @@ Extra-Source-Files: CHANGELOG.md Source-Repository head Type: git- Location: https://github.com/Gabriel439/Haskell-MMorph-Library+ Location: https://github.com/Gabriella439/Haskell-MMorph-Library Library Hs-Source-Dirs: src Build-Depends:- base >= 4 && < 5 ,- mtl >= 2.1 && < 2.3,- transformers >= 0.2.0.0 && < 0.6,- transformers-compat >= 0.3 && < 0.7+ base >= 4.5 && < 5 ,+ mtl >= 2.1 && < 2.4,+ transformers >= 0.2.0.0 && < 0.7,+ transformers-compat >= 0.6.1 && < 0.8+ if impl(ghc < 8.0)+ Build-Depends:+ fail == 4.9.* Exposed-Modules: Control.Monad.Morph, Control.Monad.Trans.Compose GHC-Options: -O2+ Default-Language: Haskell2010
src/Control/Monad/Morph.hs view
@@ -1,7 +1,8 @@-{-# LANGUAGE CPP, RankNTypes #-}-+{-# LANGUAGE CPP #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE Safe #-} #if __GLASGOW_HASKELL__ >= 706-{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE PolyKinds #-} #endif {-| A monad morphism is a natural transformation:@@ -77,10 +78,9 @@ ) where import Control.Monad.Trans.Class (MonadTrans(lift))-import qualified Control.Monad.Trans.Error as E+import qualified Control.Monad.Trans.Accum as A import qualified Control.Monad.Trans.Except as Ex 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@@ -116,8 +116,8 @@ -} hoist :: (Monad m) => (forall a . m a -> n a) -> t m b -> t n b -instance MFunctor (E.ErrorT e) where- hoist nat m = E.ErrorT (nat (E.runErrorT m))+instance MFunctor (A.AccumT w) where+ hoist nat m = A.AccumT (nat . A.runAccumT m) instance MFunctor (Ex.ExceptT e) where hoist nat m = Ex.ExceptT (nat (Ex.runExceptT m))@@ -125,9 +125,6 @@ instance MFunctor I.IdentityT where hoist nat m = I.IdentityT (nat (I.runIdentityT m)) -instance MFunctor L.ListT where- hoist nat m = L.ListT (nat (L.runListT m))- instance MFunctor M.MaybeT where hoist nat m = M.MaybeT (nat (M.runMaybeT m)) @@ -237,13 +234,10 @@ t |>= f = embed f t {-# INLINABLE (|>=) #-} -instance (E.Error e) => MMonad (E.ErrorT e) where- embed f m = E.ErrorT (do- x <- E.runErrorT (f (E.runErrorT m))- return (case x of- Left e -> Left e- Right (Left e) -> Left e- Right (Right a) -> Right a ) )+instance Monoid w => MMonad (A.AccumT w) where+ embed f m = A.AccumT $ \w -> do+ ((b, wInner), wOuter) <- A.runAccumT (f $ A.runAccumT m w) w+ return (b, wInner `mappend` wOuter) instance MMonad (Ex.ExceptT e) where embed f m = Ex.ExceptT (do@@ -255,11 +249,6 @@ instance MMonad I.IdentityT where embed f m = f (I.runIdentityT m)--instance MMonad L.ListT where- embed f m = L.ListT (do- x <- L.runListT (f (L.runListT m))- return (concat x)) instance MMonad M.MaybeT where embed f m = M.MaybeT (do
src/Control/Monad/Trans/Compose.hs view
@@ -1,9 +1,18 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE StandaloneKindSignatures #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE DeriveTraversable #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE Trustworthy #-} +#if __GLASGOW_HASKELL__ >= 806+{-# LANGUAGE QuantifiedConstraints #-}+#endif+ {-| Composition of monad transformers. A higher-order version of "Data.Functor.Compose". -}@@ -19,6 +28,7 @@ import Control.Monad (MonadPlus(mzero, mplus), liftM) import Control.Monad.Cont.Class (MonadCont(callCC)) import Control.Monad.Error.Class (MonadError(throwError, catchError))+import Control.Monad.Fail (MonadFail(..)) import Control.Monad.Morph (MFunctor(hoist)) import Control.Monad.RWS.Class (MonadRWS) import Control.Monad.Reader.Class (MonadReader(ask, local, reader))@@ -27,83 +37,47 @@ import Control.Monad.Writer.Class (MonadWriter(writer, tell, listen, pass)) import Control.Monad.IO.Class (MonadIO(liftIO)) import Data.Foldable (Foldable(fold, foldMap, foldr, foldl, foldr1, foldl1))+import Data.Kind (Type) import Data.Traversable (Traversable(traverse, sequenceA, mapM, sequence)) import Prelude hiding (foldr, foldl, foldr1, foldl1, mapM, sequence) infixr 9 `ComposeT` -- | Composition of monad transformers.-newtype ComposeT (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *) m a+type ComposeT :: ((Type -> Type) -> Type -> Type) -> ((Type -> Type) -> Type -> Type) -> (Type -> Type) -> Type -> Type+newtype ComposeT f g m a = ComposeT { getComposeT :: f (g m) a }- deriving (Eq, Ord, Read, Show)+ deriving+ ( Alternative+ , Applicative+ , Eq+ , Foldable+ , Functor+ , Ord+ , Read+ , Show+ , Traversable+ , Monad+ , MonadCont+ , MonadError e+ , MonadFail+ , MonadIO+ , MonadPlus+ , MonadReader r+ , MonadRWS r w s+ , MonadState s+ , MonadWriter w+ ) instance (MFunctor f, MonadTrans f, MonadTrans g) => MonadTrans (ComposeT f g) where lift = ComposeT . hoist lift . lift -instance Functor (f (g m)) => Functor (ComposeT f g m) where- fmap f (ComposeT m) = ComposeT (fmap f m)--instance Applicative (f (g m)) => Applicative (ComposeT f g m) where- pure a = ComposeT (pure a)- ComposeT f <*> ComposeT a = ComposeT (f <*> a)- ComposeT a *> ComposeT b = ComposeT (a *> b)- ComposeT a <* ComposeT b = ComposeT (a <* b)--instance Alternative (f (g m)) => Alternative (ComposeT f g m) where- empty = ComposeT empty- ComposeT a <|> ComposeT b = ComposeT (a <|> b)--instance Monad (f (g m)) => Monad (ComposeT f g m) where- return a = ComposeT (return a)- m >>= f = ComposeT (getComposeT m >>= \x -> getComposeT (f x))- fail e = ComposeT (fail e)--instance MonadPlus (f (g m)) => MonadPlus (ComposeT f g m) where- mzero = ComposeT mzero- ComposeT a `mplus` ComposeT b = ComposeT (a `mplus` b)--instance MonadIO (f (g m)) => MonadIO (ComposeT f g m) where- liftIO m = ComposeT (liftIO m)--instance Foldable (f (g m)) => Foldable (ComposeT f g m) where- fold (ComposeT m) = fold m- foldMap f (ComposeT m) = foldMap f m- foldr f a (ComposeT m) = foldr f a m- foldl f a (ComposeT m) = foldl f a m- foldr1 f (ComposeT m) = foldr1 f m- foldl1 f (ComposeT m) = foldl1 f m--instance Traversable (f (g m)) => Traversable (ComposeT f g m) where- traverse f (ComposeT m) = fmap ComposeT (traverse f m)- sequenceA (ComposeT m) = fmap ComposeT (sequenceA m)- mapM f (ComposeT m) = liftM ComposeT (mapM f m)- sequence (ComposeT m) = liftM ComposeT (sequence m)--instance MonadCont (f (g m)) => MonadCont (ComposeT f g m) where- callCC f = ComposeT $ callCC $ \c -> getComposeT (f (ComposeT . c))--instance MonadError e (f (g m)) => MonadError e (ComposeT f g m) where- throwError = ComposeT . throwError- catchError m h = ComposeT $ catchError (getComposeT m) (getComposeT . h)--instance MonadRWS r w s (f (g m)) => MonadRWS r w s (ComposeT f g m)--instance MonadReader r (f (g m)) => MonadReader r (ComposeT f g m) where- ask = ComposeT ask- local = mapComposeT . local- reader = ComposeT . reader--instance MonadState s (f (g m)) => MonadState s (ComposeT f g m) where- get = ComposeT get- put = ComposeT . put- state = ComposeT . state--instance MonadWriter w (f (g m)) => MonadWriter w (ComposeT f g m) where- writer = ComposeT . writer- tell = ComposeT . tell- listen = mapComposeT listen- pass = mapComposeT pass+#if defined(__MHS__) || __GLASGOW_HASKELL__ >= 806+instance (MFunctor f, MFunctor g, forall m. Monad m => Monad (g m))+ => MFunctor (ComposeT f g) where+ hoist f (ComposeT m) = ComposeT (hoist (hoist f) m)+#endif -- | Transform the computation inside a 'ComposeT'. mapComposeT :: (f (g m) a -> p (q n) b) -> ComposeT f g m a -> ComposeT p q n b