Literate Programming in Haskell?
Sun, 18 Feb 2001 11:46:54 +0000

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


I'm no expert, but I've found a solution that works for me.  I use the


delimiters (rather than >).  Since these aren't standard Latex, I
threw together a style file that called the listings package to handle

The result is a file that ghc and hugs can compile directly, but which
latex can also process.  No need for weaving and tangling, while line
numbers in error messages are correct.  On the other hand, I'm not
doing anything very sophisticated - no labelling of blocks or anything
like that.

I needed to update to the version of tetex in the "testing" Debian
release to get this to work - the listing package in the standard
distribution doesn't support Haskell (not that I really use that
support), so if you get an error message about being unable to load
something, that may be the problem.  (Warning: I wouldn't recommend
moving to Debian testing at the moment; when I last tried the X
support had changed significantly and failed to install, so don't
upgraed anything apart from tetex).

I've included the style file.  I don't have a public example yet
(hopefully later this week), but I can email you a postscript file
directly if you want.

Haskell is the first language where I've managed to work happily with
literate programming - partly because of the direct integration and
partly because the order isn't critical and the code is compact.


PS The style file includes lots of stuff unrelated to literate
programming - delete everything but the first block, if you like.

On Sun, Feb 18, 2001 at 01:53:41AM -0500, Tom Moertel wrote:
> In the Haskell community is there a generally accepted best way to
> approach Literate Programming?  The language has support for literate
> comments, but it seems that many common LP tools don't respect it.
> For example, in order to convert some .lhs code into LaTeX via the noweb
> LP tools, I had to write a preprocessor to convert the ">" code blocks
> into something that noweb would respect.  (The preprocessor actually
> does a bit more and, in conjunection with noweb, gives pretty good
> results for little effort.  For an example, see:
> )
> Yet somehow, I don't think that my homebrew approach is optimal.  Can
> anybody recommend a particularly elegant LP setup for Haskell
> programming?  Or if you have an approach that works well for you, would
> you mind sharing it?
> Cheers,
> Tom
> _______________________________________________
> Haskell-Cafe mailing list


Content-Type: text/x-tex; charset=us-ascii
Content-Disposition: attachment; filename="haskell.sty"


% Code support

% stop warning from listings when used in article mode
     \csname lst@SetFirstLabel\endcsname}
    {\csname lst@SaveFirstLabel\endcsname}
%  basicstyle=\small,
%  keywordstyle=\underbar,
%  identifierstyle=\slshape,
%  commentstyle=\underbar
  literate={-}{{$-$}}1 {+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1
           {>}{{$>$}}1 {<}{{$<$}}1 
           {->}{{$\rightarrow$}}2 {>=}{{$\geq$}}2 {<-}{{$\leftarrow$}}2
           {<=}{{$\leq$}}2 {=>}{{$\Rightarrow$}}2 {\ .}{{ $\circ$}}2

% Page size


% Titles, layout etc


{\filright\footnotesize\enspace Andrew Cooke \enspace}

{3cm}{2.5ex plus .1ex minus .2ex}{1pc}

{3cm}{1.5ex plus .1ex minus .2ex}{1pc}

\setlength{\parindent 0pt}
\setlength{\parskip 1.5ex plus 0.5ex minus 0.2ex}

% eps images