Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node(adt.Sum):
- __slots__ = ()
- Inner: adt.Ctor[BinOp, Node, Node]
- Leaf: adt.Ctor[int]
- @match.function
- def eval(self) -> int:
- """Evaluate this node to an int."""
- @Node.eval.when(self=Node.Inner(match.pat.opr, match.pat.left, match.pat.right))
- def _eval_inner(opr, left, right):
- return opr(left.eval(), right.eval())
- @Node.eval.when(self=Node.Leaf(match.pat.value))
- def _eval_leaf(value):
- return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement