CoMonads and the Web
As I stated a few weeks ago, I’m hoping to start a discussion on thinking about the Web in a different light that attempts to include its collective role and activities as a living substrate for multiple authors (human and machine) to extend and modify it across multiple edges in an ever adapting form. This perspective I am proposing for the Web is best understood as a Comonad *, an object from algebraic category theory. *For a basic introduction to Comonads, see Bartosz Milewski’s enjoyable description of them (https://bartoszmilewski.com/2017/01/02/comonads), as well as their dual, Monads (https://bartoszmilewski.com/2016/11/21/monads-programmers-definition/).
Since its inception, the World Wide Web was always described as a graph of URL internet located documents with http links embedded in each document (page). This has proven to be a very powerful and extensible model for publishing on the web and sharing documents by contextualized reference. Many features have been layered onto this: visually formatted pages, bookmarks, embedded javascript, breadcrumbs, cookies, already-viewed affordances, etc., but all these basically maintain the Web as a stateless entity when traversed and viewed. Even the semantic web emerged as a data extension of the Web with semantics introduced to describe entities and relations more precisely and in support of logical inference, yet the Web itself (http mechanics) doesn’t gain or utilize anything from these semantics, and so we have limited means for its extension. Keeping http simple like this is probably why the Web took off; it also limits its general potential and relies on third-parties for work-arounds, both open and closed. However, this graph model of the Web is not quite accurate, since in fact the Web changes and the way new links are introduced define critical mechanics of the Web not yet addressed explicitly by a graph model. More importantly, without the ability for users to view a web page (document) or navigate across the links, the Web as only a graph has virtually no value: it needs observers and actors to perform actions onto it. If on the other hand the views, the various contexts of users, and current location of a browser are considered as part of the overall Web model, what emerges is an algebraic framework for the Web (including algebras and coalgebras).
More specifically, if we assume the Web can grow indefinitely (perhaps not an infinite web, but certainly one where we don’t know when it will stop), we will need a formulation that encompasses this, analogous to the concept of streams of data which are List-like but have no obvious size but do have a current index. This is where Comonads possibly come in: they handle structures of unknown size with possible (even multiple) contexts over different of its elements. Comonads (W) consist of 2 maps (aka natural transformations, since a comonad is more accurately defined as an endofunctor):
A coproduct 𝛅: W(X) → W(X) × W(X) a kind of data copy & branch, and a counit 𝛆: W(X) → X that extracts some specific (focused) content out.
A common example used to describe a Comonad is the universal covering, which is a map (functor actually) taking a pointed space (𝑋, 𝑥0) and producing the space of homotopy classes of paths starting at 𝑥0 (think paths on top of other paths). This example extends to the rooted tree model on directed graphs G, whose vertices are all the paths starting from a root 𝑥0, and are connected if they have a single edge between them in G. This notion of spaces of traversals really begins to suggest the link between the usage of the Web and Comonads.
Other familiar example of Comonads are the Reader Comonad (its dual is the Writer Monad), which takes a set X and adds (reads) extra data (A) onto it , and the Stream Comonad, which takes a monoid sequence like time T and adds sets of maps T → X for the various histories or trajectories of X (which are contravariant in T) . The **coproduct 𝛅 **duplicates the data or relative histories and passes it along, while the counit 𝛆 forgets the rest of the data or the different histories and returns the value at the local context. This further characterizes a comonadic model of how web browsers work with the Web. (see Runar Bjarnason's blog example http://blog.higher-order.com/blog/2016/04/02/a-comonad-of-graph-decompositions/)
The Comonad of a graph can be visualized as a graph of graphs with different context views at each higher-level graph vertex. Going to a page involves selecting an index onto the Web and forming an element of its coproduct, namely the traversal; the browser request of the new page (http-get) at a site and its rendering of the http-response is the extraction (counit 𝛆). That’s all very abstract, but this lets us establish multiple forms of these principles for using with or even extending the current Web.
So, what actually can be the (indexed) contexts on a Comonad of a Web graph? I believe there are several practical candidates which I would like to list for consideration, in hopes they will elicit a useful discussion in this thread…
I will begin with the first example, which is about how most of us use the Web:
- The current location of a browser that a user is viewing is certainly one index of the Web graph; it is something that analyzers of web activity are constantly harvesting (think Hubspot, Facebook, etc). From each viewed location (browser context), a user views out onto parts of the larger Web from their particular context. Their subsequent actions are dictated by their initial objective+current thoughts (model), and the link-out content of the webpage they are currently viewing. The history path they create is itself a subgraph around their context, and since it extends during a session it is also comonadic.
Also consider, this is happening many times each second across the same Web by web users all over the planet! It's not different from what Tim BL was thinking, but here we include the activities of all users as part of the overall algebra, not just the static Web graph object.
-
In addition to the comonadic structure for the Web, when one uses a browser, the session begins with an initial site launch (using a searched returned, bookmarked or shared site). One is then given choices for next step with embedded displayed links relative to the page’s context. The hyperlink selection chosen is done based the user’s intent context (UIC), which also would benefit from being modeled. Each browser’s click and view is therefor an action on a Comonad and therefore a coalgebra h: X → W(X) from a locally-viewed page to an indexed site on the Web’s (via an internet protocol). Indeed, this action doesn’t alway complete, and one gets a 404 error or no internet connection. It would very useful to build upon these coalgebraic web actions.
-
The use of web cookies is another form of Comonad artifact, since many enable web apps to collect and analyze user-specific web (graph) traversals per a user context. Their inception and growth almost seem to indicate that the original web misjudged the utility/inclusion of these monadic forms. If we agreed that these are jcoalgebras, we would define exact ways of seeing all the cookies we accumulate and drag along, and would have better control of which types of cookies are acceptable. Currently, this is dark matter...
-
The notion of using the web to find things (intentional), not by single queries, but by assessing partial results (what it means to ‘google’) and deciding when to halt or go further. This (search context) has deeper implications for certain modes of use including:
- “find all items matching exactly characteristic C”
- “gather as much knowledge as possible about a space or field F”
- “find >40 mentions of a citation in other publications”
- “index everything based on page content and create an inverted index to look them up later” (Google)
-
By determining how to rank and index linked content, Google made a successful business of creating Comonad collections (inverted index) and allowing users to interact/search parts of it, while not sharing it as a whole. By fanning out relations to other associated sites, one is effectively applying a comultiplication to a set of sites. This Index Comonad could have been foreseen and built into the Web for open public use if the Web was seen as Algebraic.
-
WRT the Linked Data/Semantic Web, finding all data of type T⊂D is akin to a web-wide query which is a search-context over the Schema (or Ontology) D-based Instance Functor (D-SET) (Semantic Data context, SDC). Comonads could have several applications in finding/combining Linked Data across M sites. Alternatively, comonadic results could also be injected back into often used Linked Data repositories to optimize searches.
“The path to how I got to this site” is a context that has value for marketers, optimizers, and future smart sites which can use the path to offer more focused local items. In fact, the path is itself a graph of contexts (path history context, PHC) with the head being the current location.
Path Comonads can be saved and analyzed locally by users as part of a knowledge model. Instead of constantly bookmarking pages using weak semantics, the structure of multiple related pages is hyper-bookmarked as a semantic structure with context for a themed knowledge model. This knowledge can be individualized or aggregated with a community, and if indexed forms a Knowledge Context (KC).
-
The question “Where can I still go from here in this current page/linked data context” is something most of us do frequently. It depends on framing what kind of things am I looking for and being able to rank them. Future web sites may provide APIs that can assist with this dynamic user-driven ‘crawling’ contexts. Each potential context-dependent subgraph is also a Comonad element: ‘concept-indexed subgraphs of a graph centered at site X’. (path relevancy context, PRC)
-
Inclusion into future browsers of session-based mobile-context that actively assesses user- or machine-driven web traversals. This possibly adds a monadic model onto the traversal of the Web (merged with any local context) and keeping a compiled and processed structure of the visits at the last site visited. (think knowledge assembly). These opportunities make defining a **(Co)Algebraic Web **significant and worth the effort to design it. The browser and the web sites begin to form a more formal relation that will advance the possible applications on the Next Generation Web .
-
Web Links can be adorned with “why this link?” semantics, depending on the (browser) context of a traversal/search. This opens the possibility of obtaining different but not inconsistent results to the same site depending on what context had when visiting. Again, cookies are a poor, opaque version of this. Web meta-content would be available for Comonadic interactions by users/browsers.
I will pause here for now.
I hope to intentionally show which aspects of the Web can be currently implemented, possibly by extending browsers or search tools, as well as ornamenting web sites with additional reachable (http-get) labelled attributes. How the Web mechanism itself could be extended is a real possibility but not yet considered in this initial discussion.