fpco / unliftio

The MonadUnliftIO typeclass for unlifting monads to IO
Other
151 stars 51 forks source link

Move `askUnliftIO` out of class #55

Closed akrmn closed 4 years ago

akrmn commented 4 years ago

When defining monad transformers as newtypes over IdentityT or ReaderT r, I'd like to simply derive an instance for UnliftIO with the newtype strategy,

newtype Newtype m a = Newtype (m a) 
  deriving newtype (Functor, Applicative, Monad, MonadIO, MonadUnliftIO)

However, this currently fails with the error

    • Couldn't match representation of type ‘m (UnliftIO (Newtype m))’
                               with that of ‘m (UnliftIO m)’
        arising from the coercion of the method ‘askUnliftIO’
          from type ‘m (UnliftIO m)’
            to type ‘Newtype m (UnliftIO (Newtype m))’
      NB: We cannot know what roles the parameters to ‘m’ have;
        we must assume that the role is nominal
    • When deriving the instance for (MonadUnliftIO (Newtype m))

This could be avoided by moving the askUnliftIO method out of the class definition. This is pretty much the breaking part of #13.

snoyberg commented 4 years ago

Good call, it's about time. I'm testing a few other packages, and then I'll release.

akrmn commented 4 years ago

Thanks a lot!

evanrelf commented 3 years ago

Now that askUnliftIO is no longer a method in the MonadUnliftIO class, would it be possible to remove or deprecate wrappedWithRunInIO? I wasn't aware you could just derive MonadUnliftIO for newtypes (and get a correct instance) because of the example for wrappedWithRunInIO saying you can't.

snoyberg commented 3 years ago

I'm OK with deprecating, but I think the more direct fix here is fixing the documentation, which is simply out of date.