Skip to content

Instantly share code, notes, and snippets.

@lotz84
Last active December 9, 2015 08:10
Show Gist options
  • Save lotz84/5f663290b4131139f47b to your computer and use it in GitHub Desktop.
Save lotz84/5f663290b4131139f47b to your computer and use it in GitHub Desktop.
Calculate unigram of Lovecraft's Dagon using multiset <https://hackage.haskell.org/package/multiset>.
import Data.List (sortOn)
import qualified Data.MultiSet as MultiSet
main :: IO ()
main = do
contents <- concat . map words . lines <$> readFile "dagon.txt"
mapM_ print . take 10 . reverse . sortOn snd . MultiSet.toOccurList . MultiSet.fromList $ contents
$ runhaskell Main.hs
("the",154)
("I",91)
("of",85)
("and",61)
("a",56)
("to",41)
("in",39)
("was",33)
("that",28)
("my",27)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment