Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MonadUnliftIO instances for eligible carrier types. #420

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.1.2.0
- Adds `MonadUnliftIO` instances for `ReaderC`, `LiftC`, and `InterpretC`. ([#420](https://github.com/fused-effects/fused-effects/pull/420))

- Adds `Accum` ([#391](https://github.com/fused-effects/fused-effects/pull/391)) (by @turion)
- Adds an `Accum` effect
Expand Down
1 change: 1 addition & 0 deletions fused-effects.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ library
build-depends:
base >= 4.9 && < 4.17
, transformers >= 0.4 && < 0.6
, unliftio-core >= 0.2 && < 0.3


test-suite examples
Expand Down
3 changes: 2 additions & 1 deletion src/Control/Carrier/Interpret.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.IO.Unlift (MonadUnliftIO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever of this PR and #419 gets merged first should make sure to derive an instance for Choosing as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…and should note it in the changelog.

import Data.Functor.Const (Const(..))
import Data.Kind (Type)
import Unsafe.Coerce (unsafeCoerce)
Expand Down Expand Up @@ -87,7 +88,7 @@ runInterpretState handler state m

-- | @since 1.0.0.0
newtype InterpretC s (sig :: (Type -> Type) -> (Type -> Type)) m a = InterpretC { runInterpretC :: m a }
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus)
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus, MonadUnliftIO)

instance MonadTrans (InterpretC s sig) where
lift = InterpretC
Expand Down
3 changes: 2 additions & 1 deletion src/Control/Carrier/Lift.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.IO.Unlift (MonadUnliftIO)

-- | Extract a 'Lift'ed 'Monad'ic action from an effectful computation.
--
Expand All @@ -30,7 +31,7 @@ runM (LiftC m) = m

-- | @since 1.0.0.0
newtype LiftC m a = LiftC (m a)
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus)
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus, MonadUnliftIO)

instance MonadTrans LiftC where
lift = LiftC
Expand Down
5 changes: 5 additions & 0 deletions src/Control/Carrier/Reader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.IO.Unlift

-- | Run a 'Reader' effect with the passed environment value.
--
Expand Down Expand Up @@ -98,3 +99,7 @@ instance Algebra sig m => Algebra (Reader r :+: sig) (ReaderC r m) where
L (Local f m) -> runReader (f r) (hdl (m <$ ctx))
R other -> alg (runReader r . hdl) other ctx
{-# INLINE alg #-}

instance MonadUnliftIO m => MonadUnliftIO (ReaderC r m) where
withRunInIO inner = ReaderC $ \ r -> withRunInIO $ \ run -> inner (run . runReader r)
{-# INLINE withRunInIO #-}
patrickt marked this conversation as resolved.
Show resolved Hide resolved