[Haskell-beginners] mind your head,
was: Parsing a file with data divided into sections
Christian Maeder
Christian.Maeder at dfki.de
Thu Feb 5 04:58:30 EST 2009
Magnus Therning wrote:
>> isSection line = not . isSpace . head $ line
I'ld be more careful with "head"! Imagine your binary fails with:
Prelude.head: empty list
> countDays [] = []
> countDays ls = let
> day = head ls
> count = length $ takeWhile (isSpace . head) $ tail ls
> in (day, count) : countDays (drop (1 + count) ls)
here too, and better use a pattern like: ls@(hd, tl)
Cheers Christian
More information about the Beginners
mailing list