识字哈斯克尔:参考文献和索引

发布于 2024-11-25 06:56:13 字数 701 浏览 0 评论 0原文

Literate Haskell 支持索引函数名称、类型类和变量引用吗?是否有一个可以在 Literate Haskell 源上运行的过滤器来执行此操作,并为我提供一份不错的 PDF 手册或超链接的 HTML 文档。

这些是 nowebCWEB 我认为这将刺激 Literate Haskell 的广泛采用。

作为示例,请查看用 CWEB 编写的字数统计程序。第 4 项中第一页上的代码块带有使用该代码的位置的脚注。 LHS 不支持块,但我想知道代码在哪里使用:

  1. 描述 func 的注释。

    func=id

    用于:(XYZf、ABCg、第 1.5 节)

    func2 = 未定义

    用于:(ABCx,第 2.1 节)

另外还有一个索引,用于聚合所有函数名称和变量以及它们在文档中和其他函数等中引用的位置。

Does Literate Haskell support indexing function names, typeclasses and variable references? Is there a filter I can run on Literate Haskell source that will do this and give me either a nice PDF manual or a hyperlinked HTML document.

These are a really nice features of noweb and CWEB which I think it would spur widespread adoption of Literate Haskell.

As an example, look at the word count program written in CWEB. The code chunk on the first page in item #4 is footnoted with where that code is used. LHS doesn't support chunks but I'd like to know where the code is being used:

  1. Comment describing func.

    func = id

    Used in: (X.Y.Z.f, A.B.C.g, Section 1.5)

    func2 = indefined

    Used in: (A.B.C.x, Section 2.1)

And additionally an index that aggregates all the function names and variables along where they're referenced in the document and by other functions etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2024-12-02 06:56:13

Latex中有一些可能性,以下使用包 listings,与 makeindex 一起创建所有函数的列表。此外,\label 用于在不同部分之间创建交叉引用:

\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 示例.tex

makeindex 示例.idx

pdflatex 示例.tex

pdflatex 示例.tex

生成的 pdf 位于 此处。这对于生成 pdf 文件非常有用。对于其他类型的输出(例如 html),您应该将 Latex 与 pandoc 一起使用。

另一种选择是使用 pandoc 的 markdown 语法,与临时乳胶命令(\label 和 makeindex)混合。这应该会简化任务并减少源文件中的语法噪音。

There are some possibilities in Latex, the following uses the package listings, together with makeindex to create a list of all functions. Furthermore \label is used to create cross-references between different sections:

\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}

Compile with:

pdflatex example.tex

makeindex example.idx

pdflatex example.tex

pdflatex example.tex

Resulting pdf is here. This is great for producing pdf files. For other kind of outputs (e.g. html) you should use latex together with pandoc.

Another option is to use pandoc's markdown syntax, mixed with ad hoc latex commands (\label and makeindex). This should simplify the task as well as producing less syntactic noise in the source files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文