Hi all!
I recently started hacking up some webpages that explain
some programming tricks in Haskell. For convenience, I
wanted these files to be runnable. Of course, literate
programming comes to the rescue.
Not!
Take a look at the following HTML literate fragment
(indented 2 spaces):
Take a look at the following "program snippet" (a very
popular word at last week's ICFP :-):
<PRE>
> bfReplace :: [b] -> Tree a -> Tree b
> bfReplace xs = deQ . bfReplaceQ xs . singletonQ
</PRE>
Now we just have to define <B>bfReplaceQ</B>.
Seems perfectly allright. But then Hugs complains and says:
ERROR "okasaki.lhs" (line 26): Program line next to
comment
Huh?!? Is this a bug in Hugs? Is it confused by the `<' and
`>' in the HTML code? No! It is just doing what the
Haskell98 report says:
C Literate comments
[...]
To capture some cases where one omits an ">" by mistake,
it is an error for a program line to appear adjacent to a
non-blank comment line, where a line is taken as blank if
it consists only of whitespace.
What the rationale is for this, is a big mystery to me. Look
at "to capture some cases"; what cases are captured by this?
And what cases are not captured by this? And why does this
silly restriction capture any of these cases?
This is just as silly as:
"Sometimes people forget to write commas in lists" --
"Let's force them to write every element on a single
line!". "Sometimes I miss-spell an identifier name" --
"Let's force everybody to write every identifier
twice!". Etc. etc.
So now I am forced to write my literate programs as follows:
Take a look at the following "program snippet" (a very
popular word at last week's ICFP :-):
<PRE>
> bfReplace :: [b] -> Tree a -> Tree b
> bfReplace xs = deQ . bfReplaceQ xs . singletonQ
</PRE>
Now we just have to define <B>bfReplaceQ</B>.
Which introduces large whitespaces in my text! It is
interesting to notice that the "\begin{code}" --
"\end{code}" style of literate programming does not have
this restriction -- for the same obvious reason.
Regards,
Koen.
--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424 mailto:[EMAIL PROTECTED]
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden