I'd like to use finally, signature IO a -> IO b -> IO a.
However, the operations I wanna use are based on a different monad than IO (namely Servant's ClientM).
I knew liftIO, but that seems to do the opposite -- IO a -> m a.
How can I transform my monads into IOs, or lift finally such as to operate on my monads instead?
Note that ClientM also has a MonadBaseControl IO ClientM instance which is for this sort of thing. For instance, I think the following should typecheck (and can be used with m ~ ClientM).
finally' :: MonadBaseControl IO m => m a -> m b -> m a
finally' x y = control $ \runInIO -> catch (runInIO x) (runInIO y)
Not only does the above typecheck, but it is defined in lifted-base as finally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With