traceM and traceShowM

Twan van Laarhoven twanvl at
Sun Oct 18 19:18:20 EDT 2009

Martijn van Steenbergen wrote:

> Joachim Breitner wrote:
>>     join traceShow :: (Show a) => a -> a
> Yes, you're right. I rarely use trace directly. I either use traceM, 
> join trace or join traceShow. I can't think of good names for these last 
> two functions, though. But if someone else can, I'm all in favour.

Perhaps traceShow should have had type (Show a) => a -> a, but assuming we don't 
want to remove existing functions, how about

     withTrace :: (Show a) => a -> a
     withTrace x = trace (show x) x

and perhaps

     withTraceMsg :: (Show a) => String -> a -> a
     withTraceMsg msg x = trace (msg ++ ": " ++ show x) x
                          -- not sure about formating

I'm not sure about a monadic variant of withTrace, what type should it have?


More information about the Libraries mailing list