Created
August 14, 2012 22:52
-
-
Save master-q/3353689 to your computer and use it in GitHub Desktop.
Gyo.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ghc -O2 -Wall Gyo.hs でコンパイルしてみてください。