views:

58

answers:

1

I was watching this Channel 9 talk and a very interesting statement is made in the around the 60 minutes in.

He said that even with completely pure functions once you introduce threads you can simulate side effects.

The way he outlined this was using C-omega notation, which I'm not familiar with, and this already has the relevant language support to do this.

The problem I have is how do you implement the get and set message handlers without assignments? Surely the handlers would have to change a value so that the thread's internal loop can record a new value?

What am I missing? How would I implement that in LISP, for example, that has no special constructs?

+6  A: 

The problem I have is how do you implement the get and set message handlers without assignments? Surely the handlers would have to change a value so that the thread's internal loop can record a new value?

Yes you are correct. Erik is assuming that each thread has its own message queue. Sending a message with Value(n) clearly changes the state of the message queue. He makes it sound more mysterious than it is: he is simply trading assignments for another form of mutable state. He is taking advantage of the 'precondition' feature of the language to make it syntactically clean.

As he says, you can use conventional IO (he mentions console IO) to do the same thing. Imagine Value(n) writes n to a file and the precondition Value(T t) checks whether the current value of the state is t (in the file). Voilà, mutable state without assignments (but IO is involved now!).

Mau
I found it interesting that Eric never used the words, "mutable" or "immutable" in the video, not even once. He also managed to avoid the word, "encapsulate" when describing functional purity, claiming that you can only be pure or impure, not both. Yes, he does make it more mysterious than it is. Maybe that's because he's an academic.
Robert Harvey