编程语言中的控制结构:从goto到代数效应
Control structures in programming languages: from goto to algebraic effects

原始链接: http://xavierleroy.org/control-structures/

本书全面探讨了编程语言设计,重点关注**控制结构**——决定程序执行流程的机制。它追溯了从早期的`goto`语句到现代技术的演变,考察了命令式和函数式范式。 本书首先回顾了Fortran和Algol的历史,然后介绍了高级命令式特性,如生成器和协程(通过Java、OCaml、Python和C++示例进行说明)。接着,本书转向函数式方法,详细介绍了延续、控制算子,以及**代数效应和效应处理程序**——一个现代研究领域。 本书以OCaml和Haskell作为主要示例,融合了历史背景、实用代码和理论基础。它提供了对语言设计独特的比较视角,并作为对前沿控制和效应管理技术的全面介绍。代码示例采用MIT许可协议。

这个Hacker News讨论围绕一篇关于编程语言控制结构演变的文章,从`goto`语句到代数效应。 讨论迅速转向关于错误处理的争论——具体来说,异常与返回值的优缺点。 许多评论者不喜欢异常,将其比作升级版的`goto`语句,并批评其隐式的控制流。 另一些人则为检查型异常(如Java中的异常)辩护,认为它们清晰且能够强制开发者处理错误。 一个反复出现的主题是错误应该被视为“异常”还是“预期”,这会影响异常和返回值的选择。 讨论还涉及代数效应作为一种潜在的解决方案,一些人强调了它们在管理副作用和并发方面的优势。 许多评论者提到具体的实现和性能考虑,尤其是在Haskell和OCaml等语言中。 一位用户推广了他自己的Haskell效应系统Bluefin,作为一种实用且简单的替代方案。 最终,这个帖子揭示了关于在现代编程中最佳错误处理和控制流方式的细微且持续的争论。
相关文章

原文

This book is a journey through the design space and history of programming languages from the perspective of control structures: the language mechanisms that enable programs to control their execution flows. Starting with the “goto” jumps of early programming languages and the emergence of structured programming in the 1960s, the book explores advanced control structures for imperative languages such as generators and coroutines, then develops alternate views of control in functional languages, first as continuations and their control operators, then as algebraic effects and effect handlers. Blending history, code examples, and theory, the book offers an original, comparative perspective on programming languages, as well as an extensive introduction to algebraic effects and other contemporary research topics in P.L.

Publication history

To be published by Cambridge University Press.

Book preview

This is an HTML preview of the book, generated with Hevea. License: CC-BY-NC-ND 4.0.

Part I: Control structures for imperative languages

Part II: Control operators for functional languages

Part III: From exceptions to algebraic effects and handlers

Part IV: Reasoning about control and effects

Code samples

The code samples shown in the book are available as a ZIP archive and are also shown in the pages below. License: MIT.

  • Chapter 1: Loops and conditionals in Fortran and Algol 60
  • Chapter 3: Subroutines, procedures and functions in Fortran and Algol 60
  • Chapter 4: Iterators in Java and OCaml. Generators in Python. Compiling generators to C++. Coroutines in Python.
  • Chapter 7: CPS (continuation-passing style) programming in OCaml
  • Chapter 8: callcc in OCaml; shift and reset in OCaml
  • Chapter 9: exceptions in OCaml
  • Chapter 10: effect handlers for user-defined effects in OCaml
  • Chapter 11: monads in OCaml and Haskell
联系我们 contact @ memedata.com