tryWriteF :: NFData a => IO a -> WriterT [NFException] IO (Maybe a)
tryWriteF io = do
  io' <- liftIO (try io >>= evaluate . force)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- NFException -----------------------------------------------------------------

-- | A SomeException susceptible to DeepSeq.  Doesn't actually do anything, but
--   means that we can use it within an NFData/force context (e.g., tryWriteF)
tryWriteF :: NFData a => IO a -> WriterT [NFException] IO (Maybe a)
tryWriteF io = do
  io' <- liftIO (try io >>= evaluate . force)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- NFException -----------------------------------------------------------------

-- | A SomeException susceptible to DeepSeq.  Doesn't actually do anything, but
--   means that we can use it within an NFData/force context (e.g., tryWriteF)
tryWriteF io = do
  io' <- liftIO (try io >>= evaluate . force)
  case io' of
    Left e  -> tell [e] >> liftIO (return Nothing)
    Right r -> (liftIO . return . Just) r

-- NFException -----------------------------------------------------------------

-- | A SomeException susceptible to DeepSeq.  Doesn't actually do anything, but
--   means that we can use it within an NFData/force context (e.g., tryWriteF)