[Haskell-cafe] Re: Strange HTTP module behavior [PATCH]

Peter Simons simons at cryp.to
Sat Feb 19 04:55:23 EST 2005


John Goerzen writes:

 > Which arguably is not what one would expect recv to do,
 > and in any case is undocumented at
 > http://www.haskell.org/ghc/docs/latest/html/libraries/network/Network.Socket.html#v%3Arecv

Someone correct me if I am wrong, but I think that _all_ I/O
functions may throw an EOF exception -- not just recv. I
have found the following wrapper to be the simplest solution
to dealing with that:

  -- |Return 'Nothing' if the given computation throws an
  -- 'isEOFError' exception.

  handleEOF :: IO a -> IO (Maybe a)
  handleEOF f =
    catchJust ioErrors
      (fmap Just f)
      (\e -> if isEOFError e then return Nothing else ioError e)

Peter



More information about the Haskell-Cafe mailing list