enum Tree {
Nil
Node(name: string)
Cons(left: Tree, right: Tree)
}
// this is now legal
fun walk(
enter: fun(Tree) -> Tree,
leave: fun(Tree) -> Tree,
term: Tree
): Tree = {
val e = enter(term)
leave(match e {
case cons is Cons(left, right) -> {
val newLeft = walk(enter, leave, left)
val newRight = walk(enter, leave, right)
if (newLeft != left || newRight != right) {
Cons(newLeft, newRight)
} else {
cons
}
}
else -> e
})
}
fun identity(x: Tree): Tree = x
Function as argument/values are now accepted.