HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Moduleghc-10.0.0.20260917GHC2024

GHC.Utils.Trace

Tracing utilities

  • 13 values
valuepprTrace_ :: String -> SDoc -> ()
#

A version of pprTrace that is useful for quick debugging:

fooBar x y
  | cond      = body1
  | otherwise = body2
  where
    !_ = pprTrace_ "fooBar" $
         vcat [ text "x:" + ppr x
              , text "y:" + ppr y
              , text "cond:" + ppr cond
              ]
valuepprTraceWith :: String -> (a -> SDoc) -> a -> a
#

pprTraceWith desc f x is equivalent to pprTrace desc (f x) x. This allows you to print details from the returned value as well as from ambient variables.

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.