Ocaml bonsai: let%sub vs match%sub

The match%sub construct works by constructing the computation for all the branches, and then later just switching between which one is actually active. In other words, Bonsai traverses all paths through a computation up front. If you naively construct the form for a recursive type, then Bonsai will attempt to build an infinitely large computation, since the recursive type has infinite potential size. Bonsai.lazy_ is the way you can delay constructing a computation until it is absolutely necessary. Thus, Bonsai will still attempt to traverse an infinite number of paths, but it will only actually reach those paths that actually end up being necessary.

1 Like