blob: e1245e82b9260da437a1f1aef181cf00c99d069f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
|