Sun, 23 Jul 2000 19:38:39 -0700 (PDT), Richard Uhtenwoldt <[EMAIL PROTECTED]> pisze:

> but it would be nice for a small program fragment be able to loop over
> the contents of an input file without resorting to "catch", which is
> more awkard than most constructs.  that is easy to achieve: we
> introduce a new primitive, hGetCharMaybe,

Why primitive?

catchEOF:: IO a -> IO (Maybe a)
catchEOF act = liftM Just act `catch`
    \e -> if isEOFError e then return Nothing else ioError e

hGetCharMaybe:: IO (Maybe Char)
hGetCharMaybe = catchEOF hGetChar

-- 
 __("<  Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/            GCS/M d- s+:-- a23 C+++$ UL++>++++$ P+++ L++>++++$ E-
  ^^                W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK                5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-


Reply via email to