add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / Debug / Trace.hs
index 84de4d6..ebacb6c 100644 (file)
@@ -1,3 +1,5 @@
+{-# LANGUAGE CPP, ForeignFunctionInterface #-}
+
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Debug.Trace
 -----------------------------------------------------------------------------
 
 module Debug.Trace (
-       -- * Tracing
-       putTraceMsg,      -- :: String -> IO ()
-       trace             -- :: String -> a -> a
+        -- * Tracing
+        putTraceMsg,      -- :: String -> IO ()
+        trace,            -- :: String -> a -> a
+        traceShow
   ) where
 
 import Prelude
@@ -40,7 +43,10 @@ putTraceMsg msg = do
      withCString msg  $ \cmsg ->
       debugBelch cfmt cmsg
 
-foreign import ccall unsafe debugBelch :: CString -> CString -> IO ()
+-- don't use debugBelch() directly, because we cannot call varargs functions
+-- using the FFI.
+foreign import ccall unsafe "HsBase.h debugBelch2"
+   debugBelch :: CString -> CString -> IO ()
 #endif
 
 {-# NOINLINE trace #-}
@@ -56,3 +62,11 @@ trace :: String -> a -> a
 trace string expr = unsafePerformIO $ do
     putTraceMsg string
     return expr
+
+{-|
+Like 'trace', but uses 'show' on the argument to convert it to a 'String'.
+
+> traceShow = trace . show
+-}
+traceShow :: (Show a) => a -> b -> b
+traceShow = trace . show