1 -----------------------------------------------------------------------------
3 -- Module : Debug.Trace
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
11 -- The 'trace' function.
13 -----------------------------------------------------------------------------
17 putTraceMsg, -- :: String -> IO ()
18 trace, -- :: String -> a -> a
23 import System.IO.Unsafe
25 #ifdef __GLASGOW_HASKELL__
26 import Foreign.C.String
28 import System.IO (hPutStrLn,stderr)
31 -- | 'putTraceMsg' function outputs the trace message from IO monad.
32 -- Usually the output stream is 'System.IO.stderr' but if the function is called
33 -- from Windows GUI application then the output will be directed to the Windows
35 putTraceMsg :: String -> IO ()
37 #ifndef __GLASGOW_HASKELL__
40 withCString "%s\n" $ \cfmt ->
41 withCString msg $ \cmsg ->
44 foreign import ccall unsafe "RtsMessages.h debugBelch"
45 debugBelch :: CString -> CString -> IO ()
48 {-# NOINLINE trace #-}
50 When called, 'trace' outputs the string in its first argument, before
51 returning the second argument as its result. The 'trace' function is not
52 referentially transparent, and should only be used for debugging, or for
53 monitoring execution. Some implementations of 'trace' may decorate the string
54 that\'s output to indicate that you\'re tracing. The function is implemented on
57 trace :: String -> a -> a
58 trace string expr = unsafePerformIO $ do
63 Like 'trace', but uses 'show' on the argument to convert it to a 'String'.
65 > traceShow = trace . show
67 traceShow :: (Show a) => a -> b -> b
68 traceShow = trace . show