Created
November 19, 2015 16:26
-
-
Save alcarney/d3c2a827a8148d7e5fa5 to your computer and use it in GitHub Desktop.
A simple Haskell program to count the number of lines in a given file.
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 System.Environment (getArgs) | |
countLines :: String -> IO Int | |
countLines file = do | |
contents <- readFile file | |
return (length $ lines contents) | |
main :: IO () | |
main = do | |
args <- getArgs | |
case (length args) of | |
0 -> putStrLn "You need to tell me which file you want to count the lines of" | |
_ -> let file = head args in do | |
putStr $ "The number of lines in the file" ++ file ++ "is: " | |
lines <- countLines file | |
putStrLn $ show lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment