News for hackers. Stuff that matters.
Re:The Haskell user experience by eli_gottlieb on Wednesday August 05, 2015 @09:29AM (#10009527)
Personally, I've been spending a lot of my recent time trying to debug a Parsec parser (it seems to be going into loops of backtracking, but I can't figure out where and why), and it's been a clusterfuck.

* `trace` and `traceM` don't actually get evaluated, so I can't use printing to find my bugs.

* Even putting `trace "..." True` as a guard to my parser combinators doesn't seem to actually print anything.

* `seq` and `deepseq` require that I implement all kinds of instances for datatypes whose innards I can't actually access, so I can't force the evaluation.

* I'm getting tempted to use `unsafePerformIO` just to get some damn debug output, but can't figure out how to make it have the right type inside the Parsec monad.

Debugging Haskell sucks when you need to debug dynamic behavior rather than type errors.

Re:The Haskell user experience by sfvisser on Wednesday August 05, 2015 @09:38AM (#10009586)
Note that trace is implemented in terms of unsafePerformIO (which is fine for debugging).

To get a trace message, you need to attach the trace to something that does get evaluated. I mostly define a somewhat simpler helper like this:

    tt :: Show a => a -> a
    tt x = trace (show x) x
So you surround your expressions with it and see there values, when those values get evaluated of course. Eg:

    myParser = (\_ code -> tt code) <$> parseComment <*> parseCode
Re:The Haskell user experience by jcl on Wednesday August 05, 2015 @03:56PM (#10012401)
Note: I just looked at the docs linked in creichert's sibling post, and I noticed that Debug.Trace provides traceShow as a helper.
Re:The Haskell user experience by creichert on Wednesday August 05, 2015 @12:48PM (#10011060)
Using the trace trick needs to guard on False:

  myfun a b | trace ("myfun " ++ show a ++ " " ++ show b) False = undefined
  myfun a b = ...
See here for some other helpful trace functions:

https://hackage.haskell.org/package/base-4.8.1.0/docs/Debug-...

There is even a traceStack which will print a call stack if available.