[Haskell-beginners] Re: mind your head, was: Parsing a file with data divided into sections

Christian Maeder Christian.Maeder at dfki.de
Fri Feb 6 03:47:45 EST 2009


I wrote:
> 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

see also
http://haskell.org/haskellwiki/Haskell_programming_tips#Partial_functions_like_fromJust_and_head

>> 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)

oops, the pattern should be: ls@(hd : tl)

Cheers again
Christian



More information about the Beginners mailing list