Skip to content

Instantly share code, notes, and snippets.

@bitmaybewise
Last active August 29, 2015 14:08
Show Gist options
  • Save bitmaybewise/59ab5328344a466a0f6d to your computer and use it in GitHub Desktop.
Save bitmaybewise/59ab5328344a466a0f6d to your computer and use it in GitHub Desktop.
Um contador de palavras numa frase em Haskell
import Data.List
frase = "vaca batata galinha batata coxinha macaco batata vaca batata"
wordCounter frase =
nub $ map (\x -> (x, length $ filter (== x) palavras)) palavras
where palavras = words frase
-- [("vaca",2),("batata",4),("galinha",1),("coxinha",1),("macaco",1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment