9

Occasionally I encounter the notion of continuation based web frameworks for Haskell. What does that mean exactly?

Continuations as I know them are gloried goto control structures. I fail to see how they relate to web stuff.

What exactly would using continuations give?

user782220
  • 10,677
  • 21
  • 72
  • 135

2 Answers2

6

A continuation-based web framework inverts flow of control in a web application. Instead of being page-oriented, it's flow-oriented. Displaying a web page is treated the same way as displaying a modal dialog in a desktop application. The flow of control (from the perspective of the user of the framework) is that one imperative action can request the display of multiple pages. The continuation being referred to is the rest of the action the user started.

Carl
  • 26,500
  • 4
  • 65
  • 86
  • How does "The continuation being referred to is the rest of the action the user started." make sense with http being stateless. Also I don't understand what you mean by "one imperative action can request the display of multiple pages". – user782220 Dec 30 '14 at 05:56
  • HTTP hasn't been stateless since cookies were invented. – Carl Dec 30 '14 at 15:47
  • So the sense of a continuation here does not mean that some lambda that represents a suspended computation is being saved in memory until the next relevant action. Somehow the cookie is being used to build something representing where the last request ended? – user782220 Dec 30 '14 at 21:55
  • @user782220, it's being saved "in memory", but the memory is either a cookie, a database entry, or some combination of these. – dfeuer Dec 31 '14 at 02:20
5

The canonical continuation-based web framework for Haskell is the venerable WASH system.

The idea is to capture state in the continuation, allowing for fully RESTful, stateless web apps that can in some cases be generated automatically from the non-continuation-based version of the program.

From "WASH/CGI: Server-side Web Scripting with Sessions and Typed, Compositional Forms": (2001):

The main idea is to use a continuation to take a snapshot of the state of the script after sending the form to the browser. This continuation is then stored on the server and the form contains a key for later retrieval of the continuation.

A modern description of the approach is given in the MFlow Monad Reader overview.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • Storing *application* state (a.k.a. *session* state) on the server is actually *not* RESTful as it violates REST’s [stateless constraint](https://www.baeldung.com/cs/rest-sessions). In the REST architectural style, application state is stored on the client (the server only stores *resource* state). Storing application state on the server gives a different architectural style named RS (remote session), e.g. Telnet and FTP. Storing it in both the client and the server gives yet another architectural style named RDA (remote data access), e.g. SQL. – Géry Ogam Jan 17 '22 at 19:43