3 ms·
Literate programming is more than that. It is encouraged to order things such that they make sense to the reader, not to the compiler. You can give names to c
by rekado 10y ago
Literate programming is more than that. It is encouraged to order things such that they make sense to the reader, not to the compiler. You can give names to chunks of code and later glue them all together in a different order.
My tool of choice for this is Emacs org-mode with noweb support. The source file is "tangled" (i.e. individual chunks of code are glued back together in a specified order) to create the source for the compiler to process.
Haskell itself has only limited support for literate programming. Most importantly it lacks the ability to reorder chunks of code. (noweb or org-mode babel can be used with Haskell, of course.)
- fanf2 10y agoThere's little need to reorder Haskell code because you can define things in any order. The literate programming tangle process mainly exists to remove Pascal's order restrictions.
- rekado 10y agoReordering is still useful in Haskell. Just two examples for order dependent things in Haskell: top-level Template Haskell splicing; imports and GHC feature comments. It can be nice to have a single document explaining the whole project, producing individual source files upon tangling. For this approach you need control over order and target files. "Literate Haskell" is hardly more than a reversal of the meaning of comments and code.