Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Org-Mode & Literate Haskell

In org-mode, a line starting with a colon is formatted as source code. ( http://orgmode.org/manual/Literal-examples.html )

In literate Haskell, source code lines start with a greater then sign.

I want to write literate Haskell with org-mode markdown, my current preferred format.

As I assume that I cannot change the Haskell compiler, my question is:

Can I somehow make the greater than sign a code-line marker in org mode? (I tried to find it myself, but as org.el is a 865k file, 22k loc, I'm still lost.)

like image 764
Falko Avatar asked Nov 18 '14 19:11

Falko


3 Answers

Not an exact answer to your question, but an example of how I write literate Haskell using org: https://github.com/haroldcarr/make-mp3-copies

The README.org is the literate Haskell, the MakeMP3Copies.hs is the resulting haskell file that is "tangled" out of the .org file.

I export to HTML and publish on my blog: http://haroldcarr.com/posts/2013-09-11-flac-to-mp3-via-haskell-shelly-and-ffmpeg.html

The README.org also autorenders on github (although there is some stuff in the autorendering that is only meant for HTML that I have not taken the time to fix).

like image 154
haroldcarr Avatar answered Oct 23 '22 18:10

haroldcarr


I'm a bit late, but I recently started to work on the 99 Haskell problems and decided to collect my work in an org mode file.

The orgmode way of literate programming (as I understand it), is to encapsulate source code blocks in BEGIN/END blocks. For example,

#+BEGIN_SRC hs :tangle yes
myReverse :: [a] -> [a]
myReverse l = myReverse' l []
myReverse' [] accu = accu
myReverse' (x:xs) accu = myReverse' xs (x:accu)
#+END_SRC

Such a structured orgmode document can then be

  • exported Exporting is the transformation of an orgmode file to one of several other file formats by means of a backend. Some of those formats are PDF, LateX or HTML.

  • tangled This goes in the direction of literate programming and weaving. Code blocks can be exported to pure source files. This is what I do in my 99 problems file.

  • executed Source code blocks can be executed, and the result of this execution can be placed directly in the orgmode file. I have not tried this yet for haskell.

You can have a look at my attempts at github: https://github.com/dischoen/H99 There I tangle the orgmode file to two haskell files, a module and a test harness, which can then be tested in ghc or ghci.

like image 21
dischoen Avatar answered Oct 23 '22 17:10

dischoen


I had essentially the same motivation, to use org-mode markup for my Haskell (Bird style) literate programs. I ended up using multi-mode which allows multiple emacs major modes to be used for different regions in the same buffer (there are others but multi-mode suited my requirements). I cooked up haskell-org which enables org-mode and haskell-mode to be used in a single buffer via multi-mode.

More details in this blog entry. The setup works well enough that I use it for my Haskell coding.

like image 5
sidhu1f Avatar answered Oct 23 '22 17:10

sidhu1f