Ticket #7626: tracem.diff

File tracem.diff, 1.7 KB (added by chrisseaton, 3 years ago)

Patch

  • Debug/Trace.hs

    diff --git a/Debug/Trace.hs b/Debug/Trace.hs
    index f5839ee..0c017da 100644
    a b module Debug.Trace ( 
    2222        -- * Tracing
    2323        -- $tracing
    2424        trace,
     25        traceId,
    2526        traceShow,
     27        traceShowId,
    2628        traceStack,
    2729        traceIO,
     30        traceM,
     31        traceShowM,
    2832        putTraceMsg,
    2933
    3034        -- * Eventlog tracing
    trace string expr = unsafePerformIO $ do 
    109113    return expr
    110114
    111115{-|
     116Like 'trace' but returns the message instead of a third value.
     117-}
     118traceId :: String -> String
     119traceId a = trace a a
     120
     121{-|
    112122Like 'trace', but uses 'show' on the argument to convert it to a 'String'.
    113123
    114124This makes it convenient for printing the values of interesting variables or
    variables @x@ and @z@: 
    124134traceShow :: (Show a) => a -> b -> b
    125135traceShow = trace . show
    126136
     137{-|
     138Like 'traceShow' but returns the shown value instead of a third value.
     139-}
     140traceShowId :: (Show a) => a -> a
     141traceShowId a = trace (show a) a
     142
     143{-|
     144Like 'trace' but returning unit in an arbitrary monad. Allows for convenient
     145use in do-notation. Note that the application of 'trace' is not an action in the
     146monad, as 'traceIO' is in the 'IO' monad.
     147
     148> ... = do
     149>   x <- ...
     150>   traceM $ "x: " ++ show x
     151>   y <- ...
     152>   traceM $ "y: " ++ show y
     153-}
     154traceM :: (Monad m) => String -> m ()
     155traceM string = trace string $ return ()
     156
     157{-|
     158Like 'traceM', but uses 'show' on the argument to convert it to a 'String'.
     159
     160> ... = do
     161>   x <- ...
     162>   traceMShow $ x
     163>   y <- ...
     164>   traceMShow $ x + y
     165-}
     166traceShowM :: (Show a, Monad m) => a -> m ()
     167traceShowM = traceM . show
     168
    127169-- | like 'trace', but additionally prints a call stack if one is
    128170-- available.
    129171--