Skip to content

Instantly share code, notes, and snippets.

@ybonnel
Created March 27, 2013 10:16
Show Gist options
  • Select an option

  • Save ybonnel/5253192 to your computer and use it in GitHub Desktop.

Select an option

Save ybonnel/5253192 to your computer and use it in GitHub Desktop.
Compilation error in ceylon
abstract class Tree() {
shared formal Integer evaluate();
}
class UnaryOperator(Tree branch, Integer f(Integer t)) extends Tree() {
evaluate() => f(branch.evaluate());
}
class Constant(Integer constantValue) extends Tree() {
evaluate() => constantValue;
}
class BinaryOperator(Tree left, Tree right, Integer f(Integer left, Integer right)) extends Tree() {
evaluate() => f(left.evaluate(), right.evaluate());
}
class Plus(Tree left, Tree right) extends BinaryOperator(left, right, function(Integer left, Integer right) => left+right) {
}
void testIt() {
value minus = function(Integer a) => -a;
Tree t = UnaryOperator(Constant(2), minus);
print(t.evaluate());
Tree t2 = BinaryOperator(Constant(2), Constant(4), function(Integer left, Integer right) => left*right);
print(t2.evaluate());
// Work
Tree t3 = Plus(Constant(2), Constant(3));
print(t3.evaluate());
// Doesn't work
value t4 = Plus(Constant(2), Constant(3));
print(t4.evaluate());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment