[fix] Generalize runUnliftIO to use any monad that is an instance of MonadUnliftIO.

This commit is contained in:
Yamada Ryo 2024-10-17 15:51:37 +09:00
parent 7e5fb2fdde
commit ddde1044d4
No known key found for this signature in database
GPG Key ID: AAE3C7A542B02DBF
2 changed files with 7 additions and 3 deletions

View File

@ -37,3 +37,4 @@
* Renamed `Control.Monad.Hefty.Writer.listen` -> `intercept`
* Reexported `Data.Effect.*` from the interpreters module `Control.Monad.Hefty.*`.
* Generalized `runUnliftIO` to use any monad that is an instance of `MonadUnliftIO`.

View File

@ -16,12 +16,15 @@ where
import Control.Monad.Hefty (Eff, interpretH, runEff, send0, type (~>))
import Data.Effect.Unlift
import UnliftIO (MonadUnliftIO)
import UnliftIO qualified as IO
runUnliftBase :: forall b. (Monad b) => Eff '[UnliftBase b] '[b] ~> b
runUnliftBase =
runEff . interpretH \(WithRunInBase f) ->
send0 $ f runEff
runUnliftIO :: Eff '[UnliftIO] '[IO] ~> IO
runUnliftIO = runUnliftBase
{-# INLINE runUnliftIO #-}
runUnliftIO :: (MonadUnliftIO m) => Eff '[UnliftIO] '[m] ~> m
runUnliftIO =
runEff . interpretH \(WithRunInBase f) ->
send0 $ IO.withRunInIO \run -> f $ run . runEff