Since there are many useful per-line functions, do a little refactoring, placing the following into a library:<br><br> perLine :: (String -> String) -> (String -> String)<br> perLine f = unlines . map f . lines<br>
<br><br><div class="gmail_quote">On Dec 12, 2007 12:43 PM, apfelmus <<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>> 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>> (Plus, interact is scary. :-D )<br><br></div>You have a scary feeling for a moment, then it passes. ;)<br><div class="Ih2E3d"><br>> Gwern Branwen wrote:<br>>> I... I want to provide a one-liner for 'detab', but it looks
<br>>> impressively monstrous and I'm not sure I understand it.<br>><br></div><div class="Ih2E3d">> On the other hand, I'm not looking for one-liners; I really want clarity<br>> as opposed to cleverness.
<br><br></div> tabwidth = 4<br><br> -- tabstop !! (col-1) == there is a tabstop at column col<br> -- This is an infinite list, so no need to limit the line width<br> tabstops = map (\col -> col `mod` tabwidth == 1) [1..]
<br><br> -- calculate spaces needed to fill to the next tabstop in advance<br> tabspaces = snd $ mapAccumR addspace [] tabstops<br> addspace cs isstop = let cs'=' ':cs in (if isstop then [] else cs',cs')
<br><br><br> main = interact $ unlines . map detabLine . lines<br> where<br> detabLine = concat $ zipWith replace tabspaces<br> replace cs '\t' = cs -- replace with adequate number of spaces<br>
replace _ 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>