[GHC] #9795: Debug.Trace.trace is too strict

GHC ghc-devs at haskell.org
Wed Nov 12 13:03:37 UTC 2014


#9795: Debug.Trace.trace is too strict
-------------------------------------+-------------------------------------
       Reporter:  jcpetruzza         |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  libraries/base     |                 Version:  7.8.3
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:
     Blocked By:                     |  None/Unknown
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 Consider the following toy example:

 {{{#!hs
 import Debug.Trace

 f n
   = let res = g n
     in (trace $ unlines ["in: " ++ show n, "out: " ++ show res])
        res
   where
     g n = if n <= 1000 then n+1 else g n

 main
   = print $ [f 500, f 302, f 2000, f 22]
 }}}

 When run it outputs:
 {{{
 in: 500
 out: 501

 in: 302
 out: 303

 ^C
 }}}

 In a real example, for a program that hangs, where one only ''suspects''
 that `f` may be the culprit, and where `f` is being called from various
 places with different values, this output  is not very useful (and in
 fact, it is misleading).

 My mental model of the `trace` function is something along these lines:

 {{{#!hs
 myTrace :: String -> a -> a
 myTrace s a
   = unsafePerformIO $ do
       putStrLn s
       return a
 }}}

 and in fact, replacing `trace` by `myTrace` in the example above one gets
 the more useful:

 {{{
 in: 500
 out: 501

 in: 302
 out: 303

 in: 2000
 ^C
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9795>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list