Skip to content

Instantly share code, notes, and snippets.

@sshine
Last active August 29, 2015 14:09
Show Gist options
  • Save sshine/396df7674bf6270dc7f6 to your computer and use it in GitHub Desktop.
Save sshine/396df7674bf6270dc7f6 to your computer and use it in GitHub Desktop.
foo :: IO (Maybe Socket) -> IO () -> IO (Maybe Socket)
foo sock action = do
actionHandler <- tryIOError action
return $ either (\err -> Nothing) (\sock' -> sock <|> Just sock') actionHandler
performSocketAction2 :: Socket -> IO () -> IO (Maybe Socket)
performSocketAction2 sock action = foo (Just sock) action
makeSocket :: IO (Socket) -> IO (Maybe Socket)
makeSocket action = foo Nothing action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment