shaunlaurens edited this page Mar 25, 2012 · 27 revisions

About the Language

Netrium is a Haskell based Domain Specific Language.

Language Core Con­cepts

Note: Images on this page and others are in the Scalable Vector Graphic and Portable Network Graphics formats.

Fundamentally, almost everything in Netrium is a contract. The simplest way to under­stand the lan­guage is to look at a the most basic of contracts - the receipt of 1 GBP at the moment of contract acquisition:

  contract = One (Financial gbp cash Nothing)

This example is broken down into the fol­low­ing elements:

Item Meaning
contract this iden­ti­fies this block of code as the contract.
One this means that at the time of acquis­i­tion of the con­tract, the acquirer receives One of some­thing. One is part of the core com­bin­ator lib­rary built into Netrium.
Financial this means that the some­thing is Financial (as opposed to Physical)
gbp this fur­ther defines the Fin­an­cial as being held in the cur­rency of GBP (see Static Data for more information on this).
cash this fur­ther defines the Fin­an­cial as rep­res­ent­ing a cash­flow type of ‘cash’ (see Static Data for more information on this).
Nothing this sets the Portfolio to nothing (Nothing as defined in Haskell's Maybe datatype) as for this sample, it is not relevant. If you're curious, Portfolio is defined as ```haskell Maybe Portfolio ``` meaning that if you'd like to supply a value you would need to apply Just, as in: ```haskell contract = One (Financial gbp cash (Just (Portfolio "cash"))) ```

Compiled Source

Once run through the Netrium compiler, the system outputs an XML representation of the contract, known as the Intermediate Contract Language. This is the pretty-printed output of the Netrium Compiler for the above contract:

<?xml version="1.0"?>

This executable representation can then be run through the visualisation process, which provide two important views on the contract:

Syntax Tree

The Syntax Tree shows the structure of the contract, and can be invaluable in understanding path-dependant contracts. For the above simple example, the tree is:

Syntax Tree

Decision Tree

The Decision Tree shows the operational semantics of the contract. For the above sample, when setting acquisition time to 00:00:00 on 1/1/2011 is:

Decision Tree

Language Elements

Before tak­ing you through some more examples of how con­tracts are con­struc­ted in Net­rium, it is use­ful to under­stand the core lan­guage com­bin­at­ors avail­able for use to the structurer:

Ele­ment Usage
Zero Rep­res­ents a ‘zero’ con­tract — it holds no value.
One Rep­res­ents a single ‘some­thing’ — where some­thing is either Fin­an­cial or Physical.
And Com­bines two con­tracts into a new con­tract. Both chil­dren are acquired simultaneously.
Give Inverts the dir­ec­tion of flow from Receive to Give.
Or Allows a user to make a named decision; used mostly around options.
Cond Allows the con­tract to make a decision based on an external observ­able.
Scale Mul­ti­plies the child con­tract (nor­mally a ‘One’, but can be a set of nes­ted of ‘Scales’). .
Read Accesses named vari­ables. Vari­ables can undergo con­trolled determ­in­istic muta­tion through the math­em­at­ical lan­guage avail­able to Net­rium developers.
When All ele­ments beneath a when will ‘wait’ until the asso­ci­ated time.
Anytime The chil­dren are instantly activ­ated the moment the con­di­tion in the Any­time becomes true.
Until The chil­dren are instantly des­troyed the moment the con­di­tion in the Until becomes true.
AllOf This com­bines a list of con­tracts into an And tree.
Financial This allows us to model a Fin­an­cial contract.
Physical This allows us to model a Phys­ical contract.


Increasing the Complexity

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.