The Beauty of Rholang
Guest Content from Jim Whitescarver: the Theory and Story behind the Rholang Programming Language
Modern languages are generally based on sequential lambda calculus. The lambda calculus model is a versatile tool that has been applied in diverse fields, from the Apollo missions to cutting-edge artificial intelligence research; why, then, do we need an alternative computational model? In the real world things do not happen sequentially; everything is happening at once. Our social and physical world consists of entities communicating all at once: each receiving information, undergoing some dynamic process and then emitting information. This suggests a process model of computation, not lambda calculus, is required to faithfully model real systems. Rholang is that language process model. The Rho Calculus, a reflective higher-order variant of the asynchronous polyadic pi calculus, has been implemented in the open source RChain network in the novel formal RhoLang universal model of computation language enabling cooperation by developing the fabric of collective being by supporting autonomous individuals and groups sharing capabilities. Object capability security provides disintermediated ownership and control of assets and capabilities ensuring autonomous individuals with the power to cooperate as they see fit.
At first glance Rholang might appear to be foreign, if not a bit ugly even. As a primitive universal mathematical language it is very powerful yet difficult to program or read by humans. To better understand Rholang we must first take a look at π-calculus (pi-calculus). Rholang uses pi-calculus to build parallel send and listen primitives which are also executed in parallel.
Send: receptor ! (signal)
Listen: for { signal <- receptor ) { process }
These primitives become very powerful in Rholang since a send to a parameterized message pattern is delivered. Meanwhile, a listener listening for that specific pattern will be able to extract the information from any received message that matches it. The power of basic pattern recognition is provided in the primitive language natively. There is beauty in simplicity.
It is like objects receiving messages where you can send before you listen or listen before you send. Any expression magically can behave like an object by listening for messages to it. Given a read capability the behavior of an object can be enhanced dynamically by listening for new patterns representing objects in the state of becoming.
Listeners are akin to receptors in biochemistry where signals are molecules binding to the receptor pattern of the listener, like radio receivers where only signals of the right frequencies are received. In quantum physics listeners are akin to observers beautifully exhibiting quantum causality in the macrocosm as in the microcosm as bijection of the possible and the observed. In Rholang we create possibilities with “send”s” and observables with “listen for”.
This may also be thought of as enabling Active Inference where cognition of received signals may evolve exhibiting the minimum free energy principle determining the future by what you remember and listen for. By discovery of higher order patterns active inference enables higher order morphic resonance reifying habits that enrich the information ecology by synthesizing information. Rholang is perfectly good for constructed systems but it also serves well for emergent systems. While current rholang can only demonstrate this capability the future of rholang’s computational model can optimize this process and even utilize custom rho calc hardware ultimately quantum.
Values like “hello”, 2+2, true, x<y and [1,2,3] are simple processes representing themselves. All expressions are Rholang processes exhibiting data-program equivalence enabling introspection, reflection, mobility and higher order processes that generate processes.
In Rholang concurrent processes are combined in parallel using a vertical bar.
“Hello” | (42, x) | x!(42) | for ( value <- x ) { result ! ( value + 1 )} | result
Everything is happening at once like in nature. Things are not forced to be sequential unless they need to be. The sends and corresponding receives are considered to act simultaneously regardless of which actually came first. Expression of the sends and receives of a resulting process are subsequent in sequence of local time synchronization event ordering.
Rho calculus adds private names within an expression that cannot be forged outside the scope of the expression to pi calc with the “new” construct in Rholang.
new x, y, x in {process}
This enables encapsulated control, privacy, sharing and ownership. It enables fine grained sharing and delegation of capabilities without 3rd party intermediation. The names become property. It gives autonomy to the process which includes the internal state of compose-able components suitable for higher order programming.
The match statement rounds out the basic Rholang allowing the binding of names within patterns and conditional execution.
A ledger of Rholang processes on a network of processors also has a declarative nature. With absolute verifiable certainty the only things that can happen on the network are those the rho calc rules allow. Regardless of where the names are on the network or how they are implemented, property rights are enforced.
The real beauty of Rholang is how small it is and yet so powerful. It currently lacks a good debugger and debugging can be very ugly. But the future of Rholang looks terrific as Rholang matures and development tools become available. Rholang is a low level language. Enhancements like Rholang 0.2 and MacRhoLang can make Rholang easier to program. For example, pure distributed smalltalk that only sends messages to objects converts readily into a subset of Rholang with a rich catalog of class hierarchies of classes and interfaces available to the programmer. Ultimately behavioral typing will serve to insure program correctness.
The RChain Cooperative that developed the first Rholang network node has been dissolved. Currently the Rho Vision torch is being carried by an open collective and several startup ventures.