<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Ryan,<br><br>I'm afraid you've lost me. Maybe if you showed how this would be used in ML I would get the picture.<br><br>Michael<br><br>--- On <b>Tue, 5/19/09, Ryan Ingram <i>&lt;ryani.spam@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ryan Ingram &lt;ryani.spam@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] showing a user defined type<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: "Brandon S. Allbery KF8NH" &lt;allbery@ece.cmu.edu&gt;, haskell-cafe@haskell.org<br>Date: Tuesday, May 19, 2009, 2:40 PM<br><br><div class="plainMail">On Tue, May 19, 2009 at 7:07 AM, michael rice &lt;<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt; wrote:<br>&gt; A little further along in "The Little MLer" the ints function is
 replaced by<br>&gt; other functions like primes and fibs, which also return Links:<br>&gt;<br>&gt; fun primes(n)<br>&gt; &nbsp; = if is_prime(n+1)<br>&gt; &nbsp;then Link(n+1,primes)<br>&gt; &nbsp;else primes(n+1)<br>&gt;<br>&gt; fun fibs(n)(m)<br>&gt; &nbsp; = Link(n+m,fibs(m))<br>&gt;<br>&gt; which are passed to chain_item:<br>&gt;<br>&gt; fun chain_item(n,Link(i,f))<br>&gt; &nbsp; = if eq_int(n,1)<br>&gt; &nbsp; then i<br>&gt; &nbsp; else chain_item(n-1,f(i))<br>&gt;<br>&gt; which can be called to request the nth (12th) prime number beginning at 1.<br>&gt;<br>&gt; - chain_item(12,primes(1));<br>&gt; GC #0.0.0.1.3.61:&nbsp;&nbsp; (1 ms)<br>&gt; val it = 37 : int<br>&gt; -<br>&gt;<br>&gt; So I guess the answer to your question about whether the function is ever<br>&gt; called with a different value may be, yes.<br><br>Actually, it's not calling it with another value; notice that<br>chain_item calls f(i), with i coming directly from the
 chain.<br>Consider this alternate definition:<br>(I'm not sure the syntax is exactly right, but you get the idea)<br><br>datatype chain =<br>&nbsp; Link of (int * ( unit -&gt; chain ))<br><br>fun intsFrom(n) = fun unit =&gt; (n, intsFrom (n+1))<br>fun ints(n) = intsFrom n ()<br><br>Now you *can't* call the function embedded in the link with another value.<br><br>fun chain_item(n,Link(i,f))<br>&nbsp; = if eq_int(n,1)<br>&nbsp; then i<br>&nbsp; else chain_item(n-1,f unit)<br><br>And this type for "chain" is almost the same as [Int] in Haskell, due<br>to laziness.<br><br>&nbsp; -- ryan<br></div></blockquote></td></tr></table><br>