2011-07-18 36 views
15

是否識別Haskell支持索引函數名稱,類型類型和變量引用?有沒有我可以在Literate Haskell源碼上運行的過濾器,它可以做到這一點,並給我一個不錯的PDF手冊或超鏈接的HTML文檔。Literate Haskell:引用和索引

這些都是nowebCWEB的一個很好的功能,我認爲這會刺激Literate Haskell的廣泛採用。

作爲一個例子,請看在CWEB中編寫的word count program。項目#4第一頁上的代碼塊是腳註的,代碼使用在哪裏。 LHS不支持塊,但我想知道代碼在哪裏使用:

  1. 註釋描述func。

    func = id

    用於:(XYZf,ABCG,第1.5節)

    func2 = indefined

    用於:(ABCX,第2.1節)

而且另外還有一個彙總了所有功能的索引名稱和變量沿着它們在文檔中引用的位置以及其他功能等。

+0

我認爲應該很容易通過創造性地使用LaTeX來模擬這一點。 – fuz

+0

目前Haddock和「:info」命令顯示了一個類型類的實例。但是我看不到在哪裏使用函數和變量。 – Deech

+0

通過「索引」,你的意思是一個將每個名字鏈接到它的文檔的索引,比如Haddock產生的索引。 – Heatsink

回答

1

在Latex中有一些可能性,下面使用包listings和makeindex創建所有函數的列表。此外\標籤被用於創建不同的部分之間的交叉引用:與

\documentclass[a4paper,11pt,reqno,twoside,pdflatex,makeidx]{amsart} 

\usepackage[a4paper]{geometry} 

\usepackage{listings} 
\lstloadlanguages{Haskell} 

\lstset{ 
    flexiblecolumns=false, 
    basewidth={0.5em,0.45em}, 
    basicstyle=\ttfamily, 
    language=haskell, 
    % numbers=left, % optional numbering of code lines 
    firstnumber=last, 
    numberstyle=\tiny, 
    stepnumber=2, 
    numbersep=5pt, 
    index={fac,fac2} 
} 

\lstnewenvironment{code}{}{} 

\usepackage{hyperref} 

\title{The factorial function} 
\author{Federico Squartini} 
\date{} 


\makeindex 

\begin{document} 
\maketitle 
\section{Factorial function} 
\label{code:fac1} 
The factorial function can be defined as: 

\begin{code} 

fac 0 = 1 
fac n = n * fac (n-1) 

\end{code} 

\section{Factorial function in constant space} 
The code for the factorial defined section~\ref{code:fac1} uses $o(n)$ stack 
space. The following function uses constant space: 

\begin{code} 

fac2 n = go 1 1 
    where 
     go !acc i| i <= n = go (acc*i) (i+1) 
       | otherwise = acc 

\end{code} 

\printindex 
\end{document} 

編譯:

pdflatex example.tex

makeindex example.idx

pdflatex example.tex

pdflatex example.tex

由此產生的pdf是here。這對於生成PDF文件非常有用。對於其他類型的輸出(例如html),您應該使用乳膠以及pandoc

另一種選擇是使用pandoc的markdown語法,並使用ad hoc latex命令(\ label和makeindex)。這應該簡化任務以及在源文件中產生較少的語法噪音。

+0

這是非常酷,但最終不是我要找的,因爲它需要使用標籤來手動干預以確定函數的名稱。感謝Latex課程! – Deech