Closed goertzenator closed 11 months ago
The proposed solution has some serious problems and I would like to retract it.
Also, I've found a solution that involves no modification to Servant.
The main line is this one which hoists a ReaderT _ IO
to Handler
server <- withRunInIO $ \toIo -> pure $ hoistServer counterAPI (Handler . ExceptT . try . toIo) server_rio
-- `toIO` converts from (ReaderT (IORef Int) IO) to IO
-- `Handler. ExceptT . try` converts Servant exceptions in IO back to ExceptT
That of course will work with anything that is MonadUnliftIO
such as the cleff and effectful Eff
monad.
Closing this issue.
I have been experimenting
MonadUnliftIO
handlers under Servant with some success. Example. An essential component isunliftio
's "toIO
" function which looks like this:This is an effective way to get a
IO a
which with a little further massaging can be turned intoHandler
. But, this function has a monadic context so it does not work withhoistServer
which has this signature:What is needed in this situation is a monadic version of hoistServer that looks like this:
I would like to experiment with an implementation that looks like this:
hoistServerWithContext
intohoistServerWithContextM
.hoistServerWithContext
that wrapshoistServerWithContextM
usingIdentity
.My example above demonstrates
ReaderT
, but my real motive is to enableReaderT
-based effect systems likecleff
andeffectful
.I am looking for some feedback on this idea. If I did a PR like this would it have any hope of being merged? Are there some obvious shortcomings here that I am not seeing?
As a reference, wai supports
unliftio
through the wai-control package.Thank you for your time.