Skip to content

Commit

Permalink
Merge pull request #294 from fused-effects/alg
Browse files Browse the repository at this point in the history
Rename eff to alg
  • Loading branch information
patrickt committed Oct 24, 2019
2 parents f4fc546 + 32aa66d commit d1079e8
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 143 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

## Backwards-incompatible changes

- Renames the `Carrier` class to `Algebra`, and moved the responsibilities of `Control.Carrier` to `Control.Algebra`. This makes the library more consistent with the literature and encourages a style of naming that focuses on morphisms rather than objects.
- Renames the `Carrier` class to `Algebra` and its `eff` method to `alg`, and moved the responsibilities of `Control.Carrier` to `Control.Algebra`. This makes the library more consistent with the literature and encourages a style of naming that focuses on morphisms rather than objects.

- Fixes unlawful behaviour in the `Applicative` instance for `ErrorC`, which had different behaviour between `<*>` and `ap` in the presence of a divergent rhs. In order to accomplish this, `ErrorC` has been defined as a wrapper around `Control.Monad.Trans.Except.ExceptT`. ([#228](https://github.com/fused-effects/fused-effects/pull/228))

Expand Down
2 changes: 1 addition & 1 deletion benchmark/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ instance Monad (Cod m) where
Cod a >>= f = Cod (\ k -> a (runCod k . f))

instance (Algebra sig m, Effect sig) => Algebra sig (Cod m) where
eff op = Cod (\ k -> eff (handle (Identity ()) (runCod (pure . Identity) . runIdentity) op) >>= k . runIdentity)
alg op = Cod (\ k -> alg (handle (Identity ()) (runCod (pure . Identity) . runIdentity) op) >>= k . runIdentity)
14 changes: 7 additions & 7 deletions docs/defining_effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ Following from the above section, we can define a carrier for the `Teletype` eff
newtype TeletypeIOC m a = TeletypeIOC { runTeletypeIOC :: m a }

instance (Algebra sig m, MonadIO m) => Algebra (Teletype :+: sig) (TeletypeIOC m) where
eff (L (Read k)) = TeletypeIOC (liftIO getLine >>= runTeletypeIOC . k)
eff (L (Write s k)) = TeletypeIOC (liftIO (putStrLn s) >> runTeletypeIOC k)
eff (R other) = TeletypeIOC (eff (handleCoercible other))
alg (L (Read k)) = TeletypeIOC (liftIO getLine >>= runTeletypeIOC . k)
alg (L (Write s k)) = TeletypeIOC (liftIO (putStrLn s) >> runTeletypeIOC k)
alg (R other) = TeletypeIOC (alg (handleCoercible other))
```

Here, `eff` is responsible for handling effectful computations. Since the `Algebra` instance handles a sum (`:+:`) of `Teletype` and the remaining signature, `eff` has two parts: a handler for `Teletype`, and a handler for teletype effects that might be embedded inside other effects in the signature.
Here, `alg` is responsible for handling effectful computations. Since the `Algebra` instance handles a sum (`:+:`) of `Teletype` and the remaining signature, `alg` has two parts: a handler for `Teletype`, and a handler for teletype effects that might be embedded inside other effects in the signature.

In this case, since the `Teletype` carrier is just a thin wrapper around the underlying computation, we can use `handleCoercible` to handle any embedded `TeletypeIOC` carriers by simply mapping `coerce` over them.

Expand All @@ -96,7 +96,7 @@ This allows us to use `liftIO` directly on the carrier itself, instead of only i

```haskell
instance (MonadIO m, Algebra sig m) => Algebra (Teletype :+: sig) (TeletypeIOC m) where
eff (L (Read k)) = liftIO getLine >>= k
eff (L (Write s k)) = liftIO (putStrLn s) >> k
eff (R other) = TeletypeIOC (eff (handleCoercible other))
alg (L (Read k)) = liftIO getLine >>= k
alg (L (Write s k)) = liftIO (putStrLn s) >> k
alg (R other) = TeletypeIOC (alg (handleCoercible other))
```
2 changes: 1 addition & 1 deletion examples/Inference.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ newtype HasEnv env m a = HasEnv { runHasEnv :: m a }

-- | The 'Carrier' instance for 'HasEnv' simply delegates all effects to the underlying carrier.
instance Algebra sig m => Algebra sig (HasEnv env m) where
eff = HasEnv . eff . handleCoercible
alg = HasEnv . alg . handleCoercible
6 changes: 3 additions & 3 deletions examples/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ newtype ParseC m a = ParseC { runParseC :: StateC String m a }
deriving newtype (Alternative, Applicative, Functor, Monad)

instance (Alternative m, Algebra sig m, Effect sig) => Algebra (Symbol :+: sig) (ParseC m) where
eff (L (Satisfy p k)) = do
alg (L (Satisfy p k)) = do
input <- ParseC get
case input of
c:cs | p c -> ParseC (put cs) *> k c
_ -> empty
eff (R other) = ParseC (eff (R (handleCoercible other)))
{-# INLINE eff #-}
alg (R other) = ParseC (alg (R (handleCoercible other)))
{-# INLINE alg #-}


expr :: (Alternative m, Has Cut sig m, Has Symbol sig m) => m Int
Expand Down
18 changes: 9 additions & 9 deletions examples/ReinterpretLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ instance
-- ... the 'LogStdoutC m' monad can interpret 'Log String :+: sig' effects
=> Algebra (Log String :+: sig) (LogStdoutC m) where

eff :: (Log String :+: sig) (LogStdoutC m) a -> LogStdoutC m a
eff = \case
alg :: (Log String :+: sig) (LogStdoutC m) a -> LogStdoutC m a
alg = \case
L (Log message k) ->
LogStdoutC $ do
liftIO (putStrLn message)
runLogStdout k

R other ->
LogStdoutC (eff (hmap runLogStdout other))
LogStdoutC (alg (hmap runLogStdout other))

-- The 'LogStdoutC' runner.
runLogStdout ::
Expand All @@ -168,18 +168,18 @@ instance
-- effects
=> Algebra (Log s :+: sig) (ReinterpretLogC s t m) where

eff ::
alg ::
(Log s :+: sig) (ReinterpretLogC s t m) a
-> ReinterpretLogC s t m a
eff = \case
alg = \case
L (Log s k) ->
ReinterpretLogC $ do
f <- ask @(s -> t)
log (f s)
unReinterpretLogC k

R other ->
ReinterpretLogC (eff (R (handleCoercible other)))
ReinterpretLogC (alg (R (handleCoercible other)))

-- The 'ReinterpretLogC' runner.
reinterpretLog ::
Expand All @@ -206,17 +206,17 @@ instance
-- effects
=> Algebra (Log s :+: sig) (CollectLogMessagesC s m) where

eff ::
alg ::
(Log s :+: sig) (CollectLogMessagesC s m) a
-> CollectLogMessagesC s m a
eff = \case
alg = \case
L (Log s k) ->
CollectLogMessagesC $ do
tell [s]
unCollectLogMessagesC k

R other ->
CollectLogMessagesC (eff (R (handleCoercible other)))
CollectLogMessagesC (alg (R (handleCoercible other)))

-- The 'CollectLogMessagesC' runner.
collectLogMessages ::
Expand Down
12 changes: 6 additions & 6 deletions examples/Teletype.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ newtype TeletypeIOC m a = TeletypeIOC { runTeletypeIOC :: m a }
deriving newtype (Applicative, Functor, Monad, MonadIO)

instance (MonadIO m, Algebra sig m) => Algebra (Teletype :+: sig) (TeletypeIOC m) where
eff (L (Read k)) = liftIO getLine >>= k
eff (L (Write s k)) = liftIO (putStrLn s) >> k
eff (R other) = TeletypeIOC (eff (handleCoercible other))
alg (L (Read k)) = liftIO getLine >>= k
alg (L (Write s k)) = liftIO (putStrLn s) >> k
alg (R other) = TeletypeIOC (alg (handleCoercible other))


runTeletypeRet :: [String] -> TeletypeRetC m a -> m ([String], ([String], a))
Expand All @@ -59,10 +59,10 @@ newtype TeletypeRetC m a = TeletypeRetC { runTeletypeRetC :: StateC [String] (Wr
deriving newtype (Applicative, Functor, Monad)

instance (Algebra sig m, Effect sig) => Algebra (Teletype :+: sig) (TeletypeRetC m) where
eff (L (Read k)) = do
alg (L (Read k)) = do
i <- TeletypeRetC get
case i of
[] -> k ""
h:t -> TeletypeRetC (put t) *> k h
eff (L (Write s k)) = TeletypeRetC (tell [s]) *> k
eff (R other) = TeletypeRetC (eff (R (R (handleCoercible other))))
alg (L (Write s k)) = TeletypeRetC (tell [s]) *> k
alg (R other) = TeletypeRetC (alg (R (R (handleCoercible other))))
106 changes: 53 additions & 53 deletions src/Control/Algebra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ import Data.List.NonEmpty (NonEmpty)
import qualified Data.Semigroup as S
import Data.Tuple (swap)

-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'eff' method.
-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'alg' method.
--
-- @since 1.0.0.0
class (HFunctor sig, Monad m) => Algebra sig m | m -> sig where
-- | Construct a value in the carrier for an effect signature (typically a sum of a handled effect and any remaining effects).
eff :: sig m a -> m a
alg :: sig m a -> m a

-- | @m@ is a carrier for @sig@ containing @eff@.
--
Expand All @@ -63,56 +63,56 @@ type Has eff sig m = (Members eff sig, Algebra sig m)

-- | Construct a request for an effect to be interpreted by some handler later on.
send :: (Member eff sig, Algebra sig m) => eff m a -> m a
send = eff . inj
send = alg . inj
{-# INLINE send #-}


-- base

instance Algebra (Lift IO) IO where
eff = join . unLift
alg = join . unLift

instance Algebra Pure Identity where
eff v = case v of {}
alg v = case v of {}

instance Algebra Choose NonEmpty where
eff (Choose m) = m True S.<> m False
alg (Choose m) = m True S.<> m False

instance Algebra Empty Maybe where
eff Empty = Nothing
alg Empty = Nothing

instance Algebra (Error e) (Either e) where
eff (L (Throw e)) = Left e
eff (R (Catch m h k)) = either (k <=< h) k m
alg (L (Throw e)) = Left e
alg (R (Catch m h k)) = either (k <=< h) k m

instance Algebra (Reader r) ((->) r) where
eff (Ask k) r = k r r
eff (Local f m k) r = k (m (f r)) r
alg (Ask k) r = k r r
alg (Local f m k) r = k (m (f r)) r

instance Algebra NonDet [] where
eff (L Empty) = []
eff (R (Choose k)) = k True ++ k False
alg (L Empty) = []
alg (R (Choose k)) = k True ++ k False

instance Monoid w => Algebra (Writer w) ((,) w) where
eff (Tell w (w', k)) = (mappend w w', k)
eff (Listen (w, a) k) = let (w', a') = k w a in (mappend w w', a')
eff (Censor f (w, a) k) = let (w', a') = k a in (mappend (f w) w', a')
alg (Tell w (w', k)) = (mappend w w', k)
alg (Listen (w, a) k) = let (w', a') = k w a in (mappend w w', a')
alg (Censor f (w, a) k) = let (w', a') = k a in (mappend (f w) w', a')


-- transformers

instance (Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (Except.ExceptT e m) where
eff (L (L (Throw e))) = Except.throwE e
eff (L (R (Catch m h k))) = Except.catchE m h >>= k
eff (R other) = Except.ExceptT $ eff (handle (Right ()) (either (pure . Left) Except.runExceptT) other)
alg (L (L (Throw e))) = Except.throwE e
alg (L (R (Catch m h k))) = Except.catchE m h >>= k
alg (R other) = Except.ExceptT $ alg (handle (Right ()) (either (pure . Left) Except.runExceptT) other)

instance Algebra sig m => Algebra sig (Identity.IdentityT m) where
eff = Identity.IdentityT . eff . handleCoercible
alg = Identity.IdentityT . alg . handleCoercible

instance Algebra sig m => Algebra (Reader r :+: sig) (Reader.ReaderT r m) where
eff (L (Ask k)) = Reader.ask >>= k
eff (L (Local f m k)) = Reader.local f m >>= k
eff (R other) = Reader.ReaderT $ \ r -> eff (hmap (flip Reader.runReaderT r) other)
alg (L (Ask k)) = Reader.ask >>= k
alg (L (Local f m k)) = Reader.local f m >>= k
alg (R other) = Reader.ReaderT $ \ r -> alg (hmap (flip Reader.runReaderT r) other)

newtype RWSTF w s a = RWSTF { unRWSTF :: (a, s, w) }
deriving (Functor)
Expand All @@ -122,43 +122,43 @@ toRWSTF w (a, s, w') = RWSTF (a, s, mappend w w')
{-# INLINE toRWSTF #-}

instance (Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: Writer w :+: State s :+: sig) (RWS.Lazy.RWST r w s m) where
eff (L (Ask k)) = RWS.Lazy.ask >>= k
eff (L (Local f m k)) = RWS.Lazy.local f m >>= k
eff (R (L (Tell w k))) = RWS.Lazy.tell w *> k
eff (R (L (Listen m k))) = RWS.Lazy.listen m >>= uncurry (flip k)
eff (R (L (Censor f m k))) = RWS.Lazy.censor f m >>= k
eff (R (R (L (Get k)))) = RWS.Lazy.get >>= k
eff (R (R (L (Put s k)))) = RWS.Lazy.put s *> k
eff (R (R (R other))) = RWS.Lazy.RWST $ \ r s -> unRWSTF <$> eff (handle (RWSTF ((), s, mempty)) (\ (RWSTF (x, s, w)) -> toRWSTF w <$> RWS.Lazy.runRWST x r s) other)
alg (L (Ask k)) = RWS.Lazy.ask >>= k
alg (L (Local f m k)) = RWS.Lazy.local f m >>= k
alg (R (L (Tell w k))) = RWS.Lazy.tell w *> k
alg (R (L (Listen m k))) = RWS.Lazy.listen m >>= uncurry (flip k)
alg (R (L (Censor f m k))) = RWS.Lazy.censor f m >>= k
alg (R (R (L (Get k)))) = RWS.Lazy.get >>= k
alg (R (R (L (Put s k)))) = RWS.Lazy.put s *> k
alg (R (R (R other))) = RWS.Lazy.RWST $ \ r s -> unRWSTF <$> alg (handle (RWSTF ((), s, mempty)) (\ (RWSTF (x, s, w)) -> toRWSTF w <$> RWS.Lazy.runRWST x r s) other)

instance (Algebra sig m, Effect sig, Monoid w) => Algebra (Reader r :+: Writer w :+: State s :+: sig) (RWS.Strict.RWST r w s m) where
eff (L (Ask k)) = RWS.Strict.ask >>= k
eff (L (Local f m k)) = RWS.Strict.local f m >>= k
eff (R (L (Tell w k))) = RWS.Strict.tell w *> k
eff (R (L (Listen m k))) = RWS.Strict.listen m >>= uncurry (flip k)
eff (R (L (Censor f m k))) = RWS.Strict.censor f m >>= k
eff (R (R (L (Get k)))) = RWS.Strict.get >>= k
eff (R (R (L (Put s k)))) = RWS.Strict.put s *> k
eff (R (R (R other))) = RWS.Strict.RWST $ \ r s -> unRWSTF <$> eff (handle (RWSTF ((), s, mempty)) (\ (RWSTF (x, s, w)) -> toRWSTF w <$> RWS.Strict.runRWST x r s) other)
alg (L (Ask k)) = RWS.Strict.ask >>= k
alg (L (Local f m k)) = RWS.Strict.local f m >>= k
alg (R (L (Tell w k))) = RWS.Strict.tell w *> k
alg (R (L (Listen m k))) = RWS.Strict.listen m >>= uncurry (flip k)
alg (R (L (Censor f m k))) = RWS.Strict.censor f m >>= k
alg (R (R (L (Get k)))) = RWS.Strict.get >>= k
alg (R (R (L (Put s k)))) = RWS.Strict.put s *> k
alg (R (R (R other))) = RWS.Strict.RWST $ \ r s -> unRWSTF <$> alg (handle (RWSTF ((), s, mempty)) (\ (RWSTF (x, s, w)) -> toRWSTF w <$> RWS.Strict.runRWST x r s) other)

instance (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (State.Lazy.StateT s m) where
eff (L (Get k)) = State.Lazy.get >>= k
eff (L (Put s k)) = State.Lazy.put s *> k
eff (R other) = State.Lazy.StateT $ \ s -> swap <$> eff (handle (s, ()) (\ (s, x) -> swap <$> State.Lazy.runStateT x s) other)
alg (L (Get k)) = State.Lazy.get >>= k
alg (L (Put s k)) = State.Lazy.put s *> k
alg (R other) = State.Lazy.StateT $ \ s -> swap <$> alg (handle (s, ()) (\ (s, x) -> swap <$> State.Lazy.runStateT x s) other)

instance (Algebra sig m, Effect sig) => Algebra (State s :+: sig) (State.Strict.StateT s m) where
eff (L (Get k)) = State.Strict.get >>= k
eff (L (Put s k)) = State.Strict.put s *> k
eff (R other) = State.Strict.StateT $ \ s -> swap <$> eff (handle (s, ()) (\ (s, x) -> swap <$> State.Strict.runStateT x s) other)
alg (L (Get k)) = State.Strict.get >>= k
alg (L (Put s k)) = State.Strict.put s *> k
alg (R other) = State.Strict.StateT $ \ s -> swap <$> alg (handle (s, ()) (\ (s, x) -> swap <$> State.Strict.runStateT x s) other)

instance (Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (Writer.Lazy.WriterT w m) where
eff (L (Tell w k)) = Writer.Lazy.tell w *> k
eff (L (Listen m k)) = Writer.Lazy.listen m >>= uncurry (flip k)
eff (L (Censor f m k)) = Writer.Lazy.censor f m >>= k
eff (R other) = Writer.Lazy.WriterT $ swap <$> eff (handle (mempty, ()) (\ (s, x) -> swap . fmap (mappend s) <$> Writer.Lazy.runWriterT x) other)
alg (L (Tell w k)) = Writer.Lazy.tell w *> k
alg (L (Listen m k)) = Writer.Lazy.listen m >>= uncurry (flip k)
alg (L (Censor f m k)) = Writer.Lazy.censor f m >>= k
alg (R other) = Writer.Lazy.WriterT $ swap <$> alg (handle (mempty, ()) (\ (s, x) -> swap . fmap (mappend s) <$> Writer.Lazy.runWriterT x) other)

instance (Algebra sig m, Effect sig, Monoid w) => Algebra (Writer w :+: sig) (Writer.Strict.WriterT w m) where
eff (L (Tell w k)) = Writer.Strict.tell w *> k
eff (L (Listen m k)) = Writer.Strict.listen m >>= uncurry (flip k)
eff (L (Censor f m k)) = Writer.Strict.censor f m >>= k
eff (R other) = Writer.Strict.WriterT $ swap <$> eff (handle (mempty, ()) (\ (s, x) -> swap . fmap (mappend s) <$> Writer.Strict.runWriterT x) other)
alg (L (Tell w k)) = Writer.Strict.tell w *> k
alg (L (Listen m k)) = Writer.Strict.listen m >>= uncurry (flip k)
alg (L (Censor f m k)) = Writer.Strict.censor f m >>= k
alg (R other) = Writer.Strict.WriterT $ swap <$> alg (handle (mempty, ()) (\ (s, x) -> swap . fmap (mappend s) <$> Writer.Strict.runWriterT x) other)
6 changes: 3 additions & 3 deletions src/Control/Carrier/Choose/Church.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ instance MonadTrans ChooseC where
{-# INLINE lift #-}

instance (Algebra sig m, Effect sig) => Algebra (Choose :+: sig) (ChooseC m) where
eff (L (Choose k)) = ChooseC $ \ fork leaf -> fork (runChoose fork leaf (k True)) (runChoose fork leaf (k False))
eff (R other) = ChooseC $ \ fork leaf -> eff (handle (pure ()) (runChoose (liftA2 (<|>)) (runChoose (liftA2 (<|>)) (pure . pure))) other) >>= runChoose fork leaf
{-# INLINE eff #-}
alg (L (Choose k)) = ChooseC $ \ fork leaf -> fork (runChoose fork leaf (k True)) (runChoose fork leaf (k False))
alg (R other) = ChooseC $ \ fork leaf -> alg (handle (pure ()) (runChoose (liftA2 (<|>)) (runChoose (liftA2 (<|>)) (pure . pure))) other) >>= runChoose fork leaf
{-# INLINE alg #-}
10 changes: 5 additions & 5 deletions src/Control/Carrier/Cull/Church.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ instance MonadTrans CullC where
{-# INLINE lift #-}

instance (Algebra sig m, Effect sig) => Algebra (Cull :+: NonDet :+: sig) (CullC m) where
eff (L (Cull (CullC m) k)) = CullC (local (const True) m) >>= k
eff (R (L (L Empty))) = empty
eff (R (L (R (Choose k)))) = k True <|> k False
eff (R (R other)) = CullC (eff (R (R (handleCoercible other))))
{-# INLINE eff #-}
alg (L (Cull (CullC m) k)) = CullC (local (const True) m) >>= k
alg (R (L (L Empty))) = empty
alg (R (L (R (Choose k)))) = k True <|> k False
alg (R (R other)) = CullC (alg (R (R (handleCoercible other))))
{-# INLINE alg #-}
12 changes: 6 additions & 6 deletions src/Control/Carrier/Cut/Church.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ instance MonadTrans CutC where
{-# INLINE lift #-}

instance (Algebra sig m, Effect sig) => Algebra (Cut :+: NonDet :+: sig) (CutC m) where
eff (L Cutfail) = CutC $ \ _ _ fail -> fail
eff (L (Call m k)) = CutC $ \ cons nil fail -> runCut (\ a as -> runCut cons as fail (k a)) nil nil m
eff (R (L (L Empty))) = empty
eff (R (L (R (Choose k)))) = k True <|> k False
eff (R (R other)) = CutC $ \ cons nil fail -> eff (handle (pure ()) (runCut (fmap . (<|>)) (pure empty) (pure cutfail)) other) >>= runCut cons nil fail
{-# INLINE eff #-}
alg (L Cutfail) = CutC $ \ _ _ fail -> fail
alg (L (Call m k)) = CutC $ \ cons nil fail -> runCut (\ a as -> runCut cons as fail (k a)) nil nil m
alg (R (L (L Empty))) = empty
alg (R (L (R (Choose k)))) = k True <|> k False
alg (R (R other)) = CutC $ \ cons nil fail -> alg (handle (pure ()) (runCut (fmap . (<|>)) (pure empty) (pure cutfail)) other) >>= runCut cons nil fail
{-# INLINE alg #-}
6 changes: 3 additions & 3 deletions src/Control/Carrier/Empty/Maybe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ instance Fail.MonadFail m => Fail.MonadFail (EmptyC m) where
{-# INLINE fail #-}

instance (Algebra sig m, Effect sig) => Algebra (Empty :+: sig) (EmptyC m) where
eff (L Empty) = EmptyC (MaybeT (pure Nothing))
eff (R other) = EmptyC (MaybeT (eff (handle (Just ()) (maybe (pure Nothing) runEmpty) other)))
{-# INLINE eff #-}
alg (L Empty) = EmptyC (MaybeT (pure Nothing))
alg (R other) = EmptyC (MaybeT (alg (handle (Just ()) (maybe (pure Nothing) runEmpty) other)))
{-# INLINE alg #-}
4 changes: 2 additions & 2 deletions src/Control/Carrier/Error/Either.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ instance (Alternative m, Monad m) => Alternative (ErrorC e m) where
instance (Alternative m, Monad m) => MonadPlus (ErrorC e m)

instance (Algebra sig m, Effect sig) => Algebra (Error e :+: sig) (ErrorC e m) where
eff = ErrorC . eff . handleCoercible
{-# INLINE eff #-}
alg = ErrorC . alg . handleCoercible
{-# INLINE alg #-}
4 changes: 2 additions & 2 deletions src/Control/Carrier/Fail/Either.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ instance (Algebra sig m, Effect sig) => Fail.MonadFail (FailC m) where
{-# INLINE fail #-}

instance (Algebra sig m, Effect sig) => Algebra (Fail :+: sig) (FailC m) where
eff = FailC . eff . handleCoercible
{-# INLINE eff #-}
alg = FailC . alg . handleCoercible
{-# INLINE alg #-}
Loading

0 comments on commit d1079e8

Please sign in to comment.