Safe Haskell | None |
---|---|
Language | Haskell98 |
Add tracing to the IO monad (see examples).
- Usage
{-# LANGUAGE RebindableSyntax #-} import Prelude hiding (catch, (>>=), (>>), return, fail) import Traced
- Example
test1 :: IO Int test1 = do Left x <- return (Left 1 :: Either Int Int) putStrLn "Hello world" Right y <- return (Left 2 :: Either Int Int) return (x + y)
outputs
Hello world *** Exception: user error (Pattern match failure in do expression at Traced.hs:187:3-9) Trace: 0 Left 2 1 Left 1
- Guards
Use the following idiom instead of using guard
:
test2 :: IO Int test2 = do Left x <- return (Left 1 :: Either Int Int) True <- return (x == 3) return x
The advantage of this idiom is that it gives you line number information when the guard fails:
*Traced> test2 *** Exception: user error (Pattern match failure in do expression at Traced.hs:193:3-6) Trace: 0 Left 1
- class MonadS m where
- return :: MonadS m => a -> m a
- (>>=) :: (MonadS m, Traceable a) => m a -> (a -> m b) -> m b
- (>>) :: MonadS m => m a -> m b -> m b
- fail :: MonadS m => String -> m a
- ifThenElse :: Bool -> a -> a -> a
- data Showable = forall a . Show a => Showable a
- class Traceable a where
- traceShow :: Show a => a -> Maybe Showable
Documentation
Like Monad
but bind is only defined for Trace
able instances
ifThenElse :: Bool -> a -> a -> a Source
Definition of ifThenElse
for use with RebindableSyntax
class Traceable a where Source
Traceable Bool | |
Traceable Float | |
Traceable Int | |
Traceable Int32 | |
Traceable Int64 | |
Traceable Word32 | |
Traceable Word64 | |
Traceable () | |
Traceable ThreadId | |
Traceable IOException | |
Traceable SomeException | |
Traceable ByteString | |
Traceable Transport | |
Traceable EndPoint | |
Traceable Connection | |
Traceable Event | |
Traceable EndPointAddress | |
Traceable [Char] | |
Traceable a => Traceable [a] | |
Traceable (Chan a) | |
Traceable (MVar a) | |
Traceable a => Traceable (Maybe a) | |
Show err => Traceable (TransportError err) | |
(Traceable a, Traceable b) => Traceable (Either a b) | |
(Traceable a, Traceable b) => Traceable (a, b) | |
(Traceable a, Traceable b, Traceable c) => Traceable (a, b, c) |