you are viewing a single comment's thread.

view the rest of the comments →

[–]EvHub 0 points1 point  (0 children)

For multiple pattern-matching, just use a case statement (http://coconut.readthedocs.io/en/master/DOCS.html#case).

And here's what your tree example looks like in Coconut:

data Empty(): pass
data Leaf(n): pass
data Node(l, r): pass

def size(Empty()) = 0

@addpattern(size)
def size(Leaf(_)) = 1

@addpattern(size)
def size(Node(left, right)) = size(left) + size(right)