@@ -23,19 +23,34 @@ instance (Enum a, Storable a) => Hashable (A.Array a) where
23 hashWithSalt salt arr = runIdentity $
23 hashWithSalt salt arr = runIdentity $
24 Streamly.runFold (Streamly.rollingHashWithSalt salt) (A.read arr)
24 Streamly.runFold (Streamly.rollingHashWithSalt salt) (A.read arr)
26+{-# INLINE toLower #-}
27+toLower :: Char -> Char
29+ | uc >= 0x61 && uc <= 0x7a = c
30+ | otherwise = Char.toLower c
32+ uc = fromIntegral (Char.ord c) :: Word
34+{-# INLINE isAlpha #-}
35+isAlpha :: Char -> Bool
37+ | uc >= 0x61 && uc <= 0x7a = True
38+ | otherwise = Char.isAlpha c
40+ uc = fromIntegral (Char.ord c) :: Word
26main :: IO ()
42main :: IO ()
29 increment m str = Map.insertWith (+) str (1 :: Int) m
45 increment m str = Map.insertWith (+) str (1 :: Int) m
30− report = traverse_ print
32 name <- fmap head getArgs
47 name <- fmap head getArgs
33 src <- openFile name ReadMode
48 src <- openFile name ReadMode
34 FH.read src -- SerialT IO Word8
49 FH.read src -- SerialT IO Word8
35 & Streamly.decodeChar8 -- SerialT IO Char
50 & Streamly.decodeChar8 -- SerialT IO Char
36− & Streamly.map Char.toLower -- SerialT IO Char
51+ & Streamly.map toLower -- SerialT IO Char
37 & Streamly.words -- SerialT IO (Array Char)
52 & Streamly.words -- SerialT IO (Array Char)
38− & Streamly.filterM (Streamly.all Char.isAlpha . A.read)
53+ & Streamly.filterM (Streamly.all isAlpha . A.read)
39 & Streamly.foldl' increment Map.empty
54 & Streamly.foldl' increment Map.empty
40 & fmap (List.take 25 . List.sortOn (Ord.Down . snd) . Map.toList)
55 & fmap (List.take 25 . List.sortOn (Ord.Down . snd) . Map.toList)
41− >>= report -- IO ()
56+ >>= traverse_ print