Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Tracer
Contents
Description
Tracer
is a contravariant functor to thread observable values through a
number of transformers, possibly annotating them with additional information,
or filtering them based on evaluating predicates.
Synopsis
- newtype Tracer m a = Tracer {
- runTracer :: a -> m ()
- traceWith :: Tracer m a -> a -> m ()
- nullTracer :: Applicative m => Tracer m a
- stdoutTracer :: MonadIO m => Tracer m String
- debugTracer :: Applicative m => Tracer m String
- showTracing :: Show a => Tracer m String -> Tracer m a
- condTracing :: Monad m => (a -> Bool) -> Tracer m a -> Tracer m a
- condTracingM :: Monad m => m (a -> Bool) -> Tracer m a -> Tracer m a
- natTracer :: (forall x. m x -> n x) -> Tracer m s -> Tracer n s
Documentation
example: simply output a message on the console
let logTrace = traceWith $ showTracing $ stdoutTracer in logTrace "hello world"
example: calling a function and passing in a Tracer
example1 :: IO () example1 = do let logTrace a = traceWith (showTracing (contramap ("Debug: " ++) stdoutTracer)) a void $ callFun1 logTrace
callFun1 :: (String -> IO ()) -> IO Int callFun1 logTrace = do logTrace "in function 1" return 42
Instances
Contravariant (Tracer m) Source # | |
Applicative m => Semigroup (Tracer m s) Source # | |
Applicative m => Monoid (Tracer m s) Source # | |
tracing
tracers
nullTracer :: Applicative m => Tracer m a Source #
this Tracer
forgets about all arguments
debugTracer :: Applicative m => Tracer m String Source #
transformers
showTracing :: Show a => Tracer m String -> Tracer m a Source #
transform a traced value to a showable instance.
condTracing :: Monad m => (a -> Bool) -> Tracer m a -> Tracer m a Source #
conditionally trace an observable given the evaluation of a predicate.