Dedent

Posted on 2015-07-25 by nbloomf
Tags: literate-haskell, munge

This post is literate Haskell; you can load the source into GHCi and play along.


Dedent lines by one space or tab.

module Dedent where

import Data.List (lines, intersperse)

dedent :: String -> String
dedent = concat . intersperse "\n" . map foo . lines
  where
    foo (' ':cs)  = cs
    foo ('\t':cs) = cs
    foo x = x

main :: IO ()
main = interact dedent