Skip to content

Instantly share code, notes, and snippets.

@master-q
Created August 14, 2012 22:52
Show Gist options
  • Save master-q/3353689 to your computer and use it in GitHub Desktop.
Save master-q/3353689 to your computer and use it in GitHub Desktop.
Gyo.hs
import qualified Data.ByteString.Lazy.Char8 as BS
import System.Environment
main :: IO ()
main = do
args <- getArgs
case args of
[] -> printCount
["-"] -> printCount
("-f":as) -> fmode as
_ -> mmode args
printCount :: IO ()
printCount = BS.getContents >>= print . countLines
printCountF :: String -> IO ()
printCountF arg = BS.readFile arg >>= print . countLines
fmode :: [String] -> IO ()
fmode [] = putStr ""
fmode (arg:args) = do putStr ( arg ++ " " )
printCountF arg
fmode args
mmode :: [String] -> IO ()
mmode [] = putStr ""
mmode (arg:args) = do printCountF arg; mmode args
countLines :: BS.ByteString -> Int
countLines bs = length $ BS.lines bs
@master-q
Copy link
Author

ghc -O2 -Wall Gyo.hs でコンパイルしてみてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment