Search code examples
haskellmarkdownliterate-programming

What is legal Literate Haskell? Formal Syntax somewhere?


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.


Solution

  • 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