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 trace -- :: String -> a -> a
21 import System.IO.Unsafe
24 #ifdef __GLASGOW_HASKELL__
29 {-# NOINLINE trace #-}
31 When called, 'trace' prints the string in its first argument to
32 standard error, before returning the second argument as its result.
33 The 'trace' function is not referentially transparent, and should only
34 be used for debugging, or for monitoring execution. Some
35 implementations of 'trace' may decorate the string that\'s output to
36 indicate that you\'re tracing.
38 trace :: String -> a -> a
39 trace string expr = unsafePerformIO $ do
42 #ifdef __GLASGOW_HASKELL__
43 fd <- withHandle_ "trace" stderr $ (return.haFD)
48 #ifdef __GLASGOW_HASKELL__
49 foreign import ccall "PostTraceHook" postTraceHook :: Int -> IO ()