I should have included an example. My first instinct, coming from Standard ML, was the following:
(define tree LE -> (@v LE [] <>))
(define find (@v LE T <>) X -> (let loop
(/. (@v Y [L | R]) ->
(cases (and (LE X Y) (LE Y X)) Y
(LE X Y) (loop L)
(LE Y X) (loop R))
[] -> (simple-error "not found"))
(loop T)))
I recognize that we can't actually pattern match in lambdas, and that can be worked around with cases, and I could probably have made the cases that are there side conditions if I'm assuming uniform pattern matching, but the problem is loop can't reference itself and close over LE and X at the same time. Either I hoist loop to the top level to make it recursive, or I close over LE and X, but not both. Is that an intentional limitation? No recursive closures?