[Haskell-cafe] "doctest" for haskell -- a good project?

Don Stewart dons at galois.com
Sat Mar 22 04:39:44 EDT 2008


shaun:
>    Hello,
>    
>    I am an experienced programmer, currently learning Haskell. Currently I
>    write many things in python. I use both the "doctest" and "unittest"
>    modules extensively. As I write code, I simultaneously write doctest code
>    in the doc strings to explain/set out the "typical narrative" of how the
>    code is used. Then finishing off a module I write unittests for boundary
>    conditions, more complex test cases, and generally code that would be
>    annoying to write & read in doctests.
>    
>    I note that there is a unit testing framework for Haskell, but I don't see

There's a couple, QuickCheck is the best, it generalises unit testing to
property testing with random, or not so random, data.

>    any doctest module. Might this be a good project?
>    If so, suggestions as to resources would be greatly appreciated. I believe
>    I can't just "introspect" Haskell modules to get at
>    documentation/comments, like I can in python? (Why not? :)) I notice that
>    there are a few "documentation generators". Should I try to write an
>    extension of one of these? Haddock, for instance? Are there any Haddock
>    developers hanging out on this list, to encourage or dissuade me? :) (And
>    where is the Haddock doc for Haddock?)
>    
>    In any case, thanks in advance for any comments & advice.

I'm not sure how doctest works, or how it would work in a Haskell
setting, could you elaborate?

One idea that does strike me is that it would be super useful to have
the ability in ghci to extract the haddocks associated with a function.

     > :doc map

would result in:

     -- | 'map' @f xs@ is the list obtained by applying @f@ to each element
     -- of @xs@, i.e.,
     --
     -- > map f [x1, x2, ..., xn] == [f x1, f x2, ..
     -- > map f [x1, x2, ...] == [f x1, f x2, ...]

marked up in ascii.

I'm not sure if that's related to doctest, but it sure would be useful!

-- Don


More information about the Haskell-Cafe mailing list