@@ -6,21 +6,21 @@ import qualified Data.Text.Encoding as T
66import qualified Data.Text.Lazy as TL
77import qualified Data.Text.Lazy.Encoding as TL
88
9−text needle haystack = do
10− bs <- B.readFile haystack
11− print . length . filter (==needle) . T.lines . T.decodeUtf8 $ bs
9+text haystack = do
10+ ls <- (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
11+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
1212
13−lazyText needle haystack = do
14− bs <- BL.readFile haystack
15− print . length . filter (==needle) . TL.lines . TL.decodeUtf8 $ bs
13+lazyText haystack = do
14+ ls <- (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
15+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
1616
17−string needle haystack = do
18− s <- readFile haystack
19− print . length . filter (==needle) . lines $ s
17+string haystack = do
18+ ls <- lines `fmap` readFile haystack
19+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
2020
2121main = do
2222 args <- getArgs
2323 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
24+ ["text",h] -> text h
25+ ["lazytext",h] -> lazyText h
26+ ["string",h] -> string h