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

Add MonadBase IO instances #477

Closed
wants to merge 1 commit into from

Conversation

chrismwendt
Copy link
Contributor

This makes it easier to interface with lifted-async, lifted-base, and others.

The adds a dependency on transformers-base, which seems pretty small (107 LOC) and stable (~3 patch releases in 4 years).

@chrismwendt
Copy link
Contributor Author

I stumbled upon #404 (comment) and discovered unliftio mostly does the trick 🎉

However, there are so called "control" functions like withMVar which require MonadUnliftIO, but there's no instance for MonadUnliftIO ConduitT i o m, so apparently it's impossible to use withMVar inside of a ConduitT. Could this be implemented? What's preventing it from working? It might be hard to track the values being emitted from the callback's conduit, but it seems possible (although I haven't tried it).

As a fallback, could there be hybrid functions with plain IO callbacks like:

withMVarHybrid :: MonadIO m => MVar a -> (a -> IO b) -> m b
withMVarHybrid v f = liftIO $ withMVar v f

Here's the unliftio implementation for comparison:

withMVar :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b
withMVar var f = withRunInIO $ \run -> M.withMVar var (run . f)

@snoyberg
Copy link
Owner

You cannot set up "control" functions with ConduitT since it is continuation based. This is a deep topic, and I've written quite a bit on it previously. One starting point is:

https://github.com/snoyberg/conduit#resource-allocation

Adding MonadBase will not help with this, MonadIO already does the same thing and is insufficient for what you're trying to do.

@chrismwendt
Copy link
Contributor Author

Got it, I'll read up more before diving further into this.

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

Successfully merging this pull request may close these issues.

None yet

2 participants