As the title says, for some reason, messages passed to the trace (well, a variant of which) function don't show up properly when debugging functions. Simply flushing stdout/stderr doesn't seem to do anything, either.
-- Makes it more like Haskell's trace
debug :: String -> α -> α
debug msg f = const f $ trace msg
-- dummy function
polyA :: (Num α) => α
polyA = debug "polyA\n" 0
-- another dummy function
polyB :: (Num α) => α
polyB = debug "polyB\n" polyA
main :: IO ()
main = do println (polyB :: Int )
println (polyB :: Int )
println (polyB :: Integer)
Output is just
0
0
with nothing visible in stderr (normally represented by red text in Eclipse's console).
As
constdoesn't use the second argument,tracedoesn't get invoked. You could useseqor pattern match.If you change the
debugfunction to this:or to this:
It still won't print anything due to flushing so if you change the
mainto flushstderr:It would work and it prints all the debug messages at the end:
As Ingo mentioned, we could also use
traceLnto have it flushed automatically when the function is called.