From bc0a9edd47dad7a0bf7df26941a0d870c0c3d0ad Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 9 Jan 2017 19:53:06 +1100 Subject: Cleaning things up, splitting code into more modules --- src/File.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/File.hs (limited to 'src/File.hs') diff --git a/src/File.hs b/src/File.hs new file mode 100644 index 0000000..e1245e8 --- /dev/null +++ b/src/File.hs @@ -0,0 +1,31 @@ +module File( + countLines + ) where + + + + +import qualified System.IO as IO + + + + +countLines :: FilePath -> IO Int +countLines f = do + h <- IO.openFile f IO.ReadMode + e <- IO.hIsEOF h + if e + then IO.hClose h >> return 0 + else countLinesTail h 0 + + + + +countLinesTail :: IO.Handle -> Int -> IO Int +countLinesTail h n = do + t <- IO.hGetLine h + e <- IO.hIsEOF h + if e + then IO.hClose h >> return (n + 1) + else countLinesTail h (n + 1) + -- cgit