[Haskell-beginners] Re: Simple haskell problem ! Help please

Tim Attwood timothyea at comcast.net
Mon Nov 9 03:07:38 EST 2009


> Hi ! I am beginner in Haskell and have problems with this problem:
> compress :: Eq a => [a] -> [(a, Int)]
> If you have string "AAABCCC" it transforms it to : {A, 3} {B,1} {C,3}
> 
> Could you help me with it ?
> Thank you in advance !

This is straightforward with a list comprehension and the group function.

import Data.List

compress s = [(head g, length g) | g <- group s]



More information about the Beginners mailing list