on master help sign in
Use the File module instead of the Handle module.
e000868Harendra Kumar
examples/WordClassifier.hs+11−12
@@ -16,14 +16,14 @@ import Data.IORef
16import qualified Data.List as List
16import qualified Data.List as List
17import qualified Data.Ord as Ord
17import qualified Data.Ord as Ord
18import Foreign.Storable (Storable(..))
18import Foreign.Storable (Storable(..))
19−import qualified Streamly.Data.Unicode.Stream as Streamly
19+import qualified Streamly.Data.Unicode.Stream as S
20−import qualified Streamly.Internal.Data.Unicode.Stream as Streamly
20+import qualified Streamly.Internal.Data.Unicode.Stream as S
21−import qualified Streamly.FileSystem.Handle as FH
22import qualified Streamly.Data.Fold as FL
21import qualified Streamly.Data.Fold as FL
23import qualified Streamly.Internal.Data.Fold as IFL
22import qualified Streamly.Internal.Data.Fold as IFL
24import qualified Streamly.Internal.Data.Unfold as IUF
23import qualified Streamly.Internal.Data.Unfold as IUF
24+import qualified Streamly.Internal.FileSystem.File as File
25import qualified Streamly.Memory.Array as A
25import qualified Streamly.Memory.Array as A
26−import qualified Streamly.Prelude as Streamly
26+import qualified Streamly.Prelude as S
27import System.Environment (getArgs)
27import System.Environment (getArgs)
28import System.IO (openFile, IOMode(..))
28import System.IO (openFile, IOMode(..))
29
29
@@ -50,20 +50,19 @@ isAlpha c
50
50
51main :: IO ()
51main :: IO ()
52main = do
52main = do
53− name <- fmap head getArgs
53+ inFile <- fmap head getArgs
54− src <- openFile name ReadMode
55
54
56 -- Write the stream to a hashmap consisting of word counts
55 -- Write the stream to a hashmap consisting of word counts
57 mp <-
56 mp <-
58 let
57 let
59 alter Nothing = fmap Just $ newIORef (1 :: Int)
58 alter Nothing = fmap Just $ newIORef (1 :: Int)
60 alter (Just ref) = modifyIORef' ref (+ 1) >> return (Just ref)
59 alter (Just ref) = modifyIORef' ref (+ 1) >> return (Just ref)
61− in Streamly.unfold FH.read src -- SerialT IO Word8
60+ in File.toBytes inFile -- SerialT IO Word8
62− & Streamly.decodeLatin1 -- SerialT IO Char
61+ & S.decodeLatin1 -- SerialT IO Char
63− & Streamly.map toLower -- SerialT IO Char
62+ & S.map toLower -- SerialT IO Char
64− & Streamly.words FL.toList -- SerialT IO String
63+ & S.words FL.toList -- SerialT IO String
65− & Streamly.filter (all isAlpha) -- SerialT IO String
64+ & S.filter (all isAlpha) -- SerialT IO String
66− & Streamly.foldlM' (flip (Map.alterF alter)) Map.empty -- IO (Map String (IORef Int))
65+ & S.foldlM' (flip (Map.alterF alter)) Map.empty -- IO (Map String (IORef Int))
67
66
68 -- Print the top hashmap entries
67 -- Print the top hashmap entries
69 counts <-
68 counts <-