summaryrefslogtreecommitdiff
path: root/src/File.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-09 19:53:06 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-09 19:53:06 +1100
commitbc0a9edd47dad7a0bf7df26941a0d870c0c3d0ad (patch)
tree4443f657e71a9dca3d9f017c8c4176faaab479da /src/File.hs
parent82cb1c4265c0c4a55fcd3fec9bcaec6647d11030 (diff)
Cleaning things up, splitting code into more modules
Diffstat (limited to 'src/File.hs')
-rw-r--r--src/File.hs31
1 files changed, 31 insertions, 0 deletions
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)
+