Letter frequency: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Cowgol) |
m (→{{header|Haskell}}: Tidied ( Ormolu-formatted )) |
||
Line 2,207: | Line 2,207: | ||
or, as an alternative to sorting and grouping the whole string, we could use some kind of container as the accumulator for a single fold, for example: |
or, as an alternative to sorting and grouping the whole string, we could use some kind of container as the accumulator for a single fold, for example: |
||
<lang haskell>import |
<lang haskell>import Data.List (sortBy) |
||
import qualified Data.Map.Strict as M |
|||
import Data.Ord (comparing) |
import Data.Ord (comparing) |
||
import Data.List (sortBy) |
|||
charCounts :: String -> M.Map Char Int |
charCounts :: String -> M.Map Char Int |
||
Line 2,218: | Line 2,218: | ||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
readFile "miserables.txt" |
|||
>>= mapM_ print |
|||
mapM_ print $ sortBy (flip $ comparing snd) $ M.toList (charCounts s)</lang> |
|||
. sortBy |
|||
(flip (comparing snd)) |
|||
. M.toList |
|||
. charCounts</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>(' ',516452) |
<pre>(' ',516452) |