[Haskell-cafe] Re: how do you debug programs?
Jón Fairbairn
jon.fairbairn at cl.cam.ac.uk
Wed Sep 6 10:52:29 EDT 2006
Tamas K Papp <tpapp at Princeton.EDU> writes:
> On Wed, Sep 06, 2006 at 06:33:32AM -0400, Lennart Augustsson wrote:
> > I've also used Visual Studio, and I wouldn't mind having something
> > like that for Haskell. But I have to agree with Jon, I think the
> > best way of debugging is to understand your code. I think people who
> > come from imperative programming come with a mind set that you
> > understand your code by stepping through it in the debugger. But I
> > find this paradigm much less useful for functional code.
>
> At this point, I need debugging not because I don't understand my
> code, but because I don't understand Haskell ;-) Most of the mistakes
> I make are related to indentation, precedence (need to remember that
> function application binds tightly). The compiler and the type system
> catches some mistakes, but a few remain.
I don't think you need a debugger for that. In addition to
what Lennart and Ketil have said, I think you need to take
on board the usefulness of breaking functions up into small
pieces that can be run at the GHCi or Hugs command line. And
if you aren't sure about precedence, you can type something
that demonstrates it, like this sort of thing:
*Main> let f = (+1)
*Main> f 1 * 2
4
(That particular example only works in GHCi, but you could use
let f = (+1) in f 1 * 2
in Hugs)
On top of that, in GHCi you can do this:
*Main> :info +
class (Eq a, Show a) => Num a where
(+) :: a -> a -> a
...
-- Imported from GHC.Num
infixl 6 +
*Main> :info *
class (Eq a, Show a) => Num a where
...
(*) :: a -> a -> a
...
-- Imported from GHC.Num
infixl 7 *
*Main>
Note in particular the two infixl lines, which say that both
operators bind to the left and that “*” binds more tightly
than “+”
And there's always Hoogle (and the documentation it links
to) if you want to find something of a particular
type. Kudos to Neil for producing this, by the way (though I
do hope his remarks about the readability of his code were a
more self deprecating than accurate).
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe
mailing list