import System
wcf :: ( Int, Int, Int ) -> String -> ( Int, Int, Int )
wcf ( cc, w, lc ) [] = ( cc, w, lc )
wcf ( cc, w, lc ) ( ' ' : xs ) = wcf( cc+1, w+1, lc ) xs
wcf ( cc, w, lc ) ( '\t' : xs ) = wcf( cc+1, w+1, lc ) xs
wcf ( cc, w, lc ) ( '\n' : xs ) = wcf( cc+1, w+1, lc+1 ) xs
wcf ( cc, w, lc ) ( x : xs ) = wcf( cc+1, w, lc ) xs
wc :: IO()
wc = do name <- getLine
contents <- readFile name
let ( cc, w, lc ) = wcf( 0, 0, 0 ) contents
putStrLn ( "The file:" ++ name ++ " has " )
putStrLn ( show cc ++ " chars " )
putStrLn ( show w ++ " words " )
putStrLn ( show lc ++ " lines." )
####
C:\ghc\test>wc 60sp2l.txt
wc: interrupted
C:\ghc\test>wc
60sp2l.txt
The file:60sp2l.txt has
62 chars
62 words
2 lines.
C:\ghc\test>wc
p:\test\1GB.dat
The file:p:\test\1GB.dat has
Heap exhausted;
Current maximum heap size is 268435456 bytes (256 Mb);
use `+RTS -M' to increase it.
####
wcf :: ( Int, Int, Int ) -> String -> ( Int, Int, Int )
wcf ( cc, w, lc ) [] = ( cc, w, lc )
wcf ( cc, w, lc ) ( ' ' : xs ) = wcf( cc+1, w+1, lc ) xs
wcf ( cc, w, lc ) ( '\t' : xs ) = wcf( cc+1, w+1, lc ) xs
wcf ( cc, w, lc ) ( '\n' : xs ) = wcf( cc+1, w+1, lc+1 ) xs
wcf ( cc, w, lc ) ( x : xs ) = wcf( cc+1, w, lc ) xs
wc :: IO()
wc = do putStr ( "Filename; " )
name <- getLine
contents <- readFile name
let ( cc, w, lc ) = wcf( 0, 0, 0 ) contents
putStrLn ( "The file:" ++ name ++ " has " )
putStrLn ( show cc ++ " chars " )
putStrLn ( show w ++ " words " )
putStrLn ( show lc ++ " lines." )
main = wc
####
C:\ghc\test>ghc -o wc.exe wc.hs
wc.hs:9:8: Parse error in pattern
####
Rectangle s1 s2 `containsS` (x,y) =
let t1 = s1 / 2
t2 = s2 / 2
in -t1<=x && x<=t1 && -t2<=y && t2<=t2