Letter frequency: Difference between revisions
m
→{{header|Haskell}}: Tidied ( Ormolu-formatted )
Not a robot (talk | contribs) (Add Cowgol) |
m (→{{header|Haskell}}: Tidied ( Ormolu-formatted )) |
||
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:
<lang haskell>import
import qualified Data.Map.Strict as M
import Data.Ord (comparing)
charCounts :: String -> M.Map Char Int
Line 2,218:
main :: IO ()
main =
>>= mapM_ print
. sortBy
(flip (comparing snd))
. M.toList
. charCounts</lang>
{{Out}}
<pre>(' ',516452)
|