Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 574
    • Merge requests 574
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9795
Closed
Open
Issue created Nov 12, 2014 by Daniel Gorín@jcpetruzzaReporter

Debug.Trace.trace is too strict

Consider the following toy example:

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:

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
Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC ekmett, hvr
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking