[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Markup Combinators -- A Functional Approach to XML

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Fri, 16 Dec 2011 18:59:25 +0000

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

<one>USD</one>

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

<scale><konst>100</konst><one>USD</one></scale>

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

<when>
     
<at>2012-01-02</at>
     
<one>USD</one>
</when>

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

<zcb>
   
<when><at>2012-01-02</at></when>
   
<scale><konst>100</konst><one>USD</one></scale>
</zcb>

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.

/Roger

[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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.