I realize this sounds like a terrible idea, but I'm dealing with translating some Haskell Parsec Code (and we know how much Haskell loves tail recursion.)
2.Is there a way to define a closure that refers to itself? If so, what's a minimal example? This is something of the form:
l.et x = |...| {
we have to call some other function (passing it x);
}
Is this possible? safe? Something intuitively seems wrong, but I can't figure out what.
@DanielKeep this creates a cycle thus leaking memory, right? Using a rc::Weak to make the recursive call should solve the issue (i.e., let self_ = Rc::downgrade(&self_) + (self_.try_upgrade().unwrap().borrow())(n + 1)).
Since Fn desugaring is unstable, I'd advise to use the exact same code that you would for that, but to replace afterwards impl Fn for ... by an inherent impl impl .... Then, instead of writing f() you would (just) have to write f.call(), which is not that big of a price to pay for stable-compatible code.