Language - netrium/Netrium GitHub Wiki
Netrium is a Haskell based Domain Specific Language.
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 understand the language 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 following elements:
Item | Meaning |
---|---|
contract | this identifies this block of code as the contract. |
One | this means that at the time of acquisition of the contract, the acquirer receives One of something. One is part of the core combinator library built into Netrium. |
Financial | this means that the something is Financial (as opposed to Physical) |
gbp | this further defines the Financial as being held in the currency of GBP (see Static Data for more information on this). |
cash | this further defines the Financial as representing a cashflow 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"))) ``` |
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"?>
<One>
<Financial>
<Currency>gbp</Currency>
<CashFlowType>cash</CashFlowType>
</Financial>
</One>
This executable representation can then be run through the visualisation process, which provide two important views on the contract:
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:
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:
Before taking you through some more examples of how contracts are constructed in Netrium, it is useful to understand the core language combinators available for use to the structurer:
Element | Usage |
---|---|
Zero | Represents a ‘zero’ contract — it holds no value. |
One | Represents a single ‘something’ — where something is either Financial or Physical. |
And | Combines two contracts into a new contract. Both children are acquired simultaneously. |
Give | Inverts the direction of flow from Receive to Give. |
Or | Allows a user to make a named decision; used mostly around options. |
Cond | Allows the contract to make a decision based on an external observable. |
Scale | Multiplies the child contract (normally a ‘One’, but can be a set of nested of ‘Scales’). . |
Read | Accesses named variables. Variables can undergo controlled deterministic mutation through the mathematical language available to Netrium developers. |
When | All elements beneath a when will ‘wait’ until the associated time. |
Anytime | The children are instantly activated the moment the condition in the Anytime becomes true. |
Until | The children are instantly destroyed the moment the condition in the Until becomes true. |
AllOf | This combines a list of contracts into an And tree. |
Financial | This allows us to model a Financial contract. |
Physical | This allows us to model a Physical contract. |