[Haskell-cafe] Comments and/or Criticisms

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Sep 10 02:36:32 EDT 2007


On Sep 10, 2007, at 1:47 , Stuart Cook wrote:

> On 9/10/07, PR Stanley <prstanley at ntlworld.com> wrote:
>> --count occurrences of chars in string
>> countCS :: [Char] -> [(Char, Int)]
>> countCS xs = [(x, (countC x xs)) | x <- [' '..'z'], (countC x xs)  
>> > 0]
>
> A few things to note:

My naive take on it:

import Data.List
import Control.Monad.Reader
countCS = map (liftM2 (,) head length) . group . sort

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list