Skip to content

Lenses and the Web: Modes of interaction

There is a way to think of web servers as Lenses discussed on Zulip in applied-ct/Optics-and-Lenses.

My interst in this started out with a talk Optics for servers presenting some ideas on how to build a web server in Idris using Lenses. I was not 100% convinced about traditional lenses being the best way to write a web server, and the view presented there is much too static for a read/write Solid Web: that is the paths are typed, where the web allows a very flexible layout of resources.

On the other hand there is a huge amount of emerging work generalising lenses to dynamical systems led by David Spivak et al (see the tweet thread for pointers) and these seem like these should open much more dynamical perspectives.

Lenses are closely linked to coalgebras. A few years ago in my first year phd report having learnt about coalgebras, these immediately seemed to capture key aspects of the read/write web. Coalgebras give a mathematical definition of getters and setters, which captures PUT and GET HTTP methods nicely.

But we are still left wanting to explain

  • POST on an ldp:Container - which creates a new resource
  • POST or PATCH on resources for Append purposes
  • DELETE on any kind of resources - individual or collectively

Note that the recent work on the category of Polynomials really allows one to model individual resources as having state that can be changed by setters and getters and where these actors can also change behaviour, leading me to think that they may be a good way to model Actors.

It would be very nice to locate these concepts in Cats precisely, as that could help in programming, modelling, and designing web protocols.

Edited by Henry Story