Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a showIt function in Haskell?

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.

like image 492
Oxy Avatar asked Dec 19 '22 06:12

Oxy


1 Answers

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.)

like image 189
porges Avatar answered Dec 23 '22 15:12

porges