world as value

Peter Achten peter88@cs.kun.nl
Mon, 12 Jul 1999 15:54:09 +0200


Hello everybody in this thread,

I have been on holidays for the past four weeks and so missed the interesting discussion on the 'world-as-value' entirely. I have just finished reading all comments and arguments and would like to add some of my own. 

First things first: the World in Clean has a semantics which handles the 'independent' behaviour of the real world. I guess the confusion and cause of this thread arises because it has never been worked out in full detail, but the essential parts of it have appeared in papers and my PhD Thesis. I'll be as concise as possible.

Let me first note that "world-as-value" and "explicit multiple environment passing methodology" are actually different names for the same thing. The term world-as-value was introduced in my PhD.Thesis as a slogan: it should be short and catchy. The latter term is more technical and accurate. 

The World environment is supposed to contain the context of a(n interactive) program. It is composed of sub-environments, like the file system and event stream, which can consist of sub-environments themselves, such as individual files. It also contains _all_ other programs. The major point of the World, and any other, environment is that it is a _value_. 

All programs other than the 'main' program are values. The main program is a function of type *World -> *World. In this semantics the other programs, regardless of their source code, are considered to be a state transition system: they have some state (call it data space), and a function that changes its current state to a new state (call it time slice). Working in a functional setting, such a system can be easily modeled in a data structure and placed in the World. 

Now it's not difficult to explain what happens when a functional Clean program tries to open a file: the fopen function gets the current World value as argument and first evaluates an 'arbitrary' number of other programs. This models context switching. Note that 'arbitrary' can indeed be easily modeled by an infinite sequence of random numbers, also to be placed in the World. Then the file is being opened. This either succeeds or fails, depending on the fact whether any other program already closed or opened that particular file. The (dummy) file and result boolean are passed as result of fopen, as well as the new World value. [In his e-mail d.d. 6-15-1999, Fergus Henderson mentions a similar scheme, as well as its antiquity]

The scheme is deterministic: given a Clean program and a particular World value, one can in principle completely trace and predict the outcome of the program. This is already infeasible for small programs. In general you don't write programs with a particular World value in mind; that would be the same as writing a text editor knowing exactly which text is going to be typed in by the user. Programs must work properly regardless of other programs and disk contents. The input is not determined, but the output is. 

The world-as-value paradigm embodies the idea that in a functional language one works with functions and data structures that are constructed and passed around. To do I/O one simply passes _just another_ data structure, although it is abstract and unique. No new programming skills have to be learned. This makes it a bare-bones approach, and some people dislike this way of programming. 

Fortunately, the expressive power of functional languages allows you to easily abstract away from these environments if you want to and use e.g. a monadic style or continuation style. In a sense, but not completely, the GUI library of Clean is such an abstraction, allowing you to program large and complex interactive graphical user interface applications without passing around event stream environments or knowing in what order you have to build GUI components. 


I hope this reply provides more answers than that it raises questions.

Greetings, Peter Achten