[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 05:30:33 EST 2009

Magnus Therning wrote:
>>>>>         isSection line = not . isSpace . head $ line

In this particular case I would use:
  isSection = null . takeWhile isSpace

>>> Prelude.head: empty list
>> see also
>> http://haskell.org/haskellwiki/Haskell_programming_tips#Partial_functions_like_fromJust_and_head
> Another course of action would be to add exception handling; if head
> throws an exception then the input file isn't following the accepted
> syntax.

I'ld rather check all lines before (or filter non empty ones) than
trying to catch Prelude.head: empty list!


More information about the Beginners mailing list