Since there are many useful per-line functions, do a little refactoring, placing the following into a library:<br><br>&nbsp; perLine :: (String -&gt; String) -&gt; (String -&gt; String)<br>&nbsp; perLine f = unlines . map f . lines<br>
<br><br><div class="gmail_quote">On Dec 12, 2007 12:43 PM, apfelmus &lt;<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Tommy M McGuire wrote:<br>&gt; (Plus, interact is scary. :-D )<br><br></div>You have a scary feeling for a moment, then it passes. ;)<br><div class="Ih2E3d"><br>&gt; Gwern Branwen wrote:<br>&gt;&gt; I... I want to provide a one-liner for &#39;detab&#39;, but it looks
<br>&gt;&gt; impressively monstrous and I&#39;m not sure I understand it.<br>&gt;<br></div><div class="Ih2E3d">&gt; On the other hand, I&#39;m not looking for one-liners; I really want clarity<br>&gt; as opposed to cleverness.
<br><br></div> &nbsp; tabwidth = 4<br><br> &nbsp; &nbsp; &nbsp;-- tabstop !! (col-1) == there is a tabstop at column &nbsp;col<br> &nbsp; &nbsp; &nbsp;-- This is an infinite list, so no need to limit the line width<br> &nbsp; tabstops &nbsp;= map (\col -&gt; col `mod` tabwidth == 1) [1..]
<br><br> &nbsp; &nbsp; &nbsp;-- calculate spaces needed to fill to the next tabstop in advance<br> &nbsp; tabspaces = snd $ mapAccumR addspace [] tabstops<br> &nbsp; addspace cs isstop = let cs&#39;=&#39; &#39;:cs in (if isstop then [] else cs&#39;,cs&#39;)
<br><br><br> &nbsp; main = interact $ unlines . map detabLine . lines<br> &nbsp; &nbsp; &nbsp;where<br> &nbsp; &nbsp; &nbsp;detabLine = concat $ zipWith replace tabspaces<br> &nbsp; &nbsp; &nbsp;replace cs &#39;\t&#39; = cs &nbsp; &nbsp; -- replace with adequate number of spaces<br>
 &nbsp; &nbsp; &nbsp;replace _ &nbsp;char = [char] -- pass through<br><br><br>How about that?<br><br><br>Regards,<br><font color="#888888">apfelmus<br></font><div><div></div><div class="Wj3C7c"><br>_______________________________________________
<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe
</a><br></div></div></blockquote></div><br>