@@ -16,14 +16,14 @@ import Data.IORef
1616import qualified Data.List as List
1717import qualified Data.Ord as Ord
1818import Foreign.Storable (Storable(..))
19−import qualified Streamly.Data.Unicode.Stream as Streamly
20−import qualified Streamly.Internal.Data.Unicode.Stream as Streamly
21−import qualified Streamly.FileSystem.Handle as FH
19+import qualified Streamly.Data.Unicode.Stream as S
20+import qualified Streamly.Internal.Data.Unicode.Stream as S
2221import qualified Streamly.Data.Fold as FL
2322import qualified Streamly.Internal.Data.Fold as IFL
2423import qualified Streamly.Internal.Data.Unfold as IUF
24+import qualified Streamly.Internal.FileSystem.File as File
2525import qualified Streamly.Memory.Array as A
26−import qualified Streamly.Prelude as Streamly
26+import qualified Streamly.Prelude as S
2727import System.Environment (getArgs)
2828import System.IO (openFile, IOMode(..))
2929
@@ -50,20 +50,19 @@ isAlpha c
5050
5151main :: IO ()
5252main = do
53− name <- fmap head getArgs
54− src <- openFile name ReadMode
53+ inFile <- fmap head getArgs
5554
5655 -- Write the stream to a hashmap consisting of word counts
5756 mp <-
5857 let
5958 alter Nothing = fmap Just $ newIORef (1 :: Int)
6059 alter (Just ref) = modifyIORef' ref (+ 1) >> return (Just ref)
61− in Streamly.unfold FH.read src -- SerialT IO Word8
62− & Streamly.decodeLatin1 -- SerialT IO Char
63− & Streamly.map toLower -- SerialT IO Char
64− & Streamly.words FL.toList -- SerialT IO String
65− & Streamly.filter (all isAlpha) -- SerialT IO String
66− & Streamly.foldlM' (flip (Map.alterF alter)) Map.empty -- IO (Map String (IORef Int))
60+ in File.toBytes inFile -- SerialT IO Word8
61+ & S.decodeLatin1 -- SerialT IO Char
62+ & S.map toLower -- SerialT IO Char
63+ & S.words FL.toList -- SerialT IO String
64+ & S.filter (all isAlpha) -- SerialT IO String
65+ & S.foldlM' (flip (Map.alterF alter)) Map.empty -- IO (Map String (IORef Int))
6766
6867 -- Print the top hashmap entries
6968 counts <-