traceM and traceShowM

Philip K.F. Hölzenspies p.k.f.holzenspies at utwente.nl
Wed Nov 4 10:59:56 EST 2009


On Wed, 2009-11-04 at 15:40 +0000, Simon Marlow wrote:
> On 16/10/2009 14:22, Martijn van Steenbergen wrote:
> > Hello,
> >
> > I propose the addition of the following two functions to module
> > Debug.Trace:
> >
> >> traceM :: Monad m => String -> m ()
> >> traceM msg = trace msg (return ())
> >>
> >> traceShowM :: (Show a, Monad m) => a -> m ()
> >> traceShowM = traceM . show
> 
> is traceShowM really necessary?  It doesn't save many characters, and 
> fails the "don't name a composition" test.

As a post-deadline suggestion to fix Simon's (valid) reservation:

traceShowM :: (Show a, Monad m) => a -> m a
traceShowM a = traceM (show a) a

This allows easier trace insertion, e.g.:

foo a = do
	x <- bar  a
	y <- frop x

becomes

foo a = do
	x <- bar  a >>= traceShowM
	y <- frop x >>= traceShowM

This, to me, looks like a nice syntactic solution.

Regards,
Philip

PS. Is there some seq/deep_seq/strict/whatever solution for the lazy
monads problem hiding in here somewhere?



More information about the Libraries mailing list