
Li-yao Xia
Hi Magnus,
You can use GeneralizedNewtypeDeriving:
deriving (..., MonadBase IO, MonadBaseControl IO)
I did start out with that, but got this from the compiler: Main.hs 18 26 error error: • The type family application ‘StM (ReaderT Env IO) a’ is no smaller than the instance head ‘StM AppM a’ (Use UndecidableInstances to permit this) • In the instance declaration for ‘MonadBaseControl IO AppM’ Adding `UndecidableInstances` is something I'm not quite comfortable with, since I don't understand what it means.
To do it by hand, since AppM is a newtype around ReaderT, use the fact that is already is an instance of MonadBaseControl.
liftBaseWith f = AppM (liftBaseWith (\run -> f (run . unAppM)))
To discover that implementation, you can start with the idea that liftBaseWith should basically be the same as the one as for ReaderT, using TypeApplications to make explicit the instance we want to use:
liftBaseWith = liftBaseWith @IO @(ReaderT Env IO)
And then fix the type errors by inserting AppM and unAppM in the right places, possibly after eta-expanding some things.
liftBaseWith f = liftBaseWith @IO @(ReaderT Env IO) f liftBaseWith f = liftBaseWith @IO @(ReaderT Env IO) (\run -> f run) -- The type errors now point exactly to the two locations that need changing.
Thanks. That's excellent advise, I'll need to add that extension, `TypeApplications`, to my toolbox right away.
The rest of your implementation looks good.
Thanks for your help! /M -- Magnus Therning OpenPGP: 0x927912051716CE39 email: magnus@therning.org twitter: magthe http://magnus.therning.org/ Reality is that which, when you stop believing in it, doesn't go away. — Philip K. Dick