+-- | 'putTraceMsg' function outputs the trace message from IO monad.
+-- Usually the output stream is 'stderr' but if the function is called
+-- from Windows GUI application then the output will be directed to the Windows
+-- debug console.
+putTraceMsg :: String -> IO ()
+putTraceMsg msg = do
+#ifndef __GLASGOW_HASKELL__
+ hPutStr handle msg
+ hPutChar handle '\n'
+#else
+ withCString "%s\n" $ \cfmt ->
+ withCString msg $ \cmsg ->
+ debugBelch cfmt cmsg
+
+foreign import ccall unsafe debugBelch :: CString -> CString -> IO ()