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

Modulepretty-simple-4.1.3.0Haskell2010

Debug.Pretty.Simple

This module contains the same functionality with Prelude's Debug.Trace module, with pretty printing the debug strings.

Warning: This module also shares the same unsafety of Debug.Trace module.

  • 50 values

Trace with color on dark background

14 declarations
valuepTrace :: String -> a -> a
#

pTrace remains in code

The pTrace function pretty prints 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 but first outputs the message.

pTrace ("calling f with x = " ++ show x) (f x)

The pTrace 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.

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

pTraceShow remains in code

Like pTrace, 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 value of the variables x and z:

f x y =
    pTraceShow (x, z) $ result
  where
    z = ...
    ...
valuepTraceIO :: String -> IO ()
#

pTraceIO remains in code

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

valuepTraceM :: Applicative f => String -> f ()
#

pTraceM remains in code

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

Note that the application of pTraceM is not an action in the Applicative context, as pTraceIO 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 . pTraceIO may be a better option.

... = do
  x <- ...
  pTraceM $ "x: " ++ show x
  y <- ...
  pTraceM $ "y: " ++ show y
valuepTraceStack :: String -> a -> a
#

pTraceStack remains in code

like pTrace, 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 pTraceStack behaves exactly like pTrace. 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.

valuepTraceEvent :: String -> a -> a
#

pTraceEvent remains in code

The pTraceEvent 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 pTraceEventIO 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 pTraceEvent.

valuepTraceMarker :: String -> a -> a
#

pTraceMarker remains in code

The pTraceMarker 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 pTraceMarkerIO 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 pTraceMarker.

Trace forcing color

12 declarations

Trace without color

12 declarations
valuepTraceShowNoColor :: Show a => a -> b -> b
#

pTraceShowNoColor remains in code

Similar to pTraceShow, but without color.

Example2 expressions
import qualified Data.Map as MpTraceShowNoColor (M.fromList [(1, True)]) ()fromList    [        ( 1        , True        )    ]()

Trace With OutputOptions

12 declarations