Is traceIO unnecessarily specialised to the IO monad?
chris at chrisseaton.com
Mon Jan 21 17:48:16 CET 2013
I use printf-style debugging a lot, so I am always adding and removing
applications of trace. There is the Debug.Trace.traceIO function that makes
this easy to do in the IO monad (it just applies hPutStrLn stderr), but is
that specialisation to IO unnecessary?
I find myself always using this utility function:
traceM :: (Monad m) => String -> m ()
traceM message = trace message $ return ()
Which can be used to implement traceIO.
traceIO :: String -> IO ()
traceIO = traceM
That way I can traceM in whatever monad I am in. It is easier to add and
remove an application of trace, because I do not have to wrap it around
something, and I do not have to remember the return. Of course, you are
still subject to however your monad chooses to order the execution of these
traces, but that is what people expect when using trace.
Would traceM be a wanted addition to Debug.Trace?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libraries