Permalink
Browse files

Added an example describing how to combine 2 or more adt's

  • Loading branch information...
1 parent f795875 commit c1eb6e8442c74c7c4280ebbc6cb589fd8e06eb6c @rehno-lindeque committed Apr 22, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 README.markdown
View
@@ -155,7 +155,19 @@ leveraging `Object.getOwnPropertyNames`.
#### Combining ADT's
```javascript
- TODO
+ mathCons = adt(adt.own.constructors(Math), adt('plus', 'minus', 'mul', 'div')),
+ // or equivalently:
+ // mathCons = adt(adt.own.constructors(Math), 'plus', 'minus', 'mul', 'div'),
+ mathEval = adt(adt.own(Math), adt({
+ plus: function(a,b) { return a + b; },
+ minus: function(a,b) { return a - b; }
+ mul: function(a,b) { return a * b; }
+ div: function(a,b) { return a / b; }
+ })),
+ // or equivalently:
+ // mathEval = adt(adt.own(Math), { ... }),
+ formula = mathCons.pow(mathCons.plus(0.5, 3.9), mathCons.mul(0.1, mathCons.exp(4.3))),
+ result = mathEval(formula);
```
#### Stateful visitors

0 comments on commit c1eb6e8

Please sign in to comment.