22 lines
446 B
Haskell
Executable File
22 lines
446 B
Haskell
Executable File
#!/usr/bin/env nix-script
|
|
#!>haskell
|
|
|
|
{- Calculate words frequency. Use in a pipe. -}
|
|
|
|
import Data.List
|
|
import Data.Ord (comparing)
|
|
import Data.Map (toList, fromListWith)
|
|
|
|
freqs = sort' . toList . fromListWith (+) . map t
|
|
where
|
|
t x = (x, 1)
|
|
sort' = reverse . sortBy (comparing snd)
|
|
|
|
pretty = intercalate "\n" . map line
|
|
where line (x, y) = x ++ ": " ++ show y
|
|
|
|
best = filter ((>50) . snd)
|
|
|
|
main = interact (pretty . freqs . words)
|
|
|