Skip to content

Instantly share code, notes, and snippets.

@tanakh
Created August 14, 2012 14:04
Show Gist options
  • Select an option

  • Save tanakh/3349522 to your computer and use it in GitHub Desktop.

Select an option

Save tanakh/3349522 to your computer and use it in GitHub Desktop.
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as L
import System.Environment
main :: IO ()
main = go False =<< getArgs where
go _ ("-f": rest) = go True rest
go _ [] = print . gyo =<< L.getContents
go _ ["-"] = print . gyo =<< L.getContents
go f files = forM_ files $ \file -> do
ln <- return . gyo =<< L.readFile file
if f
then putStrLn $ file ++ " " ++ show ln
else putStrLn $ show ln ++ " " ++ file
gyo :: L.ByteString -> Int
gyo = length . L.lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment