-
Notifications
You must be signed in to change notification settings - Fork 53
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
Separate carrier and effect modules #204
Merged
Merged
Changes from all commits
Commits
Show all changes
113 commits
Select commit
Hold shift + click to select a range
9f9cce4
Merge branch '🔥-random' into separate-carrier-and-effect-modules
robrix 35b7563
Rename Control.Effect.Carrier to Control.Carrier.
robrix bd536bb
Move the lazy & strict state carriers under Control.Carrier.State.
robrix 4234fa7
Rename Control.Effect.State.Internal to Control.Effect.State.
robrix 7aa358b
Combine some re-exports.
robrix 03af9be
Move Control.Effect.Interpret to Control.Carrier.Interpret.
robrix 7b8396d
Re-export HFunctor from Control.Effect.
robrix 78182bf
Move Control.Carrier to Control.Carrier.Class.
robrix 88a513a
Reintroduce Control.Carrier for convenient imports.
robrix 18d38fb
Rename Control.Effect.Interpose to Control.Carrier.Interpose.
robrix 75acb21
Stub in a module for the ignoring Trace carrier.
robrix e43af18
Move TraceByIgnoringC &c. into Control.Carrier.Trace.Ignoring.
robrix 47681cd
Rename runTraceByIgnoring to runTrace.
robrix 479500e
Rename TraceByIgnoringC to TraceC.
robrix 7b27ec2
Move TraceByPrintingC into a new module.
robrix 133883d
Rename TraceByPrintingC to TraceC.
robrix ab00ad8
Rename runTraceByPrinting to runTrace.
robrix e2b81ea
Move TraceByReturningC into its own module.
robrix 8b47c87
Rename TraceByReturningC to TraceC.
robrix 915a66a
Rename runTraceByReturning to runTrace.
robrix 43b89e1
Add the doctests setup boilerplate.
robrix ad8e644
Simplify the language extensions for Control.Effect.Trace.
robrix dcc358e
There are no tests in this file.
robrix 9e24d62
Move ReaderC into its own module.
robrix 49555e7
Move ErrorC into its own module.
robrix 2775984
Add a missing import for the doctests.
robrix ff471aa
Move WriterC into its own module.
robrix 443fac2
Don’t rename the module.
robrix 2adc771
Tidy up the language extensions.
robrix b7f3d89
Move ResumableC into its own module.
robrix 027c7f8
Move SomeError into Control.Carrier.Resumable.Either.
robrix ef2277c
Move Control.Carrier.Error to Control.Carrier.Error.Either.
robrix 4b858e0
Move ChooseC into its own module.
robrix 4ce3c63
Rename Control.Effect.NonDet to Control.Carrier.NonDet.Church.
robrix 0975f43
Re-export Carrier/Member/run from the carrier modules only.
robrix 1d03a98
:fire: OnceC.
robrix 56b8e3b
Move CullC into its own module.
robrix 24f59e4
Move CutC into its own module.
robrix 2c588fd
Move EmptyC into its own module.
robrix 5976f52
Correct a doctest.
robrix 2fc6329
Move FailC into its own module.
robrix bc3d9fc
Move FreshC into its own module.
robrix 6481c42
Rename the Resumable carrier module.
robrix 9cb5b52
Move ResumableWithC into its own module & rename it.
robrix a5ec56a
Move ResourceC into its own module.
robrix ed5c43f
Merge branch '🔥-random' into separate-carrier-and-effect-modules
robrix 2764c1a
Move LiftC into its own module.
robrix c4bbc55
Move PureC into its own module.
robrix 7d383af
Merge branch '🔥-deprecations' into separate-carrier-and-effect-modules
robrix 5d47ab0
Spacing.
robrix 22ebc73
Move HFunctor & Effect into their own module.
robrix f7938e9
Move handleCoercible into Control.Effect.Class.
robrix e32881b
Merge branch 'the-great-divide' into separate-carrier-and-effect-modules
robrix 9f5bda2
Add the abort smart constructor back in.
robrix 6fc8d2a
Whoops.
robrix 50c0d4a
:fire: a redundant import.
robrix 034313a
Merge branch 'the-great-divide' into separate-carrier-and-effect-modules
robrix 9f0c274
Add a note about removing OnceC.
robrix 12fc819
Note that the carriers have all moved.
robrix 51c4139
Qualify the re-export of MonadFail.
robrix f54d246
Merge branch 'master' into separate-carrier-and-effect-modules
robrix 2172610
Merge branch 'master' into separate-carrier-and-effect-modules
robrix 35beaf4
Correct the imports in the benchmarks.
robrix 32fb382
Correct the imports in the examples.
robrix 376be33
Correct the imports in the tests.
robrix d46d29f
Get the doctests passing again.
robrix e4bf415
Rename the cull carrier module to .Church.
robrix 33102e5
Rename the Empty carrier module to .Direct.
robrix 651cb10
Revert "Rename the Empty carrier module to .Direct."
robrix 75e0b13
Rename the Fail carrier module to .Either.
robrix 7e41347
Re-export MonadFail from the Fail effect module.
robrix 2a91353
Handle Fail in the Carrier instance.
robrix 61e047a
:fire: a redundant import.
robrix e3cd41e
Re-export a bunch of stuff from Control.Carrier.
robrix 27dd510
Import Control.Carrier in general.
robrix 6e175f1
Don’t re-export anything from Control.Carrier.Class.
robrix 1cd444b
Move the Carrier instance for PureC into Control.Carrier.Pure.
robrix 4d3d85d
Tidy up the language extensions in Control.Carrier.Class.
robrix c68e311
Move send into Control.Effect.Sum.
robrix 822620f
Rename Control.Carrier.Resumable.Abort to .Either.
robrix d8e37b1
:fire: a redundant file.
robrix 41bc7c3
Reintroduce Control.Effect.NonDet, re-exporting Choose, Empty, & Alte…
robrix d10d041
Rename abort to empty.
robrix dc07eb4
Rename choose to <|>.
robrix aef5e94
Combine the headings for the nondet effects.
robrix 1f3f887
Move oneOf into Control.Effect.NonDet.
robrix ef2850a
Use the #. trick to optimize oneOf.
robrix 2b760ba
:memo: #.
robrix 64640e2
Introduce foldMapA to map a Foldable container into an Alternative co…
robrix 7184084
Define oneOf using foldMapA.
robrix 059d92f
:memo: foldMapA.
robrix e42e999
Define a guard operation for Empty effects.
robrix 193b58a
Add a note about foldMapA to the changelog.
robrix 36adb35
:memo: guard.
robrix c73d97c
Re-export the Alternative-based definition of guard.
robrix a60ee75
Define an Alternative module giving implementations in terms of Alter…
robrix 1ce0655
:memo: Control.Effect.Alternative.
robrix 53aa8a9
:memo: Control.Effect.NonDet.
robrix 700fe3c
Define a Choosing newtype.
robrix de31527
Define a Semigroup instance for Choosing.
robrix 3ff5d28
Define a Monoid instance for Choosing.
robrix 595cbcb
Define the Control.Effect.NonDet interfaces in terms of the effects.
robrix 358c54d
Define oneOf & foldMapA via the Alternative interfaces.
robrix f65b114
Revert "Define oneOf & foldMapA via the Alternative interfaces."
robrix 6b4a0be
Note the addition of Control.Effect.Alternative in the changelog.
robrix 744d6f9
Revert "Note the addition of Control.Effect.Alternative in the change…
robrix 0c70e38
Revert "Define the Control.Effect.NonDet interfaces in terms of the e…
robrix f49bc6d
Revert ":memo: Control.Effect.NonDet."
robrix c25bf81
Revert ":memo: Control.Effect.Alternative."
robrix db163b3
Revert "Define an Alternative module giving implementations in terms …
robrix 3e2ebb9
:fire: a redundant import.
robrix de4e147
Use a qualified import of Semigroup to accommodate 8.2.
robrix 031e95d
Explicitly give the canonical definition of mappend.
robrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Control.Carrier | ||
( -- * Re-exports | ||
module Control.Carrier.Class | ||
, module Control.Effect.Class | ||
, module Control.Effect.Sum | ||
, run | ||
) where | ||
|
||
import Control.Carrier.Class | ||
import Control.Carrier.Pure | ||
import Control.Effect.Class | ||
import Control.Effect.Sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{-# LANGUAGE DeriveTraversable, FlexibleInstances, MultiParamTypeClasses, RankNTypes, TypeOperators, UndecidableInstances #-} | ||
module Control.Carrier.Choose.Church | ||
( -- * Choose effect | ||
module Control.Effect.Choose | ||
-- * Choose carrier | ||
, runChoose | ||
, ChooseC(..) | ||
-- * Re-exports | ||
, Carrier | ||
, Member | ||
, run | ||
) where | ||
|
||
import Control.Applicative as Alt ((<|>), liftA2) | ||
import Control.Carrier | ||
import Control.Effect.Choose | ||
import Control.Monad (join) | ||
import qualified Control.Monad.Fail as Fail | ||
import Control.Monad.Fix | ||
import Control.Monad.IO.Class | ||
import Control.Monad.Trans.Class | ||
import Data.Maybe (fromJust) | ||
import Prelude hiding (fail) | ||
|
||
runChoose :: (m b -> m b -> m b) -> (a -> m b) -> ChooseC m a -> m b | ||
runChoose fork leaf m = runChooseC m fork leaf | ||
|
||
-- | A carrier for 'Choose' effects based on Ralf Hinze’s design described in [Deriving Backtracking Monad Transformers](https://www.cs.ox.ac.uk/ralf.hinze/publications/#P12). | ||
newtype ChooseC m a = ChooseC | ||
{ -- | A higher-order function receiving two continuations, respectively implementing choice and 'pure'. | ||
runChooseC :: forall b . (m b -> m b -> m b) -> (a -> m b) -> m b | ||
} | ||
deriving (Functor) | ||
|
||
instance Applicative (ChooseC m) where | ||
pure a = ChooseC (\ _ leaf -> leaf a) | ||
{-# INLINE pure #-} | ||
ChooseC f <*> ChooseC a = ChooseC $ \ fork leaf -> | ||
f fork (\ f' -> a fork (leaf . f')) | ||
{-# INLINE (<*>) #-} | ||
|
||
instance Monad (ChooseC m) where | ||
ChooseC a >>= f = ChooseC $ \ fork leaf -> | ||
a fork (runChoose fork leaf . f) | ||
{-# INLINE (>>=) #-} | ||
|
||
instance Fail.MonadFail m => Fail.MonadFail (ChooseC m) where | ||
fail s = lift (Fail.fail s) | ||
{-# INLINE fail #-} | ||
|
||
instance MonadFix m => MonadFix (ChooseC m) where | ||
mfix f = ChooseC $ \ fork leaf -> | ||
mfix (runChoose (liftA2 Fork) (pure . Leaf) | ||
. f . fromJust . fold (Alt.<|>) Just) | ||
>>= fold fork leaf | ||
{-# INLINE mfix #-} | ||
|
||
instance MonadIO m => MonadIO (ChooseC m) where | ||
liftIO io = lift (liftIO io) | ||
{-# INLINE liftIO #-} | ||
|
||
instance MonadTrans ChooseC where | ||
lift m = ChooseC (\ _ leaf -> m >>= leaf) | ||
{-# INLINE lift #-} | ||
|
||
instance (Carrier sig m, Effect sig) => Carrier (Choose :+: sig) (ChooseC m) where | ||
eff (L (Choose k)) = ChooseC $ \ fork leaf -> fork (runChooseC (k True) fork leaf) (runChooseC (k False) fork leaf) | ||
eff (R other) = ChooseC $ \ fork leaf -> eff (handle (Leaf ()) (fmap join . traverse (runChoose (liftA2 Fork) (pure . Leaf))) other) >>= fold fork leaf | ||
{-# INLINE eff #-} | ||
|
||
|
||
data BinaryTree a = Leaf a | Fork (BinaryTree a) (BinaryTree a) | ||
deriving (Eq, Foldable, Functor, Ord, Show, Traversable) | ||
|
||
instance Applicative BinaryTree where | ||
pure = Leaf | ||
{-# INLINE pure #-} | ||
f <*> a = fold Fork (<$> a) f | ||
{-# INLINE (<*>) #-} | ||
|
||
instance Monad BinaryTree where | ||
a >>= f = fold Fork f a | ||
{-# INLINE (>>=) #-} | ||
|
||
|
||
fold :: (b -> b -> b) -> (a -> b) -> BinaryTree a -> b | ||
fold fork leaf = go where | ||
go (Leaf a) = leaf a | ||
go (Fork a b) = fork (go a) (go b) | ||
{-# INLINE fold #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{-# LANGUAGE FunctionalDependencies #-} | ||
module Control.Carrier.Class | ||
( Carrier(..) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of exporting |
||
) where | ||
|
||
import Control.Effect.Class | ||
|
||
-- | The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the 'eff' method. | ||
class (HFunctor sig, Monad m) => Carrier 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} | ||
module Control.Carrier.Cull.Church | ||
( -- * Cull effect | ||
module Control.Effect.Cull | ||
-- * NonDet effects | ||
, module Control.Effect.NonDet | ||
-- * Cull carrier | ||
, runCull | ||
, CullC(..) | ||
-- * Re-exports | ||
, Carrier | ||
, Member | ||
, run | ||
) where | ||
|
||
import Control.Carrier | ||
import Control.Carrier.NonDet.Church | ||
import Control.Carrier.Reader | ||
import Control.Effect.Cull | ||
import Control.Effect.NonDet | ||
import Control.Monad (MonadPlus(..)) | ||
import qualified Control.Monad.Fail as Fail | ||
import Control.Monad.Fix | ||
import Control.Monad.IO.Class | ||
import Control.Monad.Trans.Class | ||
|
||
-- | Run a 'Cull' effect. Branches outside of any 'cull' block will not be pruned. | ||
-- | ||
-- prop> run (runNonDet (runCull (pure a <|> pure b))) === [a, b] | ||
runCull :: Alternative m => CullC m a -> m a | ||
runCull (CullC m) = runNonDetC (runReader False m) (<|>) pure empty | ||
|
||
newtype CullC m a = CullC { runCullC :: ReaderC Bool (NonDetC m) a } | ||
deriving (Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO) | ||
|
||
instance Alternative (CullC m) where | ||
empty = CullC empty | ||
{-# INLINE empty #-} | ||
l <|> r = CullC $ ReaderC $ \ cull -> | ||
if cull then | ||
NonDetC $ \ fork leaf nil -> | ||
runNonDetC (runReader cull (runCullC l)) fork leaf (runNonDetC (runReader cull (runCullC r)) fork leaf nil) | ||
else | ||
runReader cull (runCullC l) <|> runReader cull (runCullC r) | ||
{-# INLINE (<|>) #-} | ||
|
||
instance MonadPlus (CullC m) | ||
|
||
instance MonadTrans CullC where | ||
lift = CullC . lift . lift | ||
{-# INLINE lift #-} | ||
|
||
instance (Carrier sig m, Effect sig) => Carrier (Cull :+: Empty :+: Choose :+: sig) (CullC m) where | ||
eff (L (Cull m k)) = CullC (local (const True) (runCullC m)) >>= k | ||
eff (R (L Empty)) = empty | ||
eff (R (R (L (Choose k)))) = k True <|> k False | ||
eff (R (R (R other))) = CullC (eff (R (R (R (handleCoercible other))))) | ||
{-# INLINE eff #-} | ||
|
||
|
||
-- $setup | ||
-- >>> :seti -XFlexibleContexts | ||
-- >>> import Test.QuickCheck | ||
-- >>> import Control.Carrier.NonDet.Church | ||
-- >>> import Control.Carrier.Pure |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Carrier modules are now named descriptively of the implementation;
.Church
here indicates that this is a church-encoded carrier forChoose
.