编程语言中的控制结构:从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许可协议。

一篇最近发表在Xavier Leroy网站上的文章,探讨了编程语言中控制结构从`goto`到代数效应的演变,引发了Hacker News上的讨论。一位评论者tankenmate表达了对文章对异常批评分析不足的失望,指出异常与有问题“come from”语句(如`goto`、POSIX信号和`setjmp/longjmp`)相似。 另一位用户指出“come from”语句的惊人潜力,并提到了INTERCAL对其在简洁多线程方面的应用。最后,一位用户分享了Leroy关于同一主题的完整讲座在YouTube上可观看,专门面向法语使用者,在Collège de France发表。该帖子还包含一个Y Combinator申请公告。
相关文章

原文

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