4
看看traceIO
的描述,我覺得它確實是hPutStrLn stderr
所做的。然而,當我看着它的源代碼:`traceIO`和`hPutStrLn stderr`有什麼區別?
traceIO :: String -> IO()
traceIO msg = do
withCString "%s\n" $ \cfmt -> do
-- NB: debugBelch can't deal with null bytes, so filter them
-- out so we don't accidentally truncate the message. See TraC#9395
let (nulls, msg') = partition (=='\0') msg
withCString msg' $ \cmsg ->
debugBelch cfmt cmsg
when (not (null nulls)) $
withCString "WARNING: previous trace message had null bytes" $ \cmsg ->
debugBelch cfmt cmsg
看來它採用了國外的例行叫debugBelch
,我沒能找到任何文件。那麼traceIO
做什麼不能通過hPutStrLn stderr
完成?
難道不是'先評估$ force msg'才能避免干擾嗎? – dfeuer
@dfeuer你是對的,這*可以直接從Haskell完成。它已經作爲C函數提供。我已經編輯了我的答案並附上了關於此的說明。 –