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

Remove Effect class #118

Merged
merged 1 commit into from
Jun 17, 2019
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
1 change: 0 additions & 1 deletion polysemy-plugin/test/InlineRecursiveCallsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module InlineRecursiveCallsSpec
import qualified Control.Monad.Trans.State as S
import Data.Tuple
import Polysemy.Internal
import Polysemy.Internal.Effect
import Polysemy.Internal.Union
import Test.Hspec
import Test.Inspection
Expand Down
3 changes: 1 addition & 2 deletions polysemy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 175e68dde4fe16b8480b3336ef932ff07e9abc0de4ea7ac90d0faa9465a55c59
-- hash: 45b44bbfb10eb9741561ea8fc127dbacabacbf59bcf754f8875c50ef623fbd48

name: polysemy
version: 0.4.0.0
Expand Down Expand Up @@ -46,7 +46,6 @@ library
Polysemy.Internal
Polysemy.Internal.Combinators
Polysemy.Internal.CustomErrors
Polysemy.Internal.Effect
Polysemy.Internal.Fixpoint
Polysemy.Internal.Kind
Polysemy.Internal.Lift
Expand Down
1 change: 0 additions & 1 deletion src/Polysemy/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Data.Bifunctor (first)
import Data.Typeable
import Polysemy
import Polysemy.Internal
import Polysemy.Internal.Effect
import Polysemy.Internal.Union


Expand Down
1 change: 0 additions & 1 deletion src/Polysemy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Control.Monad.Fix
import Control.Monad.IO.Class
import Data.Functor.Identity
import Data.Kind
import Polysemy.Internal.Effect
import Polysemy.Internal.Fixpoint
import Polysemy.Internal.Lift
import Polysemy.Internal.NonDet
Expand Down
1 change: 0 additions & 1 deletion src/Polysemy/Internal/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import qualified Control.Monad.Trans.State.Lazy as LS
import qualified Control.Monad.Trans.State.Strict as S
import Polysemy.Internal
import Polysemy.Internal.CustomErrors
import Polysemy.Internal.Effect
import Polysemy.Internal.Tactics
import Polysemy.Internal.Union

Expand Down
125 changes: 0 additions & 125 deletions src/Polysemy/Internal/Effect.hs

This file was deleted.

1 change: 0 additions & 1 deletion src/Polysemy/Internal/Tactics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Polysemy.Internal.Tactics
) where

import Polysemy.Internal
import Polysemy.Internal.Effect
import Polysemy.Internal.Union


Expand Down
74 changes: 54 additions & 20 deletions src/Polysemy/Internal/Union.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module Polysemy.Internal.Union
, Yo (..)
, liftYo
, Member
, weave
, hoist
-- * Building Unions
, inj
, weaken
Expand All @@ -28,12 +30,11 @@ module Polysemy.Internal.Union
, Nat (..)
) where

import Control.Monad
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Type.Equality
import Polysemy.Internal.Effect
import qualified Polysemy.Internal.Kind as K
import Control.Monad
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Type.Equality
import Polysemy.Internal.Kind

#ifndef NO_ERROR_MESSAGES
import Polysemy.Internal.CustomErrors
Expand All @@ -43,7 +44,7 @@ import Polysemy.Internal.CustomErrors
------------------------------------------------------------------------------
-- | An extensible, type-safe union. The @r@ type parameter is a type-level
-- list of effects, any one of which may be held within the 'Union'.
data Union (r :: K.EffectRow) (m :: * -> *) a where
data Union (r :: EffectRow) (m :: * -> *) a where
Union
:: SNat n
-- ^ A proof that the effect is actually in @r@.
Expand All @@ -67,33 +68,66 @@ instance Functor (Yo e m) where
fmap f (Yo e s d f' v) = Yo e s d (f . f') v
{-# INLINE fmap #-}

instance Effect (Yo e) where
weave s' d v' (Yo e s nt f v) =
weaveYo
:: (Functor s, Functor m, Functor n)
=> s ()
-> (∀ x. s (m x) -> n (s x))
-> (∀ x. s x -> Maybe x)
-> Yo e m a
-> Yo e n (s a)
weaveYo s' d v' (Yo e s nt f v) =
Yo e (Compose $ s <$ s')
(fmap Compose . d . fmap nt . getCompose)
(fmap f . getCompose)
(v <=< v' . getCompose)
{-# INLINE weave #-}

hoist = defaultHoist
{-# INLINE hoist #-}
{-# INLINE weaveYo #-}

hoistYo
:: ( Functor m
, Functor n
)
=> (∀ x. m x -> n x)
-> Yo e m a
-> Yo e n a
hoistYo f = fmap runIdentity
. weaveYo (Identity ())
(fmap Identity . f . runIdentity)
(Just . runIdentity)
{-# INLINE hoistYo #-}

liftYo :: Functor m => e m a -> Yo e m a
liftYo e = Yo e (Identity ()) (fmap Identity . runIdentity) runIdentity (Just . runIdentity)
liftYo e = Yo e (Identity ())
(fmap Identity . runIdentity)
runIdentity
(Just . runIdentity)
{-# INLINE liftYo #-}


instance Functor (Union r m) where
fmap f (Union w t) = Union w $ fmap' f t
fmap f (Union w t) = Union w $ fmap f t
{-# INLINE fmap #-}


instance Effect (Union r) where
weave s f v (Union w e) = Union w $ weave s f v e
{-# INLINE weave #-}
weave
:: (Functor s, Functor m, Functor n)
=> s ()
-> (∀ x. s (m x) -> n (s x))
-> (∀ x. s x -> Maybe x)
-> Union r m a
-> Union r n (s a)
weave s f v (Union w e) = Union w $ weaveYo s f v e
{-# INLINE weave #-}


hoist f (Union w e) = Union w $ hoist f e
{-# INLINE hoist #-}
hoist
:: ( Functor m
, Functor n
)
=> (∀ x. m x -> n x)
-> Union r m a
-> Union r n a
hoist f (Union w e) = Union w $ hoistYo f e
{-# INLINE hoist #-}


------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/Polysemy/NonDet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Data.Maybe
import Polysemy.Internal
import Polysemy.Internal.NonDet
import Polysemy.Internal.Union
import Polysemy.Internal.Effect


--------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/Polysemy/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Data.Tuple (swap)
import Polysemy
import Polysemy.Internal
import Polysemy.Internal.Combinators
import Polysemy.Internal.Effect
import Polysemy.Internal.Union


Expand Down
1 change: 0 additions & 1 deletion test/FusionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import qualified Control.Monad.Trans.State.Strict as S
import Polysemy.Error
import Polysemy.Internal
import Polysemy.Internal.Combinators
import Polysemy.Internal.Effect
import Polysemy.Internal.Union
import Polysemy.State
import Test.Hspec
Expand Down