[Haskell-cafe] Re: Software Tools in Haskell
Conal Elliott
conal at conal.net
Wed Dec 12 19:15:38 EST 2007
Since there are many useful per-line functions, do a little refactoring,
placing the following into a library:
perLine :: (String -> String) -> (String -> String)
perLine f = unlines . map f . lines
On Dec 12, 2007 12:43 PM, apfelmus <apfelmus at quantentunnel.de> wrote:
> Tommy M McGuire wrote:
> > (Plus, interact is scary. :-D )
>
> You have a scary feeling for a moment, then it passes. ;)
>
> > Gwern Branwen wrote:
> >> I... I want to provide a one-liner for 'detab', but it looks
> >> impressively monstrous and I'm not sure I understand it.
> >
> > On the other hand, I'm not looking for one-liners; I really want clarity
> > as opposed to cleverness.
>
> tabwidth = 4
>
> -- tabstop !! (col-1) == there is a tabstop at column col
> -- This is an infinite list, so no need to limit the line width
> tabstops = map (\col -> col `mod` tabwidth == 1) [1..]
>
> -- calculate spaces needed to fill to the next tabstop in advance
> tabspaces = snd $ mapAccumR addspace [] tabstops
> addspace cs isstop = let cs'=' ':cs in (if isstop then [] else cs',cs')
>
>
> main = interact $ unlines . map detabLine . lines
> where
> detabLine = concat $ zipWith replace tabspaces
> replace cs '\t' = cs -- replace with adequate number of spaces
> replace _ char = [char] -- pass through
>
>
> How about that?
>
>
> Regards,
> apfelmus
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071212/fbd7015f/attachment.htm
More information about the Haskell-Cafe
mailing list