@@ -0,0 +1,26 @@
1+import System.Environment
2+import qualified Data.ByteString as B
3+import qualified Data.ByteString.Lazy 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+text needle haystack = do
10+ bs <- B.readFile haystack
11+ print . length . filter (==needle) . T.lines . T.decodeUtf8 $ bs
12+
13+lazyText needle haystack = do
14+ bs <- BL.readFile haystack
15+ print . length . filter (==needle) . TL.lines . TL.decodeUtf8 $ bs
16+
17+string needle haystack = do
18+ s <- readFile haystack
19+ print . length . filter (==needle) . lines $ s
20+
21+main = do
22+ args <- getArgs
23+ case args of
24+ ["text",n,h] -> text (T.pack n) h
25+ ["lazytext",n,h] -> lazyText (TL.pack n) h
26+ ["string",n,h] -> string n h