OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Markup Combinators -- A Functional Approach to XML

Hi Folks,

July 30, 2011 we had an excellent discussion on markup combinators. [1]

During that discussion Frank Manola challenged me to provide a good example of approaching XML via markup combinators. I now accept the challenge.

The following example is inspired by “How to write a financial contract” by Simon Peyton Jones. [2] Many of the below words come from that paper.

Example: Use Markup Combinators to Create Financial Contracts

The finance industry has an enormous vocabulary of jargon for typical combinations of financial contracts (swaps, futures, caps, floors, swaptions, spreads, straddles, captions, European options, American options, ..., the list goes on.) Treating these individually is like having a large catalog of prefabricated components. The trouble is that someone will soon want a contract that is not in the catalog.

If, instead, we could define each of these contracts using a fixed, precisely specified set of combinators, we would be in a much better position than having a fixed catalog. For a start, it becomes much easier to describe new, unforeseen, contracts. Beyond that, we can systematically analyze, manipulate, and perform computations over these new contracts, because they are described in terms of a fixed, well-understood set of primitives.

Let us begin with defining some simple combinators and then use them to create more complex combinators.

Here is a simple financial contract, it pays one USD at the time of acquisition


The recipient receives one USD.

one” is a combinator. It is a contract.

For our next contract the recipient again acquires the value immediately, except all the payments are multiplied by (scaled up) 100 times


The contract pays 100 USD.

scale” is a combinator. It is a contract.

To re-emphasize, this new contract was created by assembling a double with another contract.

The recipients of the previous two contracts received the value immediately. We can create a contract that is worthless until a Boolean condition becomes true. Let’s create this contract

When at January 1, 2012, acquire one USD

Here’s the contract


The “when” combinator consists of a Boolean observable and contract. Here are a couple examples to illustrate what a Boolean observable is:

Hey, I observe that the date is (not) now 2011-12016.

Hey, I observe that the temperature is (not) now 5
degrees Celsius.

at” is a Boolean observable that becomes true at time t.

Now let’s create a contract that is known in the industry as a zero-coupon discount bond (zcb). Let’s create this zcb contract

Receive 100 USD on January 1, 2012.

This is easily created by assembling the above combinators.

A zcb contract is created by assembling a date, double, and currency. The below XML creates the desired zcb contract. Read the XML as follows

This contract pays off when at January 1, 2012, an amount equally
the scaling 100x of one USD.

Here is the XML


Why did we go to the trouble of defining zcb in terms of multiple combinators rather than making it primitive? Because it turns out that scale, when, and one are all independently useful. Each embodies a distinct piece of functionality, and by separating them we significantly simplify the semantics and enrich the algebra of contracts.

Recap: the above discussion illustrates how to approach XML in a functional manner; that is, how to create XML by assembling markup combinators. This is beautiful markup. This functional approach to XML is consistent with XSLT and NVDL.


[1] http://lists.xml.org/archives/xml-dev/201107/msg00116.html

[2] http://research.microsoft.com/en-us/um/people/simonpj/papers/financial-contracts/contracts-icfp.htm


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS