11

Someone had a great idea of combining Literate Haskell and Markdown. Made sense to me, so I wanted to try it. But there is something Haskell doesn't like about the Markdown '#' header syntax:

Hello World

> main = putStrLn "hello, world"

works...

$ runhaskell hello_world.lhs 
hello, world

While...

# Hello World #

> main = putStrLn "hello, world"

doesn't...

$ runhaskell hello_world.lhs
hello_world.lhs:1:3: lexical error at character 'H'

Is there there a definition of what is legal? The Haskell syntax only mentions Literate Haskell by example, and nothing to imply the Markdown syntax is invalid.

Anm
  • 3,291
  • 2
  • 29
  • 40
  • Sorry all... the blank line in the code was deleted when I tried to make my post concise, forgetting that there was an explicit reason why it was there. the missing line is _not_ the cause of my problem. – Anm Apr 01 '11 at 14:27

3 Answers3

5

A '#' in the first column causes problems with GHCi, even with blank lines before and after code blocks. If you are using Pandoc, you can work around this problem by using underlining for headings.

Hello World
-----------

>  main = putStrLn "hello, world"

This is a known problem: http://hackage.haskell.org/trac/ghc/ticket/4836

Peter
  • 66
  • 2
4

Read this:

http://www.haskell.org/onlinereport/literate.html

It says that to avoid errors, you need a blank line between comments and code.

Ptival
  • 9,167
  • 36
  • 53
  • 1
    Specifically, *"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."* imho this is really dumb...this behavior should be configurable via command-line flags or something. – Dan Burton Apr 01 '11 at 05:39
0

I've only used LHS with Pandoc but Pandoc does specify that a bird-track delimited block quote is a paragraph level element, and paragraphs in Pandoc markdown (and regular markdown) do need a blank line before them. So the following should work...

# Hello World #

> main = putStrLn "hello, world"
altercation
  • 2,087
  • 1
  • 14
  • 3