fork download
  1. import Data.Char
  2. import Data.Map
  3.  
  4. -- return a tuple of words, punctuation
  5. splitUp :: String -> ([String], [String])
  6. splitUp s = (words s, dewords s)
  7. where dewords s = filter (not . isAlpha) s
  8.  
  9. -- map: key is word, value is another map: key is second word, val is freq: 1/n
  10. data FreqTable = Map String (Map String Int)
  11.  
  12. makeTable :: [String] -> FreqTable -> FreqTable
  13. makeTable (wa:wb:ws) table = if (member wa table)
  14. then if (member wb (table ! wa))
  15. then let n = (table ! wa) ! wb
  16. in insert wb (n+1) (table ! wa) ! wb
  17. else insert wa 1 (table ! wa) ! wb
  18. else insert wa (fromlist [(wb, 1)])
  19.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty