[Haskell-cafe] Literate Haskell source files. How do I turn them into something I can read?

Iavor Diatchki iavor.diatchki at gmail.com
Sun Dec 31 19:52:09 EST 2006

I also dislike Haskell code that contains LaTeX macros as it makes
reading the comments more difficult (and I know both Haskell and
LaTeX).  Also converting the Haskell code to pdf is probably not a
good option because you cannot use all the usual tools in your editor:
I don't read code in the same way as I read a book.

Anyways, I would leave the source alone but here is how you can
determine which parts are code and which are comments (I also find it
useful to use the highlighting of my editor which highlights comments
and code differently).  Literate Haskell scripts usually have the
extension .lhs and in them the convention of what is code and what is
comment is reversed:  everything is a comment by default and code is
marked specially.   There are two ways to mark code.   Using the one
markup, code lines start with >.   For example:

This is a comment but the lines bellow contain code:

> main = print "This is code" -- a normal comment within a code block
> pi = 3.14

This is a comment again.  The second way to mark code is to place it
between \begin{code} and \end{code}.  For example:


main = print "This is code"
pi = 3.14


An here we have comments again.  Personally, I prefer the first form
of markup but, I guess, other people like the second form so Haskell
provides both, which may be confusing,

Hope this helps and Happy New Year to everyone!

On 12/31/06, Michael T. Richter <ttmrichter at gmail.com> wrote:
> On Sat, 2006-30-12 at 02:57 -0500, Cale Gibbard wrote:
> > Assuming that it's LaTeX-based literate source, you usually run
> > pdflatex on it to get a pdf of the code, but I'm not familiar with the
> > darcs code in particular, and whether anything special needs to be
> > done, or whether they have a specialised build for that.
> It appears to be the same markup used in the GHC compiler source code
> (which does not bode well for my future reading of the GHC source
> either).  Running it on the darcs source code generates several dozen
> pages (I'm not exaggerating!) of error messages and no dvi, ps or pdf
> files.  Playing around with various command line options doesn't help.
> Running it on the GHC source code generates simpler error messages, but
> error messages nonetheless.  Then it dumps me in some kind of
> interactive mode.  Here's some sample output:
> =====8<=====
> This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
> entering extended mode
> (./CgCon.lhs
> LaTeX2e <2003/12/01>
> Babel <v3.8d> and hyphenation patterns for american, french, german,
> ngerman, b
> ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch,
> esperanto, e
> stonian, finnish, greek, icelandic, irish, italian, latin, magyar,
> norsk, polis
> h, portuges, romanian, russian, serbian, slovak, slovene, spanish,
> swedish, tur
> kish, ukrainian, nohyphenation, loaded.
> ! Undefined control sequence.
> l.4 \section
>             [CgCon]{Code generation for constructors}
> ?
> =====8<=====
> I don't know LaTeX (if that's what this is) at all and I don't know
> Haskell sufficiently comfortably to actually distinguish reliably
> between LaTeX code and Haskell, so the direct .lhs source code is
> basically useless to me.  What's the trick people use to read it?
> --
> Michael T. Richter
> Email: ttmrichter at gmail.com, mtr1966 at hotpop.com
> MSN: ttmrichter at hotmail.com, mtr1966 at hotmail.com; YIM:
> michael_richter_1966; AIM: YanJiahua1966; ICQ: 241960658; Jabber:
> mtr1966 at jabber.cn
> "Thanks to the Court's decision, only clean Indians or colored people
> other than Kaffirs, can now travel in the trams." --Mahatma Gandhi
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list