Control Structures in Programming Languages

3 days ago 1

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
Read Entire Article