예제 #1
0
        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);
        }
예제 #2
0
        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))));
        }
예제 #3
0
 public static int CoerceInt(this IAtomNode n)
 {
     return(n.TryEvaluate((Exception e) => { throw e; }).FromJust);
 }
예제 #4
0
 public override Maybe <int> TryEvaluate(TAction <Exception> handler)
 {
     return(interior.TryEvaluate(handler).Fmap((int x) => - x));
 }