Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!lotus!esegue!compilers-sender From: augustss@cs.chalmers.se (Lennart Augustsson) Newsgroups: comp.compilers Subject: Re: Graph reduction, recursion, and the Y combinator Message-ID: <1989Sep29.013305.4143@esegue.segue.boston.ma.us> Date: 29 Sep 89 01:33:05 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: Lennart AugustssonOrganization: Chalmers University of Technology Lines: 34 Approved: compilers@esegue.segue.boston.ma.us In-Reply-To: <1989Sep26.041357.26728@esegue.segue.boston.ma.us> worley@compass.com (Dale R. Worley) says > ... In theoretically pure lambda calculus, > recursion is expressed using the Y combinator, or some such, which can > be represented in terms of the simpler combinators. Has anyone > actually done this in graph reduction execution? Yes, I'm sure many have tried this. I know I have. > Has anyone analyzed the optimization which removes the Y and replaces > it with the circular edge? I haven't seen anything formal on this, but not using the "knot-tying" version of Y gives you horrible space leaks. Any recursion will unfold the definition of a function as deep as the recursion has ever been in that function. Most of the time it is not possible to garbage collect the unfolded part of the graph unless you use a very clever collector. As far as I know there is *no* reason to use the unfolding version except if you want to avoid cycles in the graph. > Is this a special case of a more general optimization? Yes and no. Y handles everything you write in a correct way (I've no formal proof of this, but I believe it to be true), but for each recursive definition you can tailor a special combinator that does it in a more efficient may. Check in "The Implementation of Functional Programming Languages" by Simon Peyton Jones (Prentice Hall, ISBN 0-13-453333-X or 0-13-453325-9) for suitable ways to do all this. This book is a *must* for anyone interested in implementation of lazy functional languages. -- Lennart Augustsson -- Send compilers articles to compilers@esegue.segue.boston.ma.us {spdcc | ima | lotus}!esegue. Meta-mail to compilers-request@esegue. Please send responses to the author of the message, not the poster.