1

I'm writing a function publish, which needs to do some IO, and also call a function in MonadBaseControl IO m.The following works, but I would like to get rid of the constraint for MonadIO, since it should be redundant with MonadBaseControl

publish :: (MonadIO m, MonadBaseControl IO m) => m ()
publish =
  withResource $ \r ->
    liftIO $ someIOAction r

withResource is defined in Data.Pool, and has a MonadBaseControl IO m constraint.

someIOAction has the type r -> IO ()

I've read this question, but I can't figure out how to get rid of the second constraint: Is there any difference between "MonadIO m" and "MonadBaseControl IO m"?

If I remove MonadIO m then I don't have liftIO anymore. How do I execute an IO action from MonadBaseControl?

Community
  • 1
  • 1
Sean Clark Hess
  • 15,859
  • 12
  • 52
  • 100

1 Answers1

4

What you are looking for is the MonadBase class which is a superclass of MonadBaseControl:

class (Applicative b, Applicative m, Monad b, Monad m) =>
      MonadBase (b :: * -> *) (m :: * -> *) | m -> b where
  liftBase :: b α -> m α

So you can liftBase $ someIOAction r.

Julia Path
  • 2,356
  • 15
  • 21