-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | TH implementation of effects. -- -- This package implements effects, as alternative to monad transformers. -- Actually, the effects themselves are created without the use of TH, -- but the binding of nested effects described by mkEff splice. For -- example. -- --
--   mkEff "MyReader"    ''Reader    ''Int       ''Lift
--   mkEff "SomeState"   ''State     ''Bool      ''MyReader
--   mkEff "OtherRdr"    ''Reader    ''Float     ''SomeState
--   
--   main:: IO ()
--   main = do
--       r <- runMyReader  100
--          $ runSomeState False
--          $ runOtherRdr  pi  $ do
--               i :: Int   <- ask                    -- MyReader
--               f :: Float <- ask                    -- OtherRdr
--               b <- get                             -- SomeState
--               put $ not b                          -- SomeState
--               lift $ putStrLn "print from effect!" -- Lift
--               return $ show $ fromIntegral i * f
--       print r
--   
-- -- For more information about extensible effects , see the original paper -- at http://okmij.org/ftp/Haskell/extensible/exteff.pdf. But, -- this package is significantly different from the original. It uses a -- chains of ordinary GADTs created by TH. No Typeable, no unsafe... , no -- ExistentialQuantification ... @package THEff @version 0.1.3 module Control.THEff -- | TH function for building types and functions to ensure the functioning -- of the chain enclosed in each other's effects mkEff :: String -> Name -> Name -> Name -> DecsQ -- | The Monad of effects newtype Eff w a Eff :: ((a -> w) -> w) -> Eff w a [runEff] :: Eff w a -> (a -> w) -> w -- | Helper class to transfer the action effects by chain. Instances of -- this class are created in mkEff. class EffClass w v e where effAction f = Eff $ \ k -> toEff $ f k effAction :: EffClass w v e => ((r -> e) -> w v e) -> Eff e r toEff :: EffClass w v e => w v e -> e -- | The first effect in a chain of effects not use monads. The chain of -- effects should start or that type, or Lift (See below.) newtype NoEff (m :: * -> *) a NoEff :: a -> NoEff a [unNoEff] :: NoEff a -> a -- | This function is used in the mkEff generated runEEEE... -- functions. effNoEff _ = error "THEff: Attempting to call the -- effect NoEff that does not have any actions!" effNoEff :: a -> b -- | This function is used in the mkEff generated runEEEE... -- functions. Do not use it alone. runNoEff :: Eff (NoEff m a) a -> a -- | Helper data type for transfer the monadic action effects by chain. data Lift' m v Lift' :: (m a) -> (a -> v) -> Lift' m v -- | Helper class to transfer the monadic action effects by chain. -- Instances of this class are created in mkEff. class EffClassM m e where effLift (Lift' m g) = Eff $ \ k -> toEffM $ Lift' m (k . g) effLift :: EffClassM m e => Lift' m r -> Eff e r toEffM :: EffClassM m e => Lift' m e -> e -- | Lift a Monad to an Effect. lift :: EffClassM m e => m a -> Eff e a -- | The first effect in a chain of monadic effects. The chain of effects -- should start or that type, or NoEff. data Lift m a Lift_ :: (Lift' m (Lift m a)) -> Lift m a LiftResult :: a -> Lift m a -- | This function is used in the mkEff generated runEEEE... -- functions. Do not use it alone. runLift :: Monad m => Eff (Lift m a) a -> m a instance GHC.Base.Functor (Control.THEff.Eff w) instance GHC.Base.Applicative (Control.THEff.Eff w) instance GHC.Base.Monad (Control.THEff.Eff w) instance Control.THEff.EffClassM m (Control.THEff.Lift m a) module Control.THEff.Catch -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Catch' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE function. data Catch (m :: * -> *) e o v a CatchOuter :: (o m e) -> Catch e o v a CatchAction :: (Catch' v e) -> Catch e o v a CatchResult :: a -> Catch e o v a -- | Type of fourth argument of runEffCatch and first argument of runEEEE. type CatchArgT v r = v -> r -- | Result type of runEEEE. type CatchResT r = r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effCatch :: EffClass Catch' v e => Catch' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffCatch :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. Monad m => (u t r -> (r -> m (CatchResT z)) -> m (CatchResT z)) -> (Catch m1 e o w a -> r) -> (r -> Catch t r u v z) -> CatchArgT v z -> Eff r a -> m (CatchResT z) -- | Throw effect specific exception. throwCtch :: EffClass Catch' v e => v -> Eff e () -- | Throw effect specific exception if first argument is True. throwCtchIf :: EffClass Catch' v e => v -> (v -> Bool) -> Eff e () module Control.THEff.Exception -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Except' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Except (m :: * -> *) e o v a ExceptOuter :: (o m e) -> Except e o v a ExceptAction :: (Except' v e) -> Except e o v a ExceptResult :: a -> Except e o v a -- | Type of fourth argument of runEffExcept and first argument of runEEEE. type ExceptArgT v = v -> v -- | Result type of runEEEE. type ExceptResT r v = Either v r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effExcept :: EffClass Except' v e => Except' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffExcept :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. Monad m => (u t r -> (r -> m (ExceptResT z v)) -> m (ExceptResT z v)) -> (Except m1 e o w a -> r) -> (r -> Except t r u v z) -> ExceptArgT v -> Eff r a -> m (ExceptResT z v) -- | Throw effect specific exception. throwExc :: EffClass Except' v e => v -> Eff e () -- | Throw effect specific exception if first argument is True. throwIf :: EffClass Except' v e => Bool -> v -> Eff e () module Control.THEff.Fresh -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Fresh' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Fresh (m :: * -> *) e o v a FreshOuter :: (o m e) -> Fresh e o v a FreshAction :: (Fresh' v e) -> Fresh e o v a FreshResult :: a -> Fresh e o v a -- | Type of fourth argument of runEffFresh and first argument of runEEEE. type FreshArgT v = v -- | Result type of runEEEE. type FreshResT r = r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effFresh :: EffClass Fresh' v e => Fresh' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffFresh :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. (Monad m, Enum v) => (u t r -> (r -> m (FreshResT z)) -> m (FreshResT z)) -> (Fresh m1 e o w a -> r) -> (r -> Fresh t r u v z) -> FreshArgT v -> Eff r a -> m (FreshResT z) -- | Get a unique value. fresh :: EffClass Fresh' v e => Eff e v module Control.THEff.Reader -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Reader' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Reader (m :: * -> *) e o v a ReaderOuter :: (o m e) -> Reader e o v a ReaderAction :: (Reader' v e) -> Reader e o v a ReaderResult :: a -> Reader e o v a -- | Type of fourth argument of runEffReader and first argument of runEEEE. type ReaderArgT v = v -- | Result type of runEEEE. type ReaderResT r = r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effReader :: EffClass Reader' v e => Reader' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffReader :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) a v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a1 r. Monad m => (u t r -> (r -> m (ReaderResT a)) -> m (ReaderResT a)) -> (Reader m1 e o w a1 -> r) -> (r -> Reader t r u v a) -> ReaderArgT v -> Eff r a1 -> m (ReaderResT a) -- | Get reader value ask :: EffClass Reader' v e => Eff e v -- | Get and convert the value of the reader asks :: EffClass Reader' r e => (r -> v) -> Eff e v module Control.THEff.Reader.Strict -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Reader' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Reader (m :: * -> *) e o v a ReaderOuter :: (o m e) -> Reader e o v a ReaderAction :: (Reader' v e) -> Reader e o v a ReaderResult :: a -> Reader e o v a -- | Type of fourth argument of runEffReader and first argument of runEEEE. type ReaderArgT v = v -- | Result type of runEEEE. type ReaderResT r = r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effReader :: EffClass Reader' v e => Reader' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffReader :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) a v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a1 r. Monad m => (u t r -> (r -> m (ReaderResT a)) -> m (ReaderResT a)) -> (Reader m1 e o w a1 -> r) -> (r -> Reader t r u v a) -> ReaderArgT v -> Eff r a1 -> m (ReaderResT a) -- | Get reader value ask :: EffClass Reader' v e => Eff e v -- | Get and convert the value of the reader asks :: EffClass Reader' r e => (r -> v) -> Eff e v module Control.THEff.State -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data State' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data State (m :: * -> *) e o v a StateOuter :: (o m e) -> State e o v a StateAction :: (State' v e) -> State e o v a StateResult :: a -> State e o v a -- | Type of fourth argument of runEffState and first argument of runEEEE. type StateArgT v = v -- | Result type of runEEEE. type StateResT r v = (r, v) -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effState :: EffClass State' v e => State' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffState :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. Monad m => (u t r -> (r -> m (StateResT z v)) -> m (StateResT z v)) -> (State m1 e o w a -> r) -> (r -> State t r u v z) -> StateArgT v -> Eff r a -> m (StateResT z v) -- | Get state value get :: EffClass State' v e => Eff e v -- | Put state value put :: EffClass State' v e => v -> Eff e () -- | Modify state value modify :: EffClass State' v e => (v -> v) -> Eff e () -- |
--   stateOnly runExample1 123 === snd (runExample1 123)
--   
stateOnly :: forall v e r t. (t -> e -> (r, v)) -> t -> e -> v -- |
--   withoutState runExample1 123 === fst (runExample1 123)
--   
withoutState :: forall v e r t. (t -> e -> (r, v)) -> t -> e -> r module Control.THEff.State.Strict -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data State' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data State (m :: * -> *) e o v a StateOuter :: (o m e) -> State e o v a StateAction :: (State' v e) -> State e o v a StateResult :: a -> State e o v a -- | Type of fourth argument of runEffState and first argument of runEEEE. type StateArgT v = v -- | Result type of runEEEE. type StateResT r v = (r, v) -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effState :: EffClass State' v e => State' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffState :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. Monad m => (u t r -> (r -> m (StateResT z v)) -> m (StateResT z v)) -> (State m1 e o w a -> r) -> (r -> State t r u v z) -> StateArgT v -> Eff r a -> m (StateResT z v) -- | Get state value get :: EffClass State' v e => Eff e v -- | Put state value put :: EffClass State' v e => v -> Eff e () -- | Modify state value modify :: EffClass State' v e => (v -> v) -> Eff e () -- |
--   stateOnly runExample1 123 === snd (runExample1 123)
--   
stateOnly :: forall v e r t. (t -> e -> (r, v)) -> t -> e -> v -- |
--   withoutState runExample1 123 === fst (runExample1 123)
--   
withoutState :: forall v e r t. (t -> e -> (r, v)) -> t -> e -> r module Control.THEff.Validator -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Validator' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Validator (m :: * -> *) e o v a ValidatorOuter :: (o m e) -> Validator e o v a ValidatorAction :: (Validator' v e) -> Validator e o v a ValidatorResult :: a -> Validator e o v a -- | Type of fourth argument of runEffValidator and first argument of -- runEEEE. type ValidatorArgT v r = v -> Either v v -- | Result type of runEEEE. type ValidatorResT r v = Either v r -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effValidator :: EffClass Validator' v e => Validator' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffValidator :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. Monad m => (u t r -> (r -> m (ValidatorResT z v)) -> m (ValidatorResT z v)) -> (Validator m1 e o w a -> r) -> (r -> Validator t r u v z) -> ValidatorArgT v z -> Eff r a -> m (ValidatorResT z v) -- | Check the conditions specified by the first argument of runEEEE chk :: EffClass Validator' v e => v -> Eff e v -- | validator returns Right v if the predicate returns True -- and Left v else. validator :: (v -> Bool) -> v -> Either v v -- | If the value is outside this range, range sets the value of the -- range. Always returns Right. range :: Ord v => v -> v -> v -> Either v v -- | right ~(Right v) = v right :: Either a b -> b -- | If the runEEEE return value is out of range, it is set on the border -- of the range. withRange :: forall r e l v. Ord v => ((v -> Either v v) -> e -> Either l r) -> v -> v -> e -> r module Control.THEff.Writer -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Writer' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Writer (m :: * -> *) e o v a WriterOuter :: (o m e) -> Writer e o v a WriterAction :: (Writer' v e) -> Writer e o v a WriterResult :: a -> Writer e o v a -- | Result type of runEEEE. type WriterResT r v = (r, v) -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effWriter :: EffClass Writer' v e => Writer' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffWriter :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. (Monad m, Monoid v) => (u t r -> (r -> m (WriterResT z v)) -> m (WriterResT z v)) -> (Writer m1 e o w a -> r) -> (r -> Writer t r u v z) -> Eff r a -> m (WriterResT z v) -- | Add value to monoid. tell :: EffClass Writer' v e => v -> Eff e () module Control.THEff.Writer.Strict -- | Actually, the effect type - v - Type - the parameter of -- the effect. - e - mkEff generated type. data Writer' v e -- | Type implements link in the chain of effects. Constructors must be -- named {EffectName}{Outer|WriterAction|WriterResult} and -- have a specified types of fields. - m - Or Monad (if use -- the Lift) or phantom type - stub (if used NoEff). - -- o - Type of outer effect. - a - The result -- of mkEff generated runEEEE... function. data Writer (m :: * -> *) e o v a WriterOuter :: (o m e) -> Writer e o v a WriterAction :: (Writer' v e) -> Writer e o v a WriterResult :: a -> Writer e o v a -- | Result type of runEEEE. type WriterResT r v = (r, v) -- | This function is used in the mkEff generated runEEEE functions -- and typically in effect action functions. Calling the effect action. effWriter :: EffClass Writer' v e => Writer' v r -> Eff e r -- | The main function of the effect implementing. This function is used in -- the mkEff generated runEEEE functions. runEffWriter :: forall (t :: * -> *) (u :: (* -> *) -> * -> *) (m :: * -> *) z v (m1 :: * -> *) e (o :: (* -> *) -> * -> *) w a r. (Monad m, Monoid v) => (u t r -> (r -> m (WriterResT z v)) -> m (WriterResT z v)) -> (Writer m1 e o w a -> r) -> (r -> Writer t r u v z) -> Eff r a -> m (WriterResT z v) -- | Add value to monoid. tell :: EffClass Writer' v e => v -> Eff e ()