如何在 Haskell 中编写 showIt 函数?

How to write a showIt function in Haskell?

在 Mathematica 中,ShowIt function 通常用于调试。 基本上,ShowIt 是一个恒等函数,可将其参数值打印到控制台。我想知道,如何为 Haskell 编写相同的函数。 Haskell 的问题在于,由于该函数执行 IO,因此它不能具有与输入类型相同的 return 类型。我想我们必须使用unsafe IO来实现showIt。但是我不知道怎么办。

Debug.Trace 包中已经存在。叫做traceShowId. (And it does use unsafePerformIO under the covers - you can see the implementation of trace here.)