'#' in literate haskell

Can anyone explain why ghc does not treat the following as a valid literate haskell program? --------- test.lhs ---- # This is a test
foo = reverse . words
------------------------ When I try to load this in ghci (or compile it using ghc), I get: test.lhs:1:2: lexical error at character 'T' It seems that the problem is the '#' character in the first column. Replacing it with something else, or moving it to the right one space, solves the problem. The following literate haskell program, from http://notvincenz.blogspot.com/2008/01/literate-haskell-and-c.html, also fails to load for me, for the same reason (the leading '#' in line 8). ---- literate-haskell-and-c.lhs --- /* c and lhs file
module Foo where main = print "Haskell"
*/ #include int main() { printf("C\n"); return 0; } ------------------------------------ I've reproduced this with ghc 6.10.1 and ghc 6.8.3 (linux binaries from haskell.org) and with ghc 6.8.2 (Ubuntu intrepid). Interestingly, hugs (September 2006 version) has no trouble with test.lhs. I haven't tried ghc 6.6. I care about this because I'd like to use markdown conventions to format the comment parts of literate haskell programs. Markdown supports atx-style headers, which begin with strings of '#' characters starting in the first column. I know that some people use markdown with literate haskell, so there must be something basic here that I'm missing! John

# is significant because it can be sh-bang line or pre-processor.
The only way I can think of is:
alias lhspp="sed 's/^#//'"
ghc --make -F -pgmF lhspp File.lhs
On Sat, Nov 29, 2008 at 10:07 PM, John MacFarlane
Can anyone explain why ghc does not treat the following as a valid literate haskell program?
--------- test.lhs ---- # This is a test
foo = reverse . words
------------------------
When I try to load this in ghci (or compile it using ghc), I get:
test.lhs:1:2: lexical error at character 'T'
It seems that the problem is the '#' character in the first column. Replacing it with something else, or moving it to the right one space, solves the problem.
The following literate haskell program, from http://notvincenz.blogspot.com/2008/01/literate-haskell-and-c.html, also fails to load for me, for the same reason (the leading '#' in line 8).
---- literate-haskell-and-c.lhs --- /* c and lhs file
module Foo where main = print "Haskell"
*/ #include
int main() { printf("C\n"); return 0; } ------------------------------------
I've reproduced this with ghc 6.10.1 and ghc 6.8.3 (linux binaries from haskell.org) and with ghc 6.8.2 (Ubuntu intrepid). Interestingly, hugs (September 2006 version) has no trouble with test.lhs. I haven't tried ghc 6.6.
I care about this because I'd like to use markdown conventions to format the comment parts of literate haskell programs. Markdown supports atx-style headers, which begin with strings of '#' characters starting in the first column. I know that some people use markdown with literate haskell, so there must be something basic here that I'm missing!
John
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

"sam lee"
# is significant because it can be sh-bang line or pre-processor.
This seems like it should be a bug, sha-bangs are unambiguous and the problem still occurs if compiled via `ghc -XNoCPP`. Regardless, I personally prefer the other sort of title in pandoc anyways, like A Title ------- -- BOFH excuse #51: Cosmic ray particles crashed through the hard disk platter

John MacFarlane wrote:
Can anyone explain why ghc does not treat the following as a valid literate haskell program?
--------- test.lhs ---- # This is a test
foo = reverse . words
------------------------
I believe this is an artifact of ghc trying to parse cpp style line number information:
foo.lhs >>> # 123 "foo.foo"
t = <> <<<
will print this error: foo.foo:124:6: parse error on input `<>' Bertram

+++ Bertram Felgenhauer [Nov 30 08 09:57 ]:
John MacFarlane wrote:
Can anyone explain why ghc does not treat the following as a valid literate haskell program?
--------- test.lhs ---- # This is a test
foo = reverse . words
------------------------
I believe this is an artifact of ghc trying to parse cpp style line number information:
foo.lhs >>> # 123 "foo.foo"
t = <> <<<
will print this error: foo.foo:124:6: parse error on input `<>'
Thanks! Mystery solved. John
participants (4)
-
Bertram Felgenhauer
-
John MacFarlane
-
mail@justinbogner.com
-
sam lee