Lambda extends Expression { @Override public String toString() { StringBuilder out = new StringBuilder(); out.append("(\\"); for (Binder x : this.binders) { out.append(" ").append(x.getBaseName()); } if (this.binders.isEmpty()) { out.append("_"); } out.append(" -> "); out.append(this.body.toString()); out.append(")"); if (this.binders.isEmpty()) { out.append(" ()"); } return out.toString(); } Lambda(List<Binder> binders, Expression body); @Override Type inferType(); @Override String toHaskell(); @Override String toString(); @Override List<Expression> getChildren();  }
@Test public void testLambdaWrapping() throws HaskellException { Environment env = new HaskellCatalog().asEnvironment(); Binder x = new Binder("x"); Binder y = new Binder("y"); Expression pxy = new Apply (new Apply(env.useFun("(+)"), new LocalVar(x)), new LocalVar(y)); Expression add = new Lambda(Arrays.asList(x,y), pxy); assertEquals("(\\ x y -> (((+) x) y))", add.toString()); Binder z = new Binder("z"); Expression ezz = new Apply (new Apply(env.useFun("(^)"), new LocalVar(z)), new LocalVar(z)); Expression exp = new Lambda(Arrays.asList(z), ezz); assertEquals("(\\ z -> (((^) z) z))", exp.toString()); Binder u = new Binder("u"); Expression f5 = new Value(Type.con("Float"), "5.0"); Expression l5 = new Lambda(Arrays.asList(u), f5); assertEquals("(\\ u -> 5.0)", l5.toString()); Expression emptyLambda = new Lambda(Collections.emptyList(), new Value(Type.con("Float"), "pi")); assertEquals("(\\_ -> pi) ()", emptyLambda.toString()); }