packages feed

monad-journal 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+56/−6 lines, 3 filesdep +either

Dependencies added: either

Files

Control/Monad/Journal/Class.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE FunctionalDependencies, UndecidableInstances #-}  {- | Module      :  Control.Monad.Journal.Class@@ -20,7 +20,15 @@   ) where  import Control.Monad ( Monad )-import Control.Monad.Trans ( MonadIO, liftIO )+import Control.Monad.Trans ( MonadIO, MonadTrans, lift, liftIO )+import Control.Monad.Trans.Either ( EitherT )+import Control.Monad.Trans.Identity ( IdentityT )+import Control.Monad.Trans.List ( ListT )+import Control.Monad.Trans.Maybe ( MaybeT )+import Control.Monad.Trans.RWS ( RWST )+import Control.Monad.Trans.Reader ( ReaderT )+import Control.Monad.Trans.State ( StateT )+import Control.Monad.Trans.Writer ( WriterT ) import Data.Monoid ( Monoid, mappend, mempty )  class (Monoid w, Monad m) => MonadJournal w m | m -> w where@@ -30,7 +38,7 @@   history :: m w   -- |Clear the logs history.   clear :: m ()-  + -- |Sink all logs history through `MonadIO` then clean it. sink :: (MonadJournal w m, MonadIO m) => (w -> IO ()) -> m () sink out = history >>= liftIO . out >> clear@@ -38,3 +46,43 @@ -- |Absorb a logs history and pass around the value. absorb :: (MonadJournal w m) => (a,w) -> m a absorb (a,w) = journal w >> return a++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (IdentityT m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ListT m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (MaybeT m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (RWST r w s m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ReaderT r m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (StateT s m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, Monoid q, MonadJournal w m) => MonadJournal w (WriterT q m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear++instance  (Monad m, Monoid w, MonadJournal w m) => MonadJournal w (EitherT e m) where+  journal !w = lift (journal w)+  history    = lift history+  clear      = lift clear
Control/Monad/Trans/Journal.hs view
@@ -28,7 +28,7 @@ newtype JournalT w m a = JournalT (StateT w m a) deriving (Applicative,Functor,Monad,MonadTrans,MonadIO)  instance (Monoid w, Monad m) => MonadJournal w (JournalT w m) where-  journal = JournalT . modify . flip mappend+  journal !w = JournalT . modify $ flip mappend w   history = JournalT get   clear   = JournalT (put mempty) 
monad-journal.cabal view
@@ -1,6 +1,6 @@ name:                monad-journal license:             PublicDomain-version:             0.2.0.0+version:             0.2.1.0 synopsis:            On-the-fly logging typeclass and monad transformer  description:         This package provides a typeclass for logging situations                      when you want to deal with the logs on-the-fly.@@ -15,7 +15,8 @@ cabal-version:       >= 1.10  library-  default-extensions:      FlexibleInstances+  default-extensions:      BangPatterns+                         , FlexibleInstances                          , MultiParamTypeClasses   other-extensions:        FunctionalDependencies                          , GeneralizedNewtypeDeriving@@ -25,5 +26,6 @@   build-depends:           base         >= 4.5 && < 4.6                          , mtl          == 2.1.*                          , transformers == 0.3.*+                         , either       == 4.1.*   default-language:        Haskell2010