extensible-effects 1.7.1.2 → 1.7.2.1
raw patch · 6 files changed
+141/−40 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Eff.Lift: instance SetMember Lift (Lift m) (Lift m :> ())
- Data.OpenUnion1: instance [overlap ok] Functor (Union r)
- Data.OpenUnion1: instance [overlap ok] Member t (t :> r)
- Data.OpenUnion1: instance [overlap ok] Member t r => Member t (t' :> r)
- Data.OpenUnion1: instance [overlap ok] SetMember set t r => SetMember set t (t' :> r)
- Data.OpenUnion1: instance [overlap ok] Typeable Id
+ Data.OpenUnion.Internal.OpenUnion1: Union :: (t v) -> Union r v
+ Data.OpenUnion.Internal.OpenUnion1: class Member (t :: * -> *) r
+ Data.OpenUnion.Internal.OpenUnion1: class Member t r => MemberU (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t
+ Data.OpenUnion.Internal.OpenUnion1: data (:>) (a :: * -> *) b
+ Data.OpenUnion.Internal.OpenUnion1: data Union r v
+ Data.OpenUnion.Internal.OpenUnion1: instance [overlap ok] Member t (t :> r)
+ Data.OpenUnion.Internal.OpenUnion1: instance [overlap ok] Member t r => Member t (t' :> r)
+ Data.OpenUnion.Internal.OpenUnion1: instance [overlap ok] MemberU tag (tag e) (tag e :> r)
+ Data.OpenUnion.Internal.OpenUnion1: instance [overlap ok] MemberU tag t r => MemberU tag t (t' :> r)
+ Data.OpenUnion1: instance MemberU set t r => SetMember set t r
+ Data.OpenUnion1: instance Typeable Id
+ Data.OpenUnion1: weaken :: (Typeable t, Functor t) => Union r w -> Union (t :> r) w
- Control.Eff: class Member t r
+ Control.Eff: class Member (t :: * -> *) r
- Data.OpenUnion1: class Member t r
+ Data.OpenUnion1: class Member (t :: * -> *) r
Files
- extensible-effects.cabal +11/−4
- src/Control/Eff/Lift.hs +1/−3
- src/Data/OpenUnion/Internal/Base.hs +30/−0
- src/Data/OpenUnion/Internal/OpenUnion1.hs +30/−0
- src/Data/OpenUnion/Internal/OpenUnion2.hs +47/−0
- src/Data/OpenUnion1.hs +22/−33
extensible-effects.cabal view
@@ -6,7 +6,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.7.1.2+version: 1.7.2.1 -- A short (one-line) description of the package. synopsis: An Alternative to Monad Transformers@@ -43,7 +43,7 @@ category: Control, Effect -tested-with: GHC==7.8.2+tested-with: GHC==7.8.3, GHC==7.6.3 build-type: Simple @@ -75,7 +75,11 @@ Data.OpenUnion1 -- Modules included in this library but not exported.- -- other-modules:+ other-modules: Data.OpenUnion.Internal.Base+ if impl(ghc >= 7.8.1)+ other-modules: Data.OpenUnion.Internal.OpenUnion2+ else+ other-modules: Data.OpenUnion.Internal.OpenUnion1 default-extensions: Trustworthy -- LANGUAGE extensions used by modules in this package.@@ -92,7 +96,6 @@ , KindSignatures , MultiParamTypeClasses , NoMonomorphismRestriction- , OverlappingInstances , PatternGuards , PolyKinds , RankNTypes@@ -100,6 +103,8 @@ , TupleSections , TypeOperators , UndecidableInstances+ if impl(ghc < 7.8.1)+ other-extensions: OverlappingInstances -- Other library packages from which modules are imported. build-depends: base >= 4.6 && < 5@@ -129,6 +134,8 @@ test-framework-hunit == 0.3.*, test-framework-quickcheck2 == 0.3.*, extensible-effects++ default-language: Haskell2010 source-repository head type: git
src/Control/Eff/Lift.hs view
@@ -28,15 +28,13 @@ -- | Lift a Monad m to an effect. data Lift m v = forall a. Lift (m a) (a -> v) #if MIN_VERSION_base(4,7,0)- deriving (Typeable) -- starting from ghc-7.8 Typeable can only be derived+ deriving (Typeable) -- starting from ghc-7.8 Typeable can only be derived #else instance Typeable1 m => Typeable1 (Lift m) where typeOf1 _ = mkTyConApp (mkTyCon3 "" "Eff" "Lift") [typeOf1 (undefined :: m ())] #endif--instance SetMember Lift (Lift m) (Lift m :> ()) instance Functor (Lift m) where fmap f (Lift m k) = Lift m (f . k)
+ src/Data/OpenUnion/Internal/Base.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE CPP #-}++#if MIN_VERSION_base(4,7,0)+#define Typeable1 Typeable+#endif++-- | Adapted from <http://okmij.org/ftp/Haskell/extensible/OpenUnion1.hs> and+-- <http://okmij.org/ftp/Haskell/extensible/OpenUnion2.hs>+module Data.OpenUnion.Internal.Base( Union (..)+ , (:>)+ ) where++import Data.Typeable++-- | Parameter @r@ is phantom: it just tells what could be in the union.+-- Where @r@ is @t1 :> t2 ... :> tn@, @`Union` r v@ can be constructed with a+-- value of type @ti v@.+-- Ideally, we should be able to add the constraint @`Member` t r@.+data Union r v = forall t. (Functor t, Typeable1 t) => Union (t v)++instance Functor (Union r) where+ {-# INLINE fmap #-}+ fmap f (Union v) = Union (fmap f v)++-- | A sum data type, for composing effects+infixr 1 :>+data ((a :: * -> *) :> b)
+ src/Data/OpenUnion/Internal/OpenUnion1.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}++-- Only for MemberU below, when emulating Monad Transformers+{-# LANGUAGE FunctionalDependencies, OverlappingInstances, UndecidableInstances #-}++-- | Original work at <http://okmij.org/ftp/Haskell/extensible/OpenUnion1.hs>.+-- Open unions (type-indexed co-products) for extensible effects.+-- This implementation relies on _closed_ overlapping instances+-- (or closed type function overlapping soon to be added to GHC).+module Data.OpenUnion.Internal.OpenUnion1( Union (..)+ , (:>)+ , Member+ , MemberU+ ) where++import Data.OpenUnion.Internal.Base++-- | The @`Member` t r@ specifies whether @t@ is present anywhere in the sum+-- type @r@, where @t@ is some effectful type,+-- e.g. @`Lift` `IO`@, @`State` Int`@.+class Member (t :: * -> *) r+instance Member t (t :> r)+instance Member t r => Member t (t' :> r)++-- | This class is used for emulating monad transformers+class Member t r => MemberU (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t+instance MemberU tag (tag e) (tag e :> r)+instance MemberU tag t r => MemberU tag t (t' :> r)
+ src/Data/OpenUnion/Internal/OpenUnion2.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE DataKinds, PolyKinds #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}++-- Only for MemberU below, when emulating Monad Transformers+{-# LANGUAGE FunctionalDependencies, UndecidableInstances #-}++-- | Original work at <http://okmij.org/ftp/Haskell/extensible/OpenUnion2.hs>.+-- Open unions (type-indexed co-products) for extensible effects.+-- This implementation relies on _closed_ type families added to GHC 7.8. It has+-- NO overlapping instances+module Data.OpenUnion.Internal.OpenUnion2( Union (..)+ , (:>)+ , Member+ , MemberU+ ) where++import Data.OpenUnion.Internal.Base++-- | Class Member is defined only for the sake of the interface compatibility+-- with OpenUnion1. Generally, the closed type family Member' below could be+-- used instead.+--+-- The @`Member` t r@ specifies whether @t@ is present anywhere in the sum type+-- @r@, where @t@ is some effectful type, e.g. @`Lift` `IO`@, @`State` Int`@.+class (Member' t r ~ True) => Member (t :: * -> *) r+instance (Member' t r ~ True) => Member t r++type family Member' (t :: * -> *) r :: Bool where+ Member' t (t :> r) = True+ Member' t () = False+ Member' t (t' :> r) = Member' t r++type family EQU (a :: k) (b :: k) :: Bool where+ EQU a a = True+ EQU a b = False++-- | This class is used for emulating monad transformers+class Member t r => MemberU (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t+instance (MemberU' (EQU t1 t2) tag t1 (t2 :> r)) => MemberU tag t1 (t2 :> r)++class Member t r =>+ MemberU' (f::Bool) (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t+instance MemberU' True tag (tag e) (tag e :> r)+instance (Member' t (t' :> r) ~ True, MemberU tag t r) =>+ MemberU' False tag t (t' :> r)
src/Data/OpenUnion1.hs view
@@ -1,15 +1,12 @@-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE EmptyDataDecls #-}-{-# LANGUAGE ExistentialQuantification #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-} {-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE OverlappingInstances #-}-{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE TypeOperators #-} {-# LANGUAGE CPP #-} +-- Only for SetMember below, when emulating Monad Transformers+{-# LANGUAGE FunctionalDependencies, UndecidableInstances #-}+ #if MIN_VERSION_base(4,7,0) #define Typeable1 Typeable #endif@@ -17,19 +14,27 @@ -- Open unions (type-indexed co-products) for extensible effects. -- This implementation relies on _closed_ overlapping instances -- (or closed type function overlapping soon to be added to GHC).+--+-- TODO: re-evaluate <https://github.com/bfops/extensible-effects/issues/13> module Data.OpenUnion1( Union (..)- , SetMember , Member+ , SetMember , (:>) , inj , prj , prjForce , decomp , unsafeReUnion+ , weaken ) where import Control.Applicative ((<$>)) import Data.Typeable+#if __GLASGOW_HASKELL__ >= 781+import Data.OpenUnion.Internal.OpenUnion2+#else+import Data.OpenUnion.Internal.OpenUnion1+#endif infixl 4 <?> @@ -38,30 +43,10 @@ Just a <?> _ = a _ <?> a = a --- for the sake of gcast1+-- | for the sake of @gcast1@ used below in @`prj`@ newtype Id a = Id { runId :: a } deriving Typeable --- | Where @r@ is @t1 :> t2 ... :> tn@, @`Union` r v@ can be constructed with a--- value of type @ti v@.--- Ideally, we should be be able to add the constraint @`Member` t r@.-data Union r v = forall t. (Functor t, Typeable1 t) => Union (t v)--instance Functor (Union r) where- {-# INLINE fmap #-}- fmap f (Union v) = Union (fmap f v)---- | A sum data type, for composing effects-infixr 1 :>-data ((a :: * -> *) :> b)---- | The @`Member` t r@ specifies whether @t@ is present anywhere in the sum--- type @r@, where @t@ is some effectful type,--- e.g. @`Lift` `IO`@, @`State` Int`@.-class Member t r-instance Member t (t :> r)-instance Member t r => Member t (t' :> r)- -- | `SetMember` is similar to `Member`, but it allows types to belong to a -- \"set\". For every set, only one member can be in @r@ at any given time. -- This allows us to specify exclusivity and uniqueness among arbitrary effects:@@ -75,8 +60,8 @@ -- > -- > -- Only allow a single unique Lift effect, by making a "Lift" set. -- > instance Member (Lift m) r => SetMember Lift (Lift m) r-class Member t r => SetMember set (t :: * -> *) r | r set -> t-instance SetMember set t r => SetMember set t (t' :> r)+class (Member t r) => SetMember set (t :: * -> *) r | r set -> t+instance (MemberU set t r) => SetMember set t r {-# INLINE inj #-} -- | Construct a Union.@@ -99,6 +84,10 @@ -- If we can't, return a reduced Union that excludes the type we just checked. decomp :: Typeable1 t => Union (t :> r) v -> Either (Union r v) (t v) decomp u = Right <$> prj u <?> Left (unsafeReUnion u)++{-# INLINE weaken #-}+weaken :: (Typeable1 t, Functor t) => Union r w -> Union (t :> r) w+weaken (Union x) = Union x {-# INLINE unsafeReUnion #-} -- | Juggle types for a Union. Use cautiously.