@@ -6,25 +6,20 @@ import qualified Data.Text.Encoding as T
66import qualified Data.Text.Lazy as TL
77import qualified Data.Text.Lazy.Encoding as TL
88
9−bytestring haystack = do
10− ls <- B.lines `fmap` B.readFile haystack
9+func :: (Eq a) => [a] -> IO ()
10+func ls =
1111 print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
1212
13−lazyBytestring haystack = do
14− ls <- BL.lines `fmap` BL.readFile haystack
15− print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
13+bytestring haystack = func =<< B.lines `fmap` B.readFile haystack
1614
17−text haystack = do
18− ls <- (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
19− print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
15+lazyBytestring haystack = func =<< BL.lines `fmap` BL.readFile haystack
2016
21−lazyText haystack = do
22− ls <- (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
23− print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
17+text haystack = func =<< (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
2418
25−string haystack = do
26− ls <- lines `fmap` readFile haystack
27− print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
19+lazyText haystack = func =<<
20+ (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
21+
22+string haystack = func =<< lines `fmap` readFile haystack
2823
2924main = do
3025 args <- getArgs