[Haskell-beginners] Re: mind your head, was: Parsing a file with
data divided into sections
Magnus Therning
magnus at therning.org
Fri Feb 6 05:40:15 EST 2009
On Fri, Feb 6, 2009 at 10:30 AM, Christian Maeder
<Christian.Maeder at dfki.de> wrote:
[..]
>> 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!
Yes, that's how I modified my own "solution" once I tracked down what
sort of input it would fail on:
main = interact (unlines . map show . countDays . dropWhile null . lines)
/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