[Haskell-cafe] Debugging

Donald Bruce Stewart dons at cse.unsw.edu.au
Sat May 5 02:18:30 EDT 2007


monang:
> On 5/5/07, Stefan O'Rear <stefanor at cox.net> wrote:
> >On Fri, May 04, 2007 at 10:44:15PM -0700, Ryan Dickie wrote:
> >> I've only written trivial applications and functions in haskell. But the
> >> title of this thread got me thinking.
> >>
> >> In an imperative language you have clear steps, states, variables to 
> >watch,
> >> etc.
> >> What techniques/strategies might one use for a functional language?
> >
> >I personally most often use a divide-and-conquer approach.  I pick a
> >point about halfway down the call stack, and add trace calls.  If the
> >subproblems are handled correctly, narrow scope to higher levels;
> >otherwise narrow to lower levels.  Repeat until you have a single
> >misbehaving function.
> 
> Isn't that called binary search, instead of divide-and-conquer?
> 
> BTW, how about adding assertion in Haskell? Can it be done?
> (I've searched in my GHC 6.4.2 library documentation, and can't find 
> 'assert')

'assert' is in Control.Exception. there's also a couple of 3rd party
packages for assert-like behaviour:

    http://hackage.haskell.org/cgi-bin/hackage-scripts/package/loch-0.2
    http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Safe-0.1

> 
> Is there any way to automatically clean all the mess I've done in
> debugging/asserting (like removing all trace/assert expressions) when
> I compile Haskell source code? Or should I create a simple program to
> remove them?

Using a logging/writer monad might be a nice approach. 'assert's are
compiled out under -O, in G, too.

-- Don


More information about the Haskell-Cafe mailing list