You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In functional languages like rescript, recursion is an important mode of control flow, on par with (or even more important than) loops. For that reason, some languages (like Scheme) have syntactic sugar for creating and immediately calling a recursive function. This reduces the need for complicated (and less flexible) loop syntax.
Motivating example:
typerectree<'t> =Leaf('t) | Branch(promise<tree<'t>>, promise<tree<'t>>)
letdelay= (ms, x) =>Promise.make((resolve, _reject) =>setTimeout(
() =>resolve(x),
ms
)->ignore)
letmyTree=Branch(
delay(100, Branch(
delay(100, Leaf(1)),
delay(100, Leaf(2))
)),
delay(100, Leaf(3))
)
// Current syntax: declare and use a helper functionletrecflatten=asynctree=>switchtree {
| Leaf(x) => [x]
| Branch(x, y) =>Array.concat(awaitflatten(awaitx), awaitflatten(awaity))
}
letmyFlatTree=awaitflatten(myTree)
// Proposed syntax: anonymous recursive function with initial parametersletmyFlatTree=asyncrecflatten (tree=myTree) =>switchtree {
| Leaf(x) => [x]
| Branch(x, y) =>Array.concat(awaitflatten(awaitx), awaitflatten(awaity))
}
The text was updated successfully, but these errors were encountered:
In functional languages like rescript, recursion is an important mode of control flow, on par with (or even more important than) loops. For that reason, some languages (like Scheme) have syntactic sugar for creating and immediately calling a recursive function. This reduces the need for complicated (and less flexible) loop syntax.
Motivating example:
The text was updated successfully, but these errors were encountered: