[Haskell-cafe] Software Tools in Haskell

Benja Fallenstein benja.fallenstein at gmail.com
Wed Dec 12 20:28:20 EST 2007


On Dec 13, 2007 2:20 AM, Benja Fallenstein <benja.fallenstein at gmail.com> wrote:
> Another version of detab:
>
> main = interact $ perLine $ concat . snd. mapAccumL f 0 where
>     f tab '\t' = (0, replicate (4-tab) ' ')
>     f tab char = ((tab+1) `mod` 4, [char])

Although on reflection, I think I might like the following compromise
with Tillmann's version best:

main = interact $ perLine $ detab 0 where
    detab tab ('\t':cs) = replicate (4-tab) ' ' ++ detab 0                 cs
    detab tab (char:cs) = char                  :  detab ((tab+1) `mod` 4) cs
    detab tab ""        = ""

- Benja


More information about the Haskell-Cafe mailing list