Jekyll blog articles as Literate Haskell modules

I recently learned cabal has a way to specify build-depends, ghc-options and more as comments in a source file, which then works with cabal run and cabal repl. This combined with markdown-unlit provides a great way to write blog posts using Markdown formatting (in my case for a Jekyll-based blog) as Literate Haskell modules, which can be executed/tested or loaded in a ghci REPL.

I wrote a little article showing how this works at Using Literate Haskell with Jekyll » I imagine the same approach can be used with other static site generators as well, of course :smiley:


Nice!! I explore the same problem a few months ago and came out with the opposite solution: write an actual .lhs file and use pandoc to convert it to markdown. The nice thing about using pandoc is that you can produce jupyter noteboks using a very small pandoc’s filter.

Also, if you use hakyll instead of jakyll (notice AFAIK jakyll is much more developed project) you can use the standard hakyll's compiler to convert .lhs to md, which is very convenient to write haskell blogpost.

I wrote some simple instructions on it. (A little bit of self-promotion)


I’ve become quite a fan of Literate Haskell myself for showcasing and explaining code on a web site. I have stylesheets generated by Clay on a Hakyll-based site, and I use Literate Haskell so the same file can be both the Haskell code and the web page. I also use a little trick based on a Hakyll tutorial such that the Haskell code is run during the Hakyll build of the site, so I need no manual regeneration of the stylesheets nor ever have to worry about the code and web page diverging.

If I really wanted to, I could even have all of the Hakyll-based Haskell code for my site included as pages on the site. I haven’t gone that far for them, though; they just have plain old Haddock documentation for now. But I expect I’ll be using a lot of Literate Haskell code for the Diagrams-based images I’m planning to include on the site; I expect lots and lots of text will be the only way the code won’t just be a random jumble of symbols to my eyes after a couple of months.