world as value

Adrian Hey ahey@iee.org
Tue, 22 Jun 1999 15:11:34 +0100 (BST)


On Mon 21 Jun, Fergus Henderson wrote:
> They were trying to find ways to express operations such as getting the
> current time in a purely functional setting in a way that didn't violate
> desirable properties of pure functional languages such as referential
> transparency.

My answer to this would be that there is no such thing as the "current time"
as far as a purely functional program (or any deterministic program, functional or otherwise) is concerned. The only times the program can be aware of are the
times of events (after those events have occured of course, even the physicist
demands causality, or maybe not ??). 

This is interesting because it neatly illustrates why (apparent)
non-determinism is necessary in real world systems.

Suppose I ask my computer to perform some computationally intense activity
which is going to take a long time, like placing and routing an FPGA (this
takes hours). Immediately after this I ask the computer the time. Let's say
I do this at precisely 2:00 pm.
 First question   - What time should the computer output?
 Answer           - The time of the "me ask computer" event I.E. 2:00 pm
 Second quesition - When does it do this?
 Answer           - When the FPGA has been placed and routed, lets say 4:15 pm

I think most people would regard this as "intolerable behaviour". What it
should do is suspend the placing and routing of the FPGA to for moment, in
order to respond, telling me the time is 2:00 pm at 2:00 pm, or very shortly
thereafter. But it simply can't do this if it's running a program expressed as
a function mapping input events to output events. This would be
non-deterministic.

> (Of course modern hardware includes non-deterministic components
> (e.g. my CD writer seems to be decidedly non-determinstic!),
> and a program expressed as a pure function can access such devices
> and therefore behave non-deterministically.  Perhaps you would argue
> that this is only apparent nondeterminism, and that if we could just
> know reset the state of the system more accurately then the nondeterminism
> would vanish.  At this point we would then most likely digress into arguments
> about quantum mechanics...)

Actually I would treat non-deterministic (in the physicist sense) hardware as
outside the system. Of course I would then have to observe and take account
of the events which this hardware generated. From a point of view of
experimental repeatability this presents a problem. So in I would probably
have to replace the actual hardware with some determinisic simulation. I think
you might say I was cheating.
 
> > The issue which concerns me is:
> > 
> >  'Can systems with tolerable behaviour be described, reasoned about and
> >   implemented within the same language?'.
> > 
> > I suppose the answer is yes (people must have been working on this problem
> > for years), but not (yet) if you're a Haskell or Clean user. (And not ever
> > if they remain purely functional ????)
> 
> I think the answer is yes, even if you're a Haskell or Clean user.
> Why do you think otherwise?

Because I can't express non-deterministic programs in Haskell or Clean. I can
build deterministic components of non-deterministic systems in Haskell or
Clean, but I will always need outside 'black box' help to complete the system.
What I want to do is describe my entire system in 1 language. 

I should add that we have the same problem in every language I know, this
isn't just an issue for functional languages. It's just as important for C etc.
But C programmers live chaotic and uncertain lives anyway, this probably
doesn't seem like a major problem to them.

Now of course, the question arises what do I mean by 'entire system'. To
properly answer this question perhaps we really need a define 'virtual machine'
to which all programs are notionally targeted. I'm not sure quite what this
machine should be capable of doing. You could argue that this is just another
piece of 'black box' outside help, indeed it is. But if it's accurately
defined, it will be less black than most.
(and before anybody asks, yes I am aware of Java:-)

So when I say that I don't think _purely_ functional languages are viable in
the long term, I'm not advocating a return to imperative languages. I think
there's something missing from _all_ programming languages (of which I am
aware). I could say a lot more about this, but I won't at this moment. All
I will say is that I do not believe that the missing "something" can be
expressed as a pure function.

Regards
- 
Adrian Hey