From 6f16f07d90eb858799402b00749fc23514edfdcf Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 5 Mar 2019 23:36:37 +0100 Subject: Merge binary operations in AST --- dhall/src/typecheck.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'dhall/src/typecheck.rs') diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index aa8d382..90e5f55 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -163,6 +163,7 @@ pub fn type_with<'i, S>(ctx: &Context<'i, Expr<'i, S, X>>, -> Result, TypeError<'i, S>> where S: Clone + ::std::fmt::Debug + 'i { + use crate::BinOp::*; match *e { Const(c) => axiom(c).map(Const), //.map(Cow::Owned), Var(V(x, n)) => { @@ -265,10 +266,10 @@ pub fn type_with<'i, S>(ctx: &Context<'i, Expr<'i, S, X>>, } } BoolLit(_) => Ok(Builtin(Bool)), - BoolAnd(ref l, ref r) => op2_type(ctx, e, Bool, CantAnd, l, r), - BoolOr(ref l, ref r) => op2_type(ctx, e, Bool, CantOr, l, r), - BoolEQ(ref l, ref r) => op2_type(ctx, e, Bool, CantEQ, l, r), - BoolNE(ref l, ref r) => op2_type(ctx, e, Bool, CantNE, l, r), + BinOp(BoolAnd, ref l, ref r) => op2_type(ctx, e, Bool, CantAnd, l, r), + BinOp(BoolOr, ref l, ref r) => op2_type(ctx, e, Bool, CantOr, l, r), + BinOp(BoolEQ, ref l, ref r) => op2_type(ctx, e, Bool, CantEQ, l, r), + BinOp(BoolNE, ref l, ref r) => op2_type(ctx, e, Bool, CantNE, l, r), BoolIf(ref x, ref y, ref z) => { let tx = normalize(&type_with(ctx, x)?); match tx { @@ -309,12 +310,12 @@ pub fn type_with<'i, S>(ctx: &Context<'i, Expr<'i, S, X>>, Builtin(NaturalIsZero) | Builtin(NaturalEven) | Builtin(NaturalOdd) => Ok(pi("_", Natural, Bool)), - NaturalPlus(ref l, ref r) => op2_type(ctx, e, Natural, CantAdd, l, r), - NaturalTimes(ref l, ref r) => op2_type(ctx, e, Natural, CantMultiply, l, r), + BinOp(NaturalPlus, ref l, ref r) => op2_type(ctx, e, Natural, CantAdd, l, r), + BinOp(NaturalTimes, ref l, ref r) => op2_type(ctx, e, Natural, CantMultiply, l, r), IntegerLit(_) => Ok(Builtin(Integer)), DoubleLit(_) => Ok(Builtin(Double)), TextLit(_) => Ok(Builtin(Text)), - TextAppend(ref l, ref r) => op2_type(ctx, e, Text, CantTextAppend, l, r), + BinOp(TextAppend, ref l, ref r) => op2_type(ctx, e, Text, CantTextAppend, l, r), ListLit(ref t, ref xs) => { let mut iter = xs.iter().enumerate(); let t: Box> = match t { -- cgit v1.2.3