To me even more concise and readable is the imperative solution the article also mentions: just refer to a &quot;global&quot; counter and increment it (it doesn&#x27;t have to actually be global, for that matter, just scoped around the tree-building code). The article doesn&#x27;t even really argue against that solution. Instead the goal here seems to be more of an intellectual challenge problem: find a functional solution that, unlike the straightforward functional solution (thread state through every function call), is not that much clunkier than the imperative solution.