[Haskell-cafe] '#' in literate haskell

sam lee skynare at gmail.com
Sat Nov 29 23:13:42 EST 2008


# 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 <jgm at berkeley.edu> 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
>
> ------------------------
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list