Last active
December 9, 2015 08:10
-
-
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>.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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