Network.firstSuccesful: 'throw' vs 'throwIO' usage

Herbert Valerio Riedel hvr at
Thu Sep 6 11:40:23 CEST 2012


while reading over the source code of network[1], I noticed a use of 'throw' where I'd
expect 'throwIO':

    import qualified Control.Exception as Exception

    catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
    catchIO = Exception.catch

    -- Returns the first action from a list which does not throw an exception.
    -- If all the actions throw exceptions (and the list of actions is not empty),
    -- the last exception is thrown.
    firstSuccessful :: [IO a] -> IO a
    firstSuccessful [] = error "firstSuccessful: empty list"
    firstSuccessful (p:ps) = catchIO p $ \e ->
        case ps of
            [] -> Exception.throw e
            _  -> firstSuccessful ps, is `throw` used properly in the code above, or should it rather
be `throwIO`?


More information about the Libraries mailing list