识字 Haskell (.lhs) 和 Haddock

发布于 2024-08-30 16:40:55 字数 552 浏览 10 评论 0原文

目前我只使用 Haddock,但在看到一些非常有趣的示例后(例如 这个要点 )的哈斯克尔,我有兴趣在一个项目中尝试它。

我得到的问题是:

  • 你在 Haddock 注释中写什么,在文学部分写什么?

  • 如何将文学编程扩展到多个文件?谁能向我指出一个在具有多个模块的包中使用文字编程的示例?您在较大的包中使用文学编程的经验是什么?

  • 文学 Haskell 的哪种风格(markdown、latex...)是首选?

  • 为什么你要使用有文化的 Haskell 或普通的 Haskell 进行编程?您是否使用这两种风格进行编程?如果是,为什么?

  • 您喜欢块样式 (\begin{code}) 还是鸟样式 (>)?为什么?

At the moment I'm only using Haddock but after seeing some really interesting examples (e.g. this gist) of literate Haskell, I'm interested in trying it out in a project.

The questions I got, are:

  • What do you write as Haddock comments and what do you write in the literate part?

  • How do you scale literate programming to multiple files? Can anyone point me to an example where literate programming is used in a package with multiple modules? What is your experience of using literate programming in larger packages?

  • Which flavour (markdown, latex, ...) of literate Haskell is preferred?

  • Why are you programming in literate Haskell or plain vanilla Haskell? Are you programming in both styles and if so why?

  • Do you prefer block-style (\begin{code}) or Bird-style (>)? Why?

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

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

发布评论

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

评论(2

裸钻 2024-09-06 16:40:55

我曾经写过很多文学程序

你在 Haddock 注释中写什么,在文学部分写什么?

外部 API 文档包含在 Haddock 注释中。其他一切都进入识字部分。 “其他一切”可能包括:

  • 数据结构的内部不变量
  • 为什么你要这样做
  • 代码的设计是什么
  • 为什么选择这种设计,其他设计是什么尝试并发现想要的

如何将读写编程扩展到多个文件?

与将大型 LaTeX 文档缩放为多个文件的方式相同:每个模块一个文件,然后是一个包含所有模块的巨大文件。

有人能给我举一个在具有多个模块的包中使用文字编程的示例吗?

它不是 Haskell,但 Quick C-- 编译器 是一个编写的大型函数程序使用文字编程。

您在大型软件包中使用文字编程的经验是什么?

文字编程非常适合记录棘手、困难或复杂的模块。对于大多数简单的模块,外部 API 文档(例如 Haddock)就足够了。任何有文字的程序都无法真正为您提供包含十多个模块的设计的全貌。为此,您需要其他工具和技术。

文学 Haskell 的哪种风格(markdown、latex...)是首选?

如果你要进行如此重大的投资,我肯定会选择 LaTeX,因为它具有数学功能,而且该工具通常更强大。

为什么你要使用有文化的 Haskell 或普通的 Haskell 进行编程?您是否使用这两种风格进行编程?如果是,为什么?

我的 Haskell 代码几乎总是普通的,原因有两个:

  • 我与拥有更多 Haskell 经验的资深人士一起工作,他们已经放弃了有文化的 Haskell。只有系统中最古老的模块才有可能成为 .lhs。

  • 对于 Haskell 来说,文字编程有点多余。文字编程工具的一大好处是,您可以摆脱编译器或语言定义可能对代码出现顺序施加的任何限制。但 Haskell 几乎没有这样的限制:使用前没有定义,对于典型的函数定义,我可以选择 let-绑定 或 where-绑定 辅助名称(或两个都)。 文学编程从来不只是花哨的注释,而对于“文学”Haskell,这就是您所得到的一切。这不值得麻烦。

你喜欢块式(\begin{code})还是鸟式(>)?为什么?

我非常喜欢块风格:

  • 它与地球上所有其他文字编程工具大致兼容。 (鸟迹是 Haskell 独有的。)

  • 我的编辑器可以更好地处理块样式。

I used to write a lot of literate programs.

What do you write as Haddock comments and what do you write in the literate part?

The external API documentation goes into the Haddock comments. Everything else goes into the literate part. "Everything else" might include:

  • Internal invariants of data structures
  • Why you are doing things this way
  • What the design of the code is
  • Why this design was chosen, what other designs were tried and found wanting

How do you scale literate programming to multiple files?

The same way you scale a large LaTeX document to multiple files: one file per module, then a giant file that \includes them all.

Can anyone point me to an example where literate programming is used in a package with multiple modules?

It's not Haskell, but the Quick C-- compiler is a large functional program that is written using literate programming.

What is your experience of using literate programming in larger packages?

Literate programming works very well for documenting tricky, difficult, or complex modules. For most simple modules, the external API documentation (e.g., Haddock) is enough. And no literate program is really going to give you the big picture of a design that contains more than a dozen modules. For that you need other tools and techniques.

Which flavour (markdown, latex, ...) of literate Haskell is preferred?

If you're making such a major investment, I'd definitely go with LaTeX just because of the math capability, and the generally greater power of the tool.

Why are you programming in literate Haskell or plain vanilla Haskell? Are you programming in both styles and if so why?

My Haskell codes are almost always all plain vanilla, for two reasons:

  • I work with senior people who have more Haskell experience, and they have abandoned literate Haskell. Only the very oldest modules in their system have any chance of being .lhs.

  • For Haskell, literate programming is kind of superfluous. One of the big benefits of a literate-programming tool is that you are freed from any constraints that the compiler or language definition might put on the order in which your code appears. But Haskell has almost no such constraints: there's no definition before use, and for a typical function definition I have the choice of let-binding or where-binding auxiliary names (or both). Literate programming was never just about fancy comments, and with "literate" Haskell that's about all you get. It's not worth the bother.

Do you prefer block-style (\begin{code}) or Bird-style (>)? Why?

I strongly prefer block style:

  • It's roughly compatible with every other literate-programming tool on the planet. (Bird tracks are unique to Haskell.)

  • My editor copes better with block style.

反话 2024-09-06 16:40:55

如果您打算在互联网上共享程序,我发现 Markdown 风格的 Lite Haskell 与 mathjax 的组合是一个很好的组合。 “Pandoc”程序非常出色,可以将“markdown+lhs”转换为您想要的任何格式,包括 PDF 或 HTML。如果您告诉 Pandoc 输出到 HTML,您可以使用 -mathjax (或其他类似的标志,如果您愿意的话)来渲染您的 Latex 数学公式。

当使用这种风格时,我发现 Bird 风格更可取,因为它对我来说更具可读性,并且似乎更适合 Markdown 风格。

将 Pandoc 与 Markdown 结合使用的好处是,您可以在代码、数学公式中添加引用,并且具有真正可移植的格式。您可以构建类似于科学研究论文但可执行的内容,也可以发布到博客/维基/网站。

Norman 表示,文学编程对于更清晰的代码排列很有用,这可以为 Norman 提供一个替代观点,可以说 Haskell 具有足够的表达能力,您用代码解决的问题实际上很有趣,并且可以通过解释性文本包围来真正受益。 。想想一篇数学研究论文。纯数学领域的优秀论文有大量文本来解释数学符号含义的动机或更高层次的解释。例如,在一篇关于纳维-斯托克斯方程的论文中,用文本解释方程的符号与牛顿动量守恒的关系,这将非常有用。

总之,我在使用 markdown+lhs 风格、美元符号嵌入乳胶数学公式、bird 风格和 pandoc 方面取得了良好的成功,并推荐使用。我建议像研究论文一样编写程序,并将 haskell 本身视为研究论文中的数学表达式。

If you intend to share programs on the internet, I've found a combination of literate haskell in markdown style with mathjax to be a great combination. The program "Pandoc" is seriously brilliant for taking this "markdown+lhs" to any format you desire, including PDF or HTML. If you tell Pandoc to output to HTML, you can use the -mathjax (or other similar flags if you prefer) to have your latex math formulas render.

When using this style, I find bird style to be preferable because it just is more readable to me and seems to fit along with the markdown style better.

The great thing about using Pandoc with markdown is that you can add citations to your code, math formulas, and have a really portable format. You can build something that resembles a scientific research paper but is executable and can also be posted to blogs/wikis/websites.

To give an alternative point to Norman where he says that literate programming is useful for clearer code arrangement, it could be argued that Haskell is expressive enough that the problems you solve with the code are actually interesting and can really benefit by being surrounded with explanatory text. Think of a mathematical research paper. Good papers in pure mathematics have a lot of text to explain the motivation or higher-level interpretations of what the mathematical notation means. In a paper about the Navier-Stokes equations, for example, it would be super useful to surround the notation of the equations with text explaining how it relates to Newton's conservation of momentum.

In summary, I have had good success with, and recommend, using markdown+lhs style, dollar signs to embed latex math formulas, bird style, and pandoc. I would recommend writing programs as if they were research papers and treat the haskell itself as you would mathematical expressions in a research paper.

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