<div dir="ltr">Hi Kurt,<br>
<br>
thank you for the detailed explanation. Indeed, I could follow your explanation on first reading :-)<br>
<br>
Dirk<br><br><div class="gmail_quote">2008/7/21 Kurt Hutchinson &lt;<a href="mailto:kelanslists@gmail.com">kelanslists@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Mon, Jul 21, 2008 at 9:34 AM, Dirk Markert &lt;<a href="mailto:dirk.markert@gmail.com">dirk.markert@gmail.com</a>&gt; wrote:<br>
&gt; I am trying to generate the following list:<br>
&gt; 2, 3, 5 -- and then alternating (+2) resp (+4) -- 7, 11, 13, 17, 19, 23<br>
&gt;<br>
&gt; I came up with the following solution<br>
&gt; 2:3:unfoldr (\(a,b) -&gt; Just (a,(a+b, if b == 2 then 4 else 2))) (5,2)<br>
&gt;<br>
&gt; Are there easier ways to generate the desired list?<br>
<br>
<br>
</div></div>So you&#39;ve got the beginnings of an infinite list, and a rule to modify<br>
that to generate new elements. How about turning that rule into a list<br>
of its own, and then combining them?<br>
<br>
 &nbsp;rule = cycle [ 2, 4 ] &nbsp;-- this will give an infinite list of 2&#39;s and 4&#39;s<br>
<br>
Combining two lists is usually done with &#39;zip&#39;. But in this case, we<br>
don&#39;t just want tuples, we want the sum of each pair. You can combine<br>
lists with a function by using &#39;zipWith&#39;. Start at the point where the<br>
rule kicks in.<br>
<br>
 &nbsp;rest = 5 : zipWith (+) rest rule<br>
<br>
Now just tack on your first elements.<br>
<br>
 &nbsp;list = 2 : 3 : rest<br>
<br>
Here it is all in one place:<br>
<br>
 &nbsp;list = 2 : 3 : rest<br>
 &nbsp; &nbsp;where<br>
 &nbsp; &nbsp;rule = cycle [ 2, 4 ]<br>
 &nbsp; &nbsp;rest = 5 : zipWith (+) rest rule<br>
<font color="#888888"><br>
Kurt<br>
</font></blockquote></div><br></div>