Since I realized my code was always using infinite lists, I replaced it by Data.Stream.<div><br></div><div>However, my code stopped working.</div><div><br></div><div>The problem is with these functions:</div><div><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; font-size: 16px; "><pre>
<span class="definition">scan</span> <span class="keyglyph" style="color: red; ">::</span> <span class="layout" style="color: red; ">(</span><span class="varid">a</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">b</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">a</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">a</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="conid">Stream</span> <span class="varid">b</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="conid">Stream</span> <span class="varid">a</span>
<a name="line-173"></a><span class="definition">scan</span> <span class="varid">f</span> <span class="varid">z</span> <span class="layout" style="color: red; ">(</span><span class="conid">Cons</span> <span class="varid">x</span> <span class="varid">xs</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">=</span>  <span class="varid">z</span> <span class="varop">&lt;:&gt;</span> <span class="varid">scan</span> <span class="varid">f</span> <span class="layout" style="color: red; ">(</span><span class="varid">f</span> <span class="varid">z</span> <span class="varid">x</span><span class="layout" style="color: red; ">)</span> <span class="varid">xs</span>
<a name="line-174"></a>
<a name="line-175"></a><a name="scan&#39;"></a><span class="comment" style="color: green; ">-- | @scan&#39;@ is a strict scan.</span>
<a name="line-176"></a><span class="definition">scan&#39;</span> <span class="keyglyph" style="color: red; ">::</span> <span class="layout" style="color: red; ">(</span><span class="varid">a</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">b</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">a</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="varid">a</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="conid">Stream</span> <span class="varid">b</span> <span class="keyglyph" style="color: red; ">-&gt;</span> <span class="conid">Stream</span> <span class="varid">a</span>
<a name="line-177"></a><span class="definition">scan&#39;</span> <span class="varid">f</span> <span class="varid">z</span> <span class="layout" style="color: red; ">(</span><span class="conid">Cons</span> <span class="varid">x</span> <span class="varid">xs</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">=</span>  <span class="varid">z</span> <span class="varop">&lt;:&gt;</span> <span class="layout" style="color: red; ">(</span><span class="varid">scan&#39;</span> <span class="varid">f</span> <span class="varop">$!</span> <span class="layout" style="color: red; ">(</span><span class="varid">f</span> <span class="varid">z</span> <span class="varid">x</span><span class="layout" style="color: red; ">)</span><span class="layout" style="color: red; ">)</span> <span class="varid">xs</span></pre>
<pre><span class="Apple-style-span" style="font-family: arial; font-size: 13px; white-space: normal; "><div>They are too strict I think. My code works again when I add a lazy pattern match:</div><div><br></div><div><span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 16px; white-space: pre; "><span class="definition">scan</span> <span class="varid">f</span> <span class="varid">z</span> ~<span class="layout" style="color: red; ">(</span><span class="conid">Cons</span> <span class="varid">x</span> <span class="varid">xs</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">=</span>  <span class="varid">z</span> <span class="varop">&lt;:&gt;</span> <span class="varid">scan</span> <span class="varid">f</span> <span class="layout" style="color: red; ">(</span><span class="varid">f</span> <span class="varid">z</span> <span class="varid">x</span><span class="layout" style="color: red; ">)</span> <span class="varid">xs</span></span><br>
</div><div><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; font-size: 16px; "><pre><a name="line-174"></a><span class="definition">scan&#39;</span> <span class="varid">f</span> <span class="varid">z</span> ~<span class="layout" style="color: red; ">(</span><span class="conid">Cons</span> <span class="varid">x</span> <span class="varid">xs</span><span class="layout" style="color: red; ">)</span> <span class="keyglyph" style="color: red; ">=</span>  <span class="varid">z</span> <span class="varop">&lt;:&gt;</span> <span class="layout" style="color: red; ">(</span><span class="varid">scan&#39;</span> <span class="varid">f</span> <span class="varop">$!</span> <span class="layout" style="color: red; ">(</span><span class="varid">f</span> <span class="varid">z</span> <span class="varid">x</span><span class="layout" style="color: red; ">)</span><span class="layout" style="color: red; ">)</span> <span class="varid">xs</span></pre>
<pre><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; white-space: normal; "><pre><span class="Apple-style-span" style="font-family: arial; font-size: 13px; white-space: normal; "><div>This is justified since they then behave like scanl on lists. However it seems this package is used a lot, so maybe some code depends on this strictness.</div>
<div><br></div><div>What to do?<br></div><div><br></div><div>PS: Why does scanl&#39; not exist in Data.List?</div><div><br></div></span></pre></span></pre><pre><br></pre></span></div></span></pre></span><div><br></div></div>