extensible-effects 1.11.0.0 → 1.11.0.1
raw patch · 5 files changed
+56/−67 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Eff.Choose: instance [safe] Functor Choose
- Control.Eff.Choose: instance [safe] Typeable Choose
- Control.Eff.Coroutine: instance [safe] Functor (Yield a)
- Control.Eff.Coroutine: instance [safe] Typeable Yield
- Control.Eff.Cut: instance [safe] Typeable CutFalse
- Control.Eff.Exception: instance [safe] Functor (Exc e)
- Control.Eff.Exception: instance [safe] Typeable Exc
- Control.Eff.Fresh: instance [safe] Functor (Fresh i)
- Control.Eff.Fresh: instance [safe] Typeable Fresh
- Control.Eff.Lift: instance [safe] (MonadBase b m, Typeable m, SetMember Lift (Lift m) r) => MonadBase b (Eff r)
- Control.Eff.Lift: instance [safe] (Typeable m, MonadIO m, SetMember Lift (Lift m) r) => MonadIO (Eff r)
- Control.Eff.Lift: instance [safe] Functor (Lift m)
- Control.Eff.Lift: instance [safe] Typeable Lift
- Control.Eff.Operational: instance [safe] Functor (Program instr)
- Control.Eff.Operational: instance [safe] Typeable Program
- Control.Eff.Operational.Example: instance [safe] Typeable Jail
- Control.Eff.Reader.Lazy: instance [safe] Functor (Reader e)
- Control.Eff.Reader.Lazy: instance [safe] Typeable Reader
- Control.Eff.Reader.Strict: instance [safe] Functor (Reader e)
- Control.Eff.Reader.Strict: instance [safe] Typeable Reader
- Control.Eff.State.Lazy: instance [safe] Functor (State s)
- Control.Eff.State.Lazy: instance [safe] Typeable State
- Control.Eff.State.Strict: instance [safe] Functor (State s)
- Control.Eff.State.Strict: instance [safe] Typeable State
- Control.Eff.Trace: instance [safe] Functor Trace
- Control.Eff.Trace: instance [safe] Typeable Trace
- Control.Eff.Writer.Lazy: instance [safe] Functor (Writer w)
- Control.Eff.Writer.Lazy: instance [safe] Typeable Writer
- Control.Eff.Writer.Strict: instance [safe] Functor (Writer w)
- Control.Eff.Writer.Strict: instance [safe] Typeable Writer
- Control.Monad.Free.Reflection: instance [safe] Functor f => Applicative (Free f)
- Control.Monad.Free.Reflection: instance [safe] Functor f => Functor (Free f)
- Control.Monad.Free.Reflection: instance [safe] Functor f => Monad (Free f)
- Control.Monad.Free.Reflection: instance [safe] Typeable Free
- Control.Monad.Free.Reflection: instance [safe] Typeable FreeView
- Data.OpenUnion: instance [safe] MemberU set t r => SetMember set t r
- Data.OpenUnion: instance [safe] Typeable Id
+ Control.Eff.Choose: instance GHC.Base.Functor Control.Eff.Choose.Choose
+ Control.Eff.Coroutine: instance GHC.Base.Functor (Control.Eff.Coroutine.Yield a)
+ Control.Eff.Example: lastAndSum :: (Typeable a, Num a) => [a] -> (Maybe a, a)
+ Control.Eff.Example: lastEff :: Typeable a => [a] -> Maybe a
+ Control.Eff.Example: sumAll :: (Typeable a, Num a, Member (State a) e) => [a] -> Eff e ()
+ Control.Eff.Example: sumEff :: (Num a, Typeable a) => [a] -> a
+ Control.Eff.Example: writeAll :: (Typeable a, Member (Writer a) e) => [a] -> Eff e ()
+ Control.Eff.Example: writeAndAdd :: (Member (Writer a) e, Member (State a) e, Num a, Typeable a) => [a] -> Eff e ()
+ Control.Eff.Exception: instance GHC.Base.Functor (Control.Eff.Exception.Exc e)
+ Control.Eff.Fresh: instance GHC.Base.Functor (Control.Eff.Fresh.Fresh i)
+ Control.Eff.Lift: instance (Control.Monad.Base.MonadBase b m, Data.Typeable.Internal.Typeable m, Data.OpenUnion.SetMember Control.Eff.Lift.Lift (Control.Eff.Lift.Lift m) r) => Control.Monad.Base.MonadBase b (Control.Eff.Eff r)
+ Control.Eff.Lift: instance (Data.Typeable.Internal.Typeable m, Control.Monad.IO.Class.MonadIO m, Data.OpenUnion.SetMember Control.Eff.Lift.Lift (Control.Eff.Lift.Lift m) r) => Control.Monad.IO.Class.MonadIO (Control.Eff.Eff r)
+ Control.Eff.Lift: instance GHC.Base.Functor (Control.Eff.Lift.Lift m)
+ Control.Eff.Operational: instance GHC.Base.Functor (Control.Eff.Operational.Program instr)
+ Control.Eff.Reader.Lazy: instance GHC.Base.Functor (Control.Eff.Reader.Lazy.Reader e)
+ Control.Eff.Reader.Strict: instance GHC.Base.Functor (Control.Eff.Reader.Strict.Reader e)
+ Control.Eff.State.Lazy: instance GHC.Base.Functor (Control.Eff.State.Lazy.State s)
+ Control.Eff.State.Strict: instance GHC.Base.Functor (Control.Eff.State.Strict.State s)
+ Control.Eff.Trace: instance GHC.Base.Functor Control.Eff.Trace.Trace
+ Control.Eff.Writer.Lazy: instance GHC.Base.Functor (Control.Eff.Writer.Lazy.Writer w)
+ Control.Eff.Writer.Strict: instance GHC.Base.Functor (Control.Eff.Writer.Strict.Writer w)
+ Control.Monad.Free.Reflection: instance GHC.Base.Functor f => GHC.Base.Applicative (Control.Monad.Free.Reflection.Free f)
+ Control.Monad.Free.Reflection: instance GHC.Base.Functor f => GHC.Base.Functor (Control.Monad.Free.Reflection.Free f)
+ Control.Monad.Free.Reflection: instance GHC.Base.Functor f => GHC.Base.Monad (Control.Monad.Free.Reflection.Free f)
+ Data.OpenUnion: instance forall (k :: BOX) (set :: k -> * -> *) (t :: * -> *) r. Data.OpenUnion.Imports.MemberU set t r => Data.OpenUnion.SetMember set t r
- Control.Eff: class Member t r => SetMember set (t :: * -> *) r | r set -> t
+ Control.Eff: class (Member t r) => SetMember set (t :: * -> *) r | r set -> t
- Data.OpenUnion: class Member t r => SetMember set (t :: * -> *) r | r set -> t
+ Data.OpenUnion: class (Member t r) => SetMember set (t :: * -> *) r | r set -> t
Files
- extensible-effects.cabal +2/−1
- src/Control/Eff.hs +2/−44
- src/Control/Eff/Example.hs +46/−0
- src/Control/Eff/Operational.hs +1/−1
- test/Test.hs +5/−21
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.11.0.0+version: 1.11.0.1 -- A short (one-line) description of the package. synopsis: An Alternative to Monad Transformers@@ -65,6 +65,7 @@ Control.Eff.Choose Control.Eff.Coroutine Control.Eff.Cut+ Control.Eff.Example Control.Eff.Exception Control.Eff.Fresh Control.Eff.Lift
src/Control/Eff.hs view
@@ -18,50 +18,8 @@ -- as described in <http://okmij.org/ftp/Haskell/extensible/exteff.pdf>. -- -- Extensible Effects are implemented as typeclass constraints on an Eff[ect] datatype.--- A contrived example is:------ > {-# LANGUAGE FlexibleContexts #-}--- > import Control.Eff--- > import Control.Eff.Lift--- > import Control.Eff.State--- > import Control.Monad (void)--- > import Data.Typeable--- >--- > -- Write the elements of a list of numbers, in order.--- > writeAll :: (Typeable a, Member (Writer a) e)--- > => [a]--- > -> Eff e ()--- > writeAll = mapM_ putWriter--- >--- > -- Add a list of numbers to the current state.--- > sumAll :: (Typeable a, Num a, Member (State a) e)--- > => [a]--- > -> Eff e ()--- > sumAll = mapM_ (onState . (+))--- >--- > -- Write a list of numbers and add them to the current state.--- > writeAndAdd :: (Member (Writer Integer) e, Member (State Integer) e)--- > => [Integer]--- > -> Eff e ()--- > writeAndAdd l = do--- > writeAll l--- > sumAll l--- >--- > -- Sum a list of numbers.--- > sumEff :: (Num a, Typeable a) => [a] -> a--- > sumEff l = let (s, ()) = run $ runState 0 $ sumAll l--- > in s--- >--- > -- Safely get the last element of a list.--- > -- Nothing for empty lists; Just the last element otherwise.--- > lastEff :: Typeable a => [a] -> Maybe a--- > lastEff l = let (a, ()) = run $ runWriter $ writeAll l--- > in a--- >--- > -- Get the last element and sum of a list--- > lastAndSum :: (Typeable a, Num a) => [a] -> (Maybe a, a)--- > lastAndSum l = let (lst, (total, ())) = run $ runWriter $ runState 0 $ writeAndAdd l--- > in (lst, total)+-- A contrived example can be found under "Control.Eff.Example". To run the+-- effects, consult the tests. module Control.Eff( Eff , module Reflection
+ src/Control/Eff/Example.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE FlexibleContexts #-}++-- | Example usage of "Control.Eff"+module Control.Eff.Example where++import Control.Eff+import Control.Eff.State.Lazy+import Control.Eff.Writer.Lazy+import Data.Typeable++-- | Write the elements of a list of numbers, in order.+writeAll :: (Typeable a, Member (Writer a) e)+ => [a]+ -> Eff e ()+writeAll = mapM_ tell++-- | Add a list of numbers to the current state.+sumAll :: (Typeable a, Num a, Member (State a) e)+ => [a]+ -> Eff e ()+sumAll = mapM_ (modify . (+))++-- | Write a list of numbers and add them to the current state.+writeAndAdd :: (Member (Writer a) e, Member (State a) e, Num a, Typeable a)+ => [a]+ -> Eff e ()+writeAndAdd l = do+ writeAll l+ sumAll l++-- | Sum a list of numbers.+sumEff :: (Num a, Typeable a) => [a] -> a+sumEff l = let (s, ()) = run $ runState 0 $ sumAll l+ in s++-- | Safely get the last element of a list.+-- Nothing for empty lists; Just the last element otherwise.+lastEff :: Typeable a => [a] -> Maybe a+lastEff l = let (a, ()) = run $ runLastWriter $ writeAll l+ in a+++-- | Get the last element and sum of a list+lastAndSum :: (Typeable a, Num a) => [a] -> (Maybe a, a)+lastAndSum l = let (lst, (total, ())) = run $ runLastWriter $ runState 0 $ writeAndAdd l+ in (lst, total)
src/Control/Eff/Operational.hs view
@@ -61,7 +61,7 @@ -- $usage ----- See 'Control.Eff.Operational.Example' for an example of defining data using+-- See "Control.Eff.Operational.Example" for an example of defining data using -- GADTs and implementing interpreters from the data to effects. -- -- To use the interpreter, see below or consult the tests.
test/Test.hs view
@@ -15,6 +15,7 @@ import Test.QuickCheck import Control.Eff+import Control.Eff.Example as Eg import Control.Eff.Exception import Control.Eff.Lift import Control.Eff.Operational as Op@@ -62,30 +63,13 @@ prop_Documentation_example :: [Integer] -> Property prop_Documentation_example l = let- (total1, ()) = run $ LazyS.runState 0 $ sumAll l- (last1, ()) = run $ LazyW.runLastWriter $ writeAll l- (total2, (last2, ())) = run $ LazyS.runState 0 $ LazyW.runLastWriter $ writeAndAdd l- (last3, (total3, ())) = run $ LazyW.runLastWriter $ LazyS.runState 0 $ writeAndAdd l+ (total1, ()) = run $ LazyS.runState 0 $ Eg.sumAll l+ (last1, ()) = run $ LazyW.runLastWriter $ Eg.writeAll l+ (total2, (last2, ())) = run $ LazyS.runState 0 $ LazyW.runLastWriter $ Eg.writeAndAdd l+ (last3, (total3, ())) = run $ LazyW.runLastWriter $ LazyS.runState 0 $ Eg.writeAndAdd l in allEqual [safeLast l, last1, last2, last3] .&&. allEqual [sum l, total1, total2, total3]- where- writeAll :: (Typeable a, Member (LazyW.Writer a) e)- => [a]- -> Eff e ()- writeAll = mapM_ LazyW.tell-- sumAll :: (Typeable a, Num a, Member (LazyS.State a) e)- => [a]- -> Eff e ()- sumAll = mapM_ (LazyS.modify . (+))-- writeAndAdd :: (Member (LazyW.Writer Integer) e, Member (LazyS.State Integer) e)- => [Integer]- -> Eff e ()- writeAndAdd lst = do- writeAll lst- sumAll lst -- }}}