Debugging 如何强制调试跟踪语句按顺序求值?

Debugging 如何强制调试跟踪语句按顺序求值?,debugging,haskell,io,lazy-evaluation,trace,Debugging,Haskell,Io,Lazy Evaluation,Trace,在另一次运行中: "x is: " 2 -8 "x is: " -7 3 "---" 我尝试了这里的建议:(bungpatterns Pragma+$!)以及添加Strict和StrictDataPragma,但是我仍然得到不一致的行为 "x is: " 2 "x is: " 3 -8 -7 "---" 是否有一种不必了解严格性/Haskell评估的解决方案?Debug.Trace函数打印到stderr,因此需要交错 至少,您可以将x及其前面的字符串放在一起,以区别于其他print输出 h

在另一次运行中:

"x is: "
2
-8
"x is: "
-7
3
"---"
我尝试了这里的建议:(bungpatterns Pragma+
$!
)以及添加
Strict
StrictData
Pragma,但是我仍然得到不一致的行为

"x is: "
2
"x is: "
3
-8
-7
"---"


是否有一种不必了解严格性/Haskell评估的解决方案?

Debug.Trace
函数打印到
stderr
,因此需要交错

至少,您可以将
x
及其前面的字符串放在一起,以区别于其他
print
输出

hmm :: a -> a
hmm x = unsafePerformIO $! do
  pure x

ff :: Int -> Int
ff z = do
  hmm (trace "x is: " . traceShowId) $ z 

您还可以使用
unsafePerformIO
重新定义打印到
stdout
的跟踪函数,以强制执行某些排序。

听起来您正在处理缓冲问题。您可以使用
hFlush
或只设置缓冲:

ff :: Int -> Int
ff x = trace ("x is: " ++ show x) x

上述措施似乎效果良好。谢谢

谢谢你的建议-不过似乎不起作用。
hmm :: a -> a
hmm x = unsafePerformIO $! do
  pure x

ff :: Int -> Int
ff z = do
  hmm (trace "x is: " . traceShowId) $ z 
ff :: Int -> Int
ff x = trace ("x is: " ++ show x) x
hSetBuffering stderr NoBuffering
hSetBuffering stdout NoBuffering
myTrace :: Show a => a -> a
myTrace x = unsafePerformIO $ do
  print x
  pure x