Created
February 18, 2015 11:32
-
-
Save shigemk2/3723819aec2b60dafa41 to your computer and use it in GitHub Desktop.
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 | |
| wordNums :: String -> [(String,Int)] | |
| wordNums = map (\ws -> (head ws, length ws)) . group . sort . words | |
| -- 関数合成がないと読みづらい | |
| wordNums' xs = map (\ws -> (head ws,length ws)) (group (sort (words xs))) | |
| main = do | |
| print $ words "hey these are the words in this sentence" | |
| print $ group [1,1,1,1,2,2,2,2,3,3,2,2,2,5,6,7] | |
| print $ group ["boom","bip","bip","boom","boom"] | |
| print $ sort [5,4,3,7,2,1] | |
| print $ sort ["boom","bip","bip","boom","boom"] | |
| print $ wordNums "wa wa wee wa" | |
| print $ wordNums' "wa wa wee wa" | |
| -- ["hey","these","are","the","words","in","this","sentence"] | |
| -- [[1,1,1,1],[2,2,2,2],[3,3],[2,2,2],[5],[6],[7]] | |
| -- [["boom"],["bip","bip"],["boom","boom"]] | |
| -- [1,2,3,4,5,7] | |
| -- ["bip","bip","boom","boom","boom"] | |
| -- [("wa",3),("wee",1)] | |
| -- [("wa",3),("wee",1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment