[Haskell-beginners] Re: Parsing a file with data divided into sections

Magnus Therning magnus at therning.org
Wed Feb 4 06:43:45 EST 2009


On Wed, Feb 4, 2009 at 11:10 AM, Heinrich Apfelmus
<apfelmus at quantentunnel.de> wrote:
[..]
> Here's a version using  span  from the Prelude:
>
>  main = interact $ unlines . map show . countDays . lines
>
>  countDays []       = []
>  countDays (day:xs) = (day, length people) : countDays xs'
>     where (people, xs') = span (isSpace . head) xs

Ah, yes, `span` is the function I was looking for!  I would have found
it if I had bothered to go to Hoogle :-(

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


More information about the Beginners mailing list