
#9795: Debug.Trace.trace is too strict -------------------------------------+------------------------------------- Reporter: jcpetruzza | Owner: Type: bug | Status: merge Priority: normal | Milestone: 7.12.1 Component: libraries/base | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by jcpetruzza): I still think that being strict on the string is the wrong default for a function whose only purpose is debugging pure functions, and I don't quite see what the benefit of the current behaviour is. Simon's workaround works after the fact, when you already know that the problem might be `res` being bottom. When starting a debugging session, one doesn't always have a clear suspicion of the culprit. A good part of the usefulness of `trace` is giving you an indication that certain expression is actually being evaluated, even if the full string fails to be printed in full. The way I see it, in order to avoid problems with a strict `trace`, one should be more defensive and start using it as Simon indicates in a systematical way. Consider for example the following excerpt from the [[https://wiki.haskell.org/Debugging|wiki entry on debugging]]: A common idiom to trace a function is: {{{ #!haskell myfun a b | trace ("myfun " ++ show a ++ " " ++ show b) False = undefined myfun a b = ... }}} With the current behaviour, I believe this should really be: {{{ #!haskell myfun a b | trace "myfun " $ trace (show a ++ " " ++ show b) False = undefined myfun a b = ... }}} and/or an explanation on `trace` being strict and what could happen if `show a` or `show b` loop or have an infinite output. With a lazy `trace` all this goes away, making `trace` more powerful and easier to use. Perhaps there are very good reasons to keep `trace` strict, but I'm not aware of them... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9795#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler