Is traceIO unnecessarily specialised to the IO monad?
patrick at parcs.ath.cx
Fri Jan 25 17:44:51 CET 2013
Note that traceM won't work correctly for monads that are not strict in the
first argument of >>=, e.g. the Identity monad.
For example, this will not print anything: runIdentity $ traceM "test" >>
On Mon, Jan 21, 2013 at 11:48 AM, Chris Seaton <chris at chrisseaton.com>wrote:
> 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?
> Chris Seaton
> Libraries mailing list
> Libraries at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libraries