Lovely!<br><br>Perhaps a stylistic shift would encourage writing this sort of elegant, fusion-friendly code.<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; -- Generalized version of &quot;interact&quot;.&nbsp; Encapsulates data getter &amp; putter.
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; genInteract :: IO i -&gt; (o -&gt; IO ()) -&gt; ((i -&gt; o) -&gt; IO ())</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; genInteract get put = \ f -&gt; get &gt;&gt;= put . f</span><br style="font-family: courier new,monospace;"><br>The intention here is that i and o are pure value types (no IO).&nbsp; Solutions 2 and three use the following specialization.
<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; -- Lazy ByteString in and showable out</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp; lGetPrint :: Show o =&gt; (L.ByteString -&gt; o) -&gt; IO ()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; lGetPrint = genInteract L.getContents print</span>

<br><br>Then rewrite solution 2 as follows:<br><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; main = lGetPrint f
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f contents = foldl&#39; (test k) 0 . map int . take n $ ls
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (l:ls) = L.lines contents</span><span class="q"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [n,k]&nbsp; = map int (L.split &#39; &#39; l)</span><br><br>
</span>And solution 3 similarly.
<br><br>Plug: for additional examples and a more general approach to separating out IO, my blog post &quot;<a href="http://conal-elliott.blogspot.com/2007/02/separating-io-from-logic-example.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
separating IO from logic -- example
</a>&quot;, which uses the <a href="http://www.haskell.org/haskellwiki/TV" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">TV</a> library.<br>