@@ -0,0 +1,38 @@
1+import System.Environment
2+import qualified Data.ByteString.Char8 as B
3+import qualified Data.ByteString.Lazy.Char8 as BL
4+import qualified Data.Text as T
5+import qualified Data.Text.Encoding as T
6+import qualified Data.Text.Lazy as TL
7+import qualified Data.Text.Lazy.Encoding as TL
8+
9+every :: Int -> [a] -> [a]
10+every k = go k
11+ where go n (x:xs)
12+ | n < k = go (n+1) xs
13+ | otherwise = x : go 1 xs
14+ go _ _ = []
15+
16+func :: (Ord a) => [a] -> IO ()
17+func ls = print . sum . map f $ every 1000 ls
18+ where f needle = length . filter ((==GT) . compare needle) $ ls
19+
20+bytestring haystack = func =<< B.lines `fmap` B.readFile haystack
21+
22+lazyBytestring haystack = func =<< BL.lines `fmap` BL.readFile haystack
23+
24+text haystack = func =<< (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
25+
26+lazyText haystack = func =<<
27+ (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
28+
29+string haystack = func =<< lines `fmap` readFile haystack
30+
31+main = do
32+ args <- getArgs
33+ case args of
34+ ["bs",h] -> bytestring h
35+ ["lazybs",h] -> lazyBytestring h
36+ ["text",h] -> text h
37+ ["lazytext",h] -> lazyText h
38+ ["string",h] -> string h