Letter frequency: Difference between revisions
Content added Content deleted
(added RPL) |
(→{{header|Haskell}}: Standard operators perhaps now preferable to Control.Arrow ?) |
||
Line 3,608: | Line 3,608: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Short version: |
Short version: |
||
<syntaxhighlight lang="haskell">import Data.List (group,sort) |
<syntaxhighlight lang="haskell">import Data.List (group, sort) |
||
import Control.Arrow ((&&&)) |
|||
main :: IO () |
|||
main = interact (show . |
main = interact (show . fmap ((,) . head <*> length) . group . sort</syntaxhighlight> |
||
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: |