1-----------------------------------------------------------------------------
3-- Module : Control.Monad.Logger
4-- Author : Phil Freeman
5-- License : MIT (http://opensource.org/licenses/MIT)
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
11-- | A replacement for WriterT IO which uses mutable references.
13-----------------------------------------------------------------------------
15{-# LANGUAGE FlexibleInstances #-}
16{-# LANGUAGE MultiParamTypeClasses #-}
17{-# LANGUAGE TypeFamilies #-}
19module Control.Monad.Logger where
26import Control.Monad (ap)
27import Control.Monad.IO.Class
28import Control.Monad.Writer.Class
29import Control.Monad.Base (MonadBase(..))
30import Control.Monad.Trans.Control (MonadBaseControl(..))
32-- | A replacement for WriterT IO which uses mutable references.
33newtype Logger w a = Logger { runLogger :: IORef w -> IO a }
35-- | Run a Logger computation, starting with an empty log.
36runLogger' :: (Monoid w) => Logger w a -> IO (a, w)
43instance Functor (Logger w) where
44 fmap f (Logger l) = Logger $ \r -> fmap f (l r)
46instance (Monoid w) => Applicative (Logger w) where
47 pure = Logger . const . pure
50instance (Monoid w) => Monad (Logger w) where
52 Logger l >>= f = Logger $ \r -> l r >>= \a -> runLogger (f a) r
54instance (Monoid w) => MonadIO (Logger w) where
55 liftIO = Logger . const
57instance (Monoid w) => MonadWriter w (Logger w) where
58 tell w = Logger $ \r -> atomicModifyIORef' r $ \w' -> (mappend w' w, ())
59 listen l = Logger $ \r -> do
60 (a, w) <- liftIO (runLogger' l)
61 atomicModifyIORef' r $ \w' -> (mappend w' w, (a, w))
62 pass l = Logger $ \r -> do
63 ((a, f), w) <- liftIO (runLogger' l)
64 atomicModifyIORef' r $ \w' -> (mappend w' (f w), a)
66instance (Monoid w) => MonadBase IO (Logger w) where
69instance (Monoid w) => MonadBaseControl IO (Logger w) where
70 type StM (Logger w) a = a
71 liftBaseWith f = Logger $ \r -> liftBaseWith $ \q -> f (q . flip runLogger r)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list