<div dir="ltr"><div class="im" style="font-family:arial,sans-serif;font-size:13px">On Sat, Jul 20, 2013 at 4:16 AM, Norman Gray <span dir="ltr"><<a href="mailto:norman@astro.gla.ac.uk" target="_blank">norman@astro.gla.ac.uk</a>></span> wrote:<br>
</div><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:13px"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>Can anyone illustrate how that solution would work in Ben's example here?<br></blockquote><div><br></div></div><div>The basic gist of it is that instead of manipulating "the-data", we manipulate</div><div>
functions. So the inner functions f2, f3, ... will change from this:</div><div><br></div><div><div><font face="courier new, monospace">(define (f2 the-data arg arg …)</font></div><div><font face="courier new, monospace"> …</font></div>
<div><font face="courier new, monospace"> (f3 the-data x y …)</font><span style="font-family:'courier new',monospace">)</span></div></div><br>to this:</div><div class="gmail_quote"><br></div><div class="gmail_quote">
<div><font face="courier new, monospace">(define (f2 arg arg …)</font></div><div><font face="courier new, monospace"> (lambda (the-data)</font></div><div><font face="courier new, monospace"> …</font></div><div><font face="courier new, monospace"> ((f3 x y …) the-data</font><span style="font-family:'courier new',monospace">)))</span></div>
<div><span style="font-family:'courier new',monospace"><br></span></div><div>We just move<font face="courier new, monospace"> the-data </font>to the end of the argument list and curry the functions.</div><div>That makes things more complicated at first, but the inner functions that don't</div>
<div>actually use <span style="font-family:'courier new',monospace">the-data </span>can be eta-reduced. (lambda (x) (f x)) => f</div><div>So <span style="font-family:'courier new',monospace">f2 </span>eta-reduces to:</div>
<div><div><font face="courier new, monospace">(define (f2 arg arg …)</font></div><div><font face="courier new, monospace"> …</font></div><div><font face="courier new, monospace"> (f3 x y …</font><span style="font-family:'courier new',monospace">))</span></div>
</div><div> and all mentions of <span style="font-family:'courier new',monospace">the-data </span>disappear in the inner functions (pretty slick!)</div><div>The innermost fx can't be reduced this way, of course, and the callers of f0</div>
<div>have to change to pass the initial value of <font face="courier new, monospace">the-data</font>.</div><div><br></div><div>I just did this with an ad-hoc code transformation. A "monad" formalizes this.</div>
<div>(and I skipped over a<i> lot </i>of detail.)</div></div></div><div class="gmail_extra"><div><br></div>-- <br>~jrm
</div></div>