4

In Mathematica, ShowIt function is commonly used for debugging. Basically, ShowIt is an identity function that prints the value of its parameter to the console. I wonder, how it is possible to write the same function for Haskell. The issue with Haskell is that since the function does IO, it cannot have the same return type as the input type. I think we have to use unsafe IO to implement showIt. But I have no idea how.

Community
  • 1
  • 1
Oxy
  • 323
  • 2
  • 9
  • For a better way of debugging pure code, see [You Could Have Invented Monads! (And Maybe You Already Have)](http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html). – Cirdec Feb 11 '15 at 00:24

1 Answers1

11

This already exists in the Debug.Trace package. It's called traceShowId. (And it does use unsafePerformIO under the covers - you can see the implementation of trace here.)

porges
  • 30,133
  • 4
  • 83
  • 114