3 ms·
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html http://www.haskell.org/ghc/docs/latest/html/libraries/base/D... As mentioned, it'll
by dllthomas 13y ago
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Debug-Trace.html http://www.haskell.org/ghc/docs/latest/html/libraries/base/D...
As mentioned, it'll only print when the wrapped value is actually evaluated, which won't always correspond to it's position very well.
However, it's very much worth noting: if you're in IO then you can just sprinkle debug statements. If you're not in IO, then your function isn't effect-full and you can run it (or pieces of it) safely with whatever args you care about (also, quickcheck is amazing).
- SilasX 13y agoThat doesn't help with debugging pure functions. Many times I've been in a position where something is going wrong in the composition of several functions and I want to know where the error is in all of that. Normally, I'd just append a print statement to each of the functions, but in haskell I'd have to rewrite the program to allow output at each stage or else break purity. Again, QuickCheck doesn't help with that.
- deleted 13y ago[deleted]
- dllthomas 13y agoI'm not following your first sentence. What doesn't help with debugging pure functions? Debug.Trace is quite precisely for the situation you describe. Another option would be to pull the file in question up in ghci and play directly with the components of the function - in pure code that should be safe in a way that it won't be in effect-full code. I also dispute the assertion that QuickCheck doesn't help - if you're getting weird behavior, then hopefully you can characterize that weird behavior, and get some example failed values out of QuickCheck - and getting a picture of what values the function is failing for can absolutely be useful.