Contract Programming
This was originally posted as the first entry in my then private research blog on Feb 5, 2006. Reposted here today because (a) I somehow didn’t manage to transfer it when I switched to Wordpress, and more importantly (b) I’m getting extremely interested in this again. I’m looking now at doing this without continuations, instead using discrete reusable contract chunks as contract “clauses,” and keeping reference to which clause is current.
In the PLW today we spent some time discussing directions for further research and development of Openstudio. Many interesting ideas came up, some new and some recurrences from past discussions. A recurring theme was that of the economy, especially the lack of incentives for users to participate in the economy. How can we make the economy more fluid? How can we find its equilibrium? How do we make buying and selling more interesting? How do we explore and add more sophisticated transactions?
Many of the UROP projects have involved extensions to the currently simple economic model. Kate, for instance, is working on her “Hire a Designer” contract/commissioning system, in which one member of OS can hire another for a particular project. Other UROPs are developing stock markets and virtual cafes and new types of aggregate documents. Each of these projects adds further expressiveness and sophistication to the current economic system.
Perhaps inspired by my recent participation in an economics course at the Harvard Business School, I wonder if we can somehow formalize and abstract these various sorts of transactions and contracts. Specifically, I am thinking of a sort of programming language or library for describing and executing contracts. Hopefully the following very rough pseudo-code will convey the idea:
def my_contract(client, designer, document, instructions, fee)
unless commit(client, designer, self)
return # both parties did not commit to this
end
account_transfer :from => client.account,
:to => self.escrow,
:amount => fee
designer_chances = 3
while designer_chances > 0
send :to => designer,
:attachment => document,
:content => instructions
deliverables = nil
while deliverables.nil?
if time.now > deadline
return # didn't meet the deadline
end
deliverables = receive_deliverables(designer)
end
if not verify(client, deliverables)
designer_chances -= 1
end
end
send :to => client,
:attachment => deliverables
account_transfer :from => self.escrow,
:to => designer.account,
:amount => fee
end
Is this interesting? Doable? Reminds me a bit of the sort of pseudo-code used to explain the Amazon mechanical turk.

