X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Debug%2FTrace.hs;h=79d44c75b4e3d3b97deb9febb87362d9ada29613;hb=17c3536d93b3d35082ac025bb35176168c359165;hp=993a72e412a338913c5f476ffe4fadeb0fdae52f;hpb=2c19d1a0efd17ab30b773ec3fd88f212af8317b6;p=ghc-base.git diff --git a/Debug/Trace.hs b/Debug/Trace.hs index 993a72e..79d44c7 100644 --- a/Debug/Trace.hs +++ b/Debug/Trace.hs @@ -1,20 +1,19 @@ ----------------------------------------------------------------------------- --- +-- | -- Module : Debug.Trace -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org -- Stability : provisional -- Portability : portable -- --- $Id: Trace.hs,v 1.2 2002/04/24 16:01:51 simonmar Exp $ --- --- The trace function. +-- The 'trace' function. -- ----------------------------------------------------------------------------- module Debug.Trace ( + -- * Tracing trace -- :: String -> a -> a ) where @@ -27,15 +26,25 @@ import GHC.IOBase import GHC.Handle #endif -#ifdef __GLASGOW_HASKELL__ {-# NOINLINE trace #-} +{-| +When called, 'trace' prints the string in its first argument to +standard error, before returning the second argument as its result. +The 'trace' function is not referentially transparent, and should only +be used for debugging, or for monitoring execution. Some +implementations of 'trace' may decorate the string that\'s output to +indicate that you\'re tracing. +-} trace :: String -> a -> a trace string expr = unsafePerformIO $ do hPutStr stderr string hPutChar stderr '\n' +#ifdef __GLASGOW_HASKELL__ fd <- withHandle_ "trace" stderr $ (return.haFD) postTraceHook fd +#endif return expr +#ifdef __GLASGOW_HASKELL__ foreign import ccall "PostTraceHook" postTraceHook :: Int -> IO () #endif