Skip to content

Instantly share code, notes, and snippets.

@imeckler
Last active October 12, 2015 19:18
Show Gist options
  • Save imeckler/4075086 to your computer and use it in GitHub Desktop.
Save imeckler/4075086 to your computer and use it in GitHub Desktop.
A wordcount program in Haskell as an example of programming as data transformation
import qualified Data.Map as M
import Control.Arrow ((>>>))
import Data.List (intercalate)
import GHC.Exts (sortWith)
main = interact $ words
>>> foldr incr M.empty
>>> M.toList
>>> sortWith (negate . snd)
>>> map show
>>> intercalate "\n"
where incr k = M.insertWith' (+) k 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment