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
22 import System.IO.Unsafe
24 #ifdef __GLASGOW_HASKELL__
25 import Foreign.C.String
28 -- | 'putTraceMsg' function outputs the trace message from IO monad.
29 -- Usually the output stream is 'stderr' but if the function is called
30 -- from Windows GUI application then the output will be directed to the Windows
32 putTraceMsg :: String -> IO ()
34 #ifndef __GLASGOW_HASKELL__
38 withCString "%s\n" $ \cfmt ->
39 withCString msg $ \cmsg ->
42 foreign import ccall unsafe debugBelch :: CString -> CString -> IO ()
45 {-# NOINLINE trace #-}
47 When called, 'trace' outputs the string in its first argument, before
48 returning the second argument as its result. The 'trace' function is not
49 referentially transparent, and should only be used for debugging, or for
50 monitoring execution. Some implementations of 'trace' may decorate the string
51 that\'s output to indicate that you\'re tracing. The function is implemented on
54 trace :: String -> a -> a
55 trace string expr = unsafePerformIO $ do