Recursive Data Structures with Bend
mainThe bend keyword creates recursive data structures by binding a variable to the return of an inline recursive function.
Inside the when arm, the fork function is available to call the function recursively. fork must receive the same number of arguments as the number of state variables defined in the bend statement.
main =
bend x = 0 {
when (< x 3):
(Tree/Node (fork (+ x 1)) (fork (+ x 1)))
else:
(Tree/Leaf x)
}You can initialize multiple state variables:
bend x = 0, y = 1 ... {
when (condition x y ...):
...
}main =
bend x = 0 {
when (< x 3):
(Tree/Node (fork (+ x 1)) (fork (+ x 1)))
else:
(Tree/Leaf x)
}