HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulebase-compat-0.14.1Haskell2010

Debug.Trace.Compat

  • 24 values
valuetraceId :: String -> String
#

Like trace but returns the message instead of a third value.

Example1 expression
traceId "hello"hello"hello"
valuetraceShowId :: Show a => a -> a
#

Like traceShow but returns the shown value instead of a third value.

Example1 expression
traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld")(6,"helloworld")
valuetraceM :: Applicative f => String -> f ()
#

Like trace but returning unit in an arbitrary Applicative context. Allows for convenient use in do-notation.

Note that the application of traceM is not an action in the Applicative context, as traceIO is in the IO type. While the fresh bindings in the following example will force the traceM expressions to be reduced every time the do-block is executed, traceM "not crashed" would only be reduced once, and the message would only be printed once. If your monad is in MonadIO, liftIO . traceIO may be a better option.

Example1 expression
:{do    x <- Just 3    traceM ("x: " ++ show x)    y <- pure 12    traceM ("y: " ++ show y)    pure (x*2 + y):}x: 3y: 12Just 18
valuetraceShowM :: (Show a, Applicative f) => a -> f ()
#

Like traceM, but uses show on the argument to convert it to a String.

Example1 expression
:{do    x <- Just 3    traceShowM x    y <- pure 12    traceShowM y    pure (x*2 + y):}312Just 18
valuetraceWith :: (a -> String) -> a -> a
#

Like trace, but outputs the result of calling a function on the argument.

Example1 expression
traceWith fst ("hello","world")hello("hello","world")
valuetraceShowWith :: Show b => (a -> b) -> a -> a
#

Like traceWith, but uses show on the result of the function to convert it to a String.

Example1 expression
traceShowWith length [1,2,3]3[1,2,3]
valuetraceEvent :: String -> a -> a
#

The traceEvent function behaves like trace with the difference that the message is emitted to the eventlog, if eventlog profiling is available and enabled at runtime.

It is suitable for use in pure code. In an IO context use traceEventIO instead.

Note that when using GHC's SMP runtime, it is possible (but rare) to get duplicate events emitted if two CPUs simultaneously evaluate the same thunk that uses traceEvent.

valuetraceIO :: String -> IO ()
#

The traceIO function outputs the trace message from the IO monad. This sequences the output with respect to other IO actions.

valuetraceMarker :: String -> a -> a
#

The traceMarker function emits a marker to the eventlog, if eventlog profiling is available and enabled at runtime. The String is the name of the marker. The name is just used in the profiling tools to help you keep clear which marker is which.

This function is suitable for use in pure code. In an IO context use traceMarkerIO instead.

Note that when using GHC's SMP runtime, it is possible (but rare) to get duplicate events emitted if two CPUs simultaneously evaluate the same thunk that uses traceMarker.

valuetraceShow :: Show a => a -> b -> b
#

Like trace, but uses show on the argument to convert it to a String.

This makes it convenient for printing the values of interesting variables or expressions inside a function. For example, here we print the values of the variables x and y:

Example1 expression
let f x y = traceShow ("x", x, "y", y) (x + y) in f (1+2) 5("x",3,"y",5)8

Note in this example we also create simple labels just by including some strings.

valuetraceStack :: String -> a -> a
#

like trace, but additionally prints a call stack if one is available.

In the current GHC implementation, the call stack is only available if the program was compiled with -prof; otherwise traceStack behaves exactly like trace. Entries in the call stack correspond to SCC annotations, so it is a good idea to use -fprof-auto or -fprof-auto-calls to add SCC annotations automatically.

valuetrace :: String -> a -> a
#

The trace function outputs the trace message given as its first argument, before returning the second argument as its result.

For example, this returns the value of f x and outputs the message to stderr. Depending on your terminal (settings), they may or may not be mixed.

Example2 expressions
let x = 123; f = showtrace ("calling f with x = " ++ show x) (f x)calling f with x = 123"123"

The trace function should only be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message.

valuetraceId :: String -> String
#

Like trace but returns the message instead of a third value.

Example1 expression
traceId "hello"hello"hello"
valuetraceShowId :: Show a => a -> a
#

Like traceShow but returns the shown value instead of a third value.

Example1 expression
traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld")(6,"helloworld")
valuetraceM :: Applicative f => String -> f ()
#

Like trace but returning unit in an arbitrary Applicative context. Allows for convenient use in do-notation.

Note that the application of traceM is not an action in the Applicative context, as traceIO is in the IO type. While the fresh bindings in the following example will force the traceM expressions to be reduced every time the do-block is executed, traceM "not crashed" would only be reduced once, and the message would only be printed once. If your monad is in MonadIO, liftIO . traceIO may be a better option.

Example1 expression
:{do    x <- Just 3    traceM ("x: " ++ show x)    y <- pure 12    traceM ("y: " ++ show y)    pure (x*2 + y):}x: 3y: 12Just 18
valuetraceShowM :: (Show a, Applicative f) => a -> f ()
#

Like traceM, but uses show on the argument to convert it to a String.

Example1 expression
:{do    x <- Just 3    traceShowM x    y <- pure 12    traceShowM y    pure (x*2 + y):}312Just 18
valuetraceWith :: (a -> String) -> a -> a
#

Like trace, but outputs the result of calling a function on the argument.

Example1 expression
traceWith fst ("hello","world")hello("hello","world")
valuetraceShowWith :: Show b => (a -> b) -> a -> a
#

Like traceWith, but uses show on the result of the function to convert it to a String.

Example1 expression
traceShowWith length [1,2,3]3[1,2,3]