Hi, I wrote something like "let t = try (hGetLine h1)" and I would like to check is it EOFError or not. How can I do this ?? Thanks
On Thursday, 2003-06-12, 18:01, CEST, Filip wrote:
Hi,
I wrote something like "let t = try (hGetLine h1)" and I would like to check is it EOFError or not. How can I do this ??
Thanks
Hello, the above code assigns the I/O action try (hGetLine h1) to t. I suppose you want to assign the result of this action to t. If this is the case, you have to write t <- try (hGetLine h1). You can then examine t as in the following example: t <- try (hGetLine h1) case t of Left error | isEOFError error -> do <EOF handling> Right result -> do <normal continuation> A better way might be to use catch which is exported from the Prelude. Wolfgang
On Thu, 12 Jun 2003, Wolfgang Jeltsch wrote:
On Thursday, 2003-06-12, 18:01, CEST, Filip wrote:
Hi,
I wrote something like "let t = try (hGetLine h1)" and I would like to check is it EOFError or not. How can I do this ??
Thanks
Hello,
the above code assigns the I/O action try (hGetLine h1) to t. I suppose you want to assign the result of this action to t. If this is the case, you have to write t <- try (hGetLine h1). You can then examine t as in the following example: t <- try (hGetLine h1) case t of Left error | isEOFError error -> do <EOF handling> Right result -> do <normal continuation>
Beware: The above causes pattern match failure if a true error (other than end of file) occurs. You probably want something like: case t of Left error | isEOFError error -> do <EOF handling> | otherwise -> do <error handling> Right result -> do <normal continuation>
A better way might be to use catch which is exported from the Prelude.
Dean
On Thursday, 2003-06-12, 21:02, CEST, Dean Herington wrote:
On Thu, 12 Jun 2003, Wolfgang Jeltsch wrote:
[...] You can then examine t as in the following example: t <- try (hGetLine h1) case t of Left error | isEOFError error -> do <EOF handling> Right result -> do <normal continuation>
Beware: The above causes pattern match failure if a true error (other than end of file) occurs. You probably want something like:
case t of Left error | isEOFError error -> do <EOF handling> | otherwise -> do <error handling> Right result -> do <normal continuation>
Ups, I overlooked this. What I really wanted was: case t of Left error | isEOFError error -> do <EOF handling> | otherwise -> ioError error Right result -> do <normal continuation>
[...]
Dean
Wolfgang
participants (3)
-
Dean Herington -
Filip -
Wolfgang Jeltsch