-
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
🔥 Pure & PureC #307
🔥 Pure & PureC #307
Changes from all commits
3c616c5
f74bd37
40122e1
92f3c22
b91adc4
3ea94a7
0c7a11e
00a1ad2
315a579
e1ba776
01ed2e6
d833c81
ca115b8
ff46692
2e9e6ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{-# LANGUAGE ConstraintKinds, DeriveFunctor, EmptyCase, FlexibleInstances, FunctionalDependencies, RankNTypes, TypeOperators, UndecidableInstances #-} | ||
{-# LANGUAGE ConstraintKinds, DeriveFunctor, FlexibleInstances, FunctionalDependencies, RankNTypes, TypeOperators, UndecidableInstances #-} | ||
|
||
{- | The 'Algebra' class is the mechanism with which effects are interpreted. | ||
|
||
|
@@ -8,25 +8,23 @@ An instance of the 'Algebra' class defines an interpretation of an effect signat | |
-} | ||
module Control.Algebra | ||
( Algebra(..) | ||
, run | ||
, Has | ||
, send | ||
, handleIdentity | ||
, handleCoercible | ||
-- * Re-exports | ||
, (:+:) (..) | ||
, run | ||
, module Control.Effect.Class | ||
) where | ||
|
||
import Control.Carrier.Pure (PureC, run) | ||
import Control.Effect.Catch.Internal | ||
import Control.Effect.Choose.Internal | ||
import Control.Effect.Class | ||
import Control.Effect.Empty.Internal | ||
import Control.Effect.Error.Internal | ||
import Control.Effect.Lift.Internal | ||
import Control.Effect.NonDet.Internal | ||
import Control.Effect.Pure | ||
import Control.Effect.Reader.Internal | ||
import Control.Effect.State.Internal | ||
import Control.Effect.Sum ((:+:)(..), Member(..), Members) | ||
|
@@ -55,9 +53,13 @@ class (Effect 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). | ||
alg :: sig m a -> m a | ||
|
||
instance Algebra Pure PureC where | ||
alg v = case v of {} | ||
{-# INLINE alg #-} | ||
|
||
-- | Run an action exhausted of effects to produce its final result value. | ||
-- | ||
-- @since 1.0.0.0 | ||
run :: Identity a -> a | ||
run = runIdentity | ||
{-# INLINE run #-} | ||
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. Should we deprecate this? I’m honestly not sure. No, we shouldn’t. This is good, as per your comment below. |
||
|
||
|
||
-- | @m@ is a carrier for @sig@ containing @eff@. | ||
|
@@ -103,8 +105,8 @@ handleCoercible = handleIdentity coerce | |
instance Algebra (Lift IO) IO where | ||
alg = join . unLift | ||
|
||
instance Algebra Pure Identity where | ||
alg v = case v of {} | ||
instance Algebra (Lift Identity) Identity where | ||
alg = join . unLift | ||
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. When I wrote the |
||
|
||
instance Algebra Choose NonEmpty where | ||
alg (Choose m) = m True S.<> m False | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
{- | Provides a mechanism to kick off the evaluation of an effect stack that takes place in a monadic context. | ||
|
||
'Lift' effects are always the last effect in a given effect stack. These stacks are invoked with 'Control.Effect.Lift.runM'. The 'Control.Effect.Pure.Pure' effect is equivalent to @Lift Identity@. | ||
'Lift' effects are always the last effect in a given effect stack. These stacks are invoked with 'Control.Carrier.Lift.runM' or 'Control.Algebra.run'. | ||
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.
|
||
|
||
Predefined carriers: | ||
|
||
* "Control.Carrier.Lift" | ||
* 'IO' | ||
* 'Data.Functor.Identity.Identity' | ||
|
||
@since 0.1.0.0 | ||
-} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{-# LANGUAGE DataKinds, DeriveFunctor, DeriveGeneric, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, KindSignatures, LambdaCase, PatternSynonyms, RankNTypes, ScopedTypeVariables, StandaloneDeriving, TypeApplications, TypeOperators, UndecidableInstances, ViewPatterns #-} | ||
{-# OPTIONS_GHC -Wno-identities #-} | ||
module Gen | ||
( module Control.Carrier.Pure | ||
, Identity(..) | ||
( module Data.Functor.Identity | ||
-- * Polymorphic generation & instantiation | ||
, m | ||
, GenM | ||
|
@@ -59,7 +58,6 @@ module Gen | |
) where | ||
|
||
import Control.Applicative | ||
import Control.Carrier.Pure | ||
import Control.Monad.Trans.Class | ||
import Control.Monad.Trans.Writer | ||
import Data.Foldable (traverse_) | ||
|
@@ -183,18 +181,18 @@ subtermM2 t1 t2 f = Comp1 (Hedgehog.subtermM2 (unComp1 t1) (unComp1 t2) (fmap un | |
|
||
|
||
-- | This captures the shape of the handler function passed to the "Monad" & "MonadFix" tests. | ||
newtype Run f g m = Run (forall a . f (m a) -> PureC (g a)) | ||
newtype Run f g m = Run (forall a . f (m a) -> Identity (g a)) | ||
|
||
-- | Handlers with output state, but no input state (e.g. 'Control.Carrier.Error.Either.ErrorC'). | ||
runL :: (forall a . m a -> PureC (f a)) -> Run Identity f m | ||
runL :: (forall a . m a -> Identity (f a)) -> Run Identity f m | ||
runL run = Run (run . runIdentity) | ||
|
||
-- | Handlers with input state, but no output state (e.g. 'Control.Carrier.Reader.ReaderC'). | ||
runR :: (forall a . f (m a) -> PureC a) -> Run f Identity m | ||
runR :: (forall a . f (m a) -> Identity a) -> Run f Identity m | ||
runR run = Run (fmap Identity . run) | ||
|
||
-- | Handlers with curried input state (e.g. 'Control.Carrier.Reader.ReaderC', 'Control.Carrier.State.Strict.StateC'). | ||
runC :: (forall a . s -> m a -> PureC (f a)) -> Run ((,) s) f m | ||
runC :: (forall a . s -> m a -> Identity (f a)) -> Run ((,) s) f m | ||
runC run = Run (uncurry run) | ||
|
||
|
||
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. There’s some underlying thing going on here that’s intensely beautiful but that I don’t have the vocabulary to describe. |
||
|
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.
I think we can ditch the
EmptyCase
extension in this file now.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.
Oh good call 👍