Word frequency: Difference between revisions

m
→‎{{header|Haskell}}: workaround failing syntax highlighting (doesn't seem to know that ' is a symbol character)
(simplify)
m (→‎{{header|Haskell}}: workaround failing syntax highlighting (doesn't seem to know that ' is a symbol character))
Line 2,456:
import Control.Category -- (>>>)
import Data.Char -- toLower, isSpace
import Data.List -- sortBy, (Foldable(foldl')), filter -- '
import Data.Ord -- Down
import System.IO -- stdin, ReadMode, openFile, hClose
Line 2,472:
 
frequencies :: Ord a => [a] -> Map a Integer
frequencies = foldl' (\m k -> M.insertWith (+) k 1 m) M.empty -- '
{-# SPECIALIZE frequencies :: [Text] -> Map Text Integer #-}
 
Line 2,509:
import System.IO (stdin, IOMode(..), openFile, hClose)
import System.Environment (getArgs)
import Data.IORef (IORef(..), newIORef, readIORef, modifyIORef') -- '
 
-- containers
Line 2,524:
where
alter Nothing = Just <$> newIORef (1 :: Int)
alter (Just ref) = modifyIORef' ref (+ 1) >> return (Just ref) -- '
 
main :: IO ()
Anonymous user