Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withSinkFile and a lot of other with* functions doesn't necessarily need a MonadUnliftIO instance of the underlying monad #458

Open
poscat0x04 opened this issue Jan 6, 2021 · 1 comment

Comments

@poscat0x04
Copy link

The current implementation of withSinkFile is:

withSinkFile
  :: (MonadUnliftIO m, MonadIO n)
  => FilePath
  -> (ConduitM ByteString o n () -> m a)
  -> m a
withSinkFile fp inner =
  withRunInIO $ \run ->
  IO.withBinaryFile fp IO.WriteMode $
  run . inner . sinkHandle

which requires the underlying monad to have a MonadUnliftIO instance. But it is enough to implement withSinkFile with only a MonadMask, which is a strictly weaker constraint than MonadUnliftIO:

withSinkFile :: (MonadMask m, MonadIO m, MonadIO n) => FilePath -> (ConduitT ByteString o n () -> m a) -> m a
withSinkFile fp k =
  bracket
    (liftIO . openBinaryFile WriteMode)
    (liftIO . hClose)
    (k . sinkHandle)

This is also true for a lot of other with* functions. It would be nice to loosen the constraints on these functions.

@snoyberg
Copy link
Owner

snoyberg commented Jan 6, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants