public static IAtomNode Simplify(this IAtomNode n, TAction <Exception> handler) { IAtomNode ret = n; n.TryEvaluate(handler).IfJust((int i) => { ret = FromInt(n.MyLocation, i); }); return(ret); }
public override Maybe <int> TryEvaluate(TAction <Exception> handler) { Maybe <int> l = left.TryEvaluate(handler); l.IfJust((int i) => { this.left = new NumberNode(left.MyLocation, i); }); Maybe <int> r = right.TryEvaluate(handler); r.IfJust((int i) => { this.right = new NumberNode(right.MyLocation, i); }); return(l.Bind((int newL) => r.Fmap((int newR) => Operators[op.Type](newL, newR)))); }
public static int CoerceInt(this IAtomNode n) { return(n.TryEvaluate((Exception e) => { throw e; }).FromJust); }
public override Maybe <int> TryEvaluate(TAction <Exception> handler) { return(interior.TryEvaluate(handler).Fmap((int x) => - x)); }