Emacs Org-Mode & Literate Haskell

前端 未结 4 699
不知归路
不知归路 2021-02-15 12:50

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 w

4条回答
  •  独厮守ぢ
    2021-02-15 13:20

    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.

提交回复
热议问题