-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Implementation of the Freer Monad -- -- Freer is an implementation of "Freer Monads, More Extensible Effects" -- -- The key features of Freer are: -- -- @package freer @version 0.2.2.6 -- | -- -- Using http://okmij.org/ftp/Haskell/extensible/FTCQueue1.hs as a -- starting point. -- -- A minimal version of FTCQueue from "Reflection w/o Remorse": -- -- module Data.FTCQueue -- | Non-empty tree. Deconstruction operations make it more and more -- left-leaning data FTCQueue m a b -- | Build a leaf from a single operation [O(1)] tsingleton :: (a -> m b) -> FTCQueue m a b -- | Append an operation to the right of the tree [O(1)] (|>) :: FTCQueue m a x -> (x -> m b) -> FTCQueue m a b -- | An alias for '(|>)' snoc :: FTCQueue m a x -> (x -> m b) -> FTCQueue m a b -- | Append two trees of operations [O(1)] (><) :: FTCQueue m a x -> FTCQueue m x b -> FTCQueue m a b -- | An alias for '(><)' append :: FTCQueue m a x -> FTCQueue m x b -> FTCQueue m a b -- | Left view deconstruction data structure data ViewL m a b TOne :: (a -> m b) -> ViewL m a b (:|) :: (a -> m x) -> FTCQueue m x b -> ViewL m a b -- | Left view deconstruction [average O(1)] tviewl :: FTCQueue m a b -> ViewL m a b -- | This implementation relies on _closed_ type families added to GHC 7.8. -- It has NO overlapping instances and NO Typeable. Alas, the absence of -- Typeable means the projections and injections generally take linear -- time. The code illustrate how to use closed type families to -- disambiguate otherwise overlapping instances. -- -- The data constructors of Union are not exported. Essentially, the -- nested Either data type. -- -- Using http://okmij.org/ftp/Haskell/extensible/OpenUnion41.hs as -- a starting point. module Data.Open.Union data Union (r :: [* -> *]) v decomp :: Union (t : r) v -> Either (Union r v) (t v) weaken :: Union r w -> Union (any : r) w class (Member' t r (FindElem t r)) => Member t r inj :: Member t r => t v -> Union r v prj :: Member t r => Union r v -> Maybe (t v) instance Data.Open.Union.Member' t r (Data.Open.Union.FindElem t r) => Data.Open.Union.Member t r instance (r ~ (t : r')) => Data.Open.Union.Member' t r 'Data.Open.Union.Z instance (r ~ (t' : r'), Data.Open.Union.Member' t r' n) => Data.Open.Union.Member' t r ('Data.Open.Union.S n) -- | Internal machinery for this effects library. This includes: -- -- -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Internal -- | The Eff representation. -- -- Status of a coroutine (client): * Val: Done with the value of type a * -- E : Sending a request of type Union r with the continuation Arrs r b a data Eff r a Val :: a -> Eff r a E :: (Union r b) -> (Arrs r b a) -> Eff r a class (Member' t r (FindElem t r)) => Member t r inj :: Member t r => t v -> Union r v prj :: Member t r => Union r v -> Maybe (t v) -- | Effectful arrow type: a function from a to b that also does effects -- denoted by r type Arr r a b = a -> Eff r b -- | An effectful function from a to b that is a -- composition of several effectful functions. The paremeter r describes -- the overall effect. The composition members are accumulated in a -- type-aligned queue. type Arrs r a b = FTCQueue (Eff r) a b data Union (r :: [* -> *]) v -- | A data type for representing nondeterminstic choice data NonDetEff a MZero :: NonDetEff a MPlus :: NonDetEff Bool -- | A handler for nondeterminstic effects makeChoiceA :: Alternative f => Eff (NonDetEff : r) a -> Eff r (f a) msplit :: Member NonDetEff r => Eff r a -> Eff r (Maybe (a, Eff r a)) decomp :: Union (t : r) v -> Either (Union r v) (t v) -- | Build a leaf from a single operation [O(1)] tsingleton :: (a -> m b) -> FTCQueue m a b -- | Function application in the context of an array of effects, Arrs r b w qApp :: Arrs r b w -> b -> Eff r w -- | Composition of effectful arrows Allows for the caller to change the -- effect environment, as well qComp :: Arrs r a b -> (Eff r b -> Eff r' c) -> Arr r' a c -- | send a request and wait for a reply send :: Member t r => t v -> Eff r v -- | Runs a set of Effects. Requires that all effects are consumed. -- Typically composed as follows: > run . runEff1 eff1Arg . runEff2 -- eff2Arg1 eff2Arg2 (program) run :: Eff '[] w -> w -- | Runs a set of Effects. Requires that all effects are consumed, except -- for a single effect known to be a monad. The value returned is a -- computation in that monad. This is useful for plugging in traditional -- transformer stacks. runM :: Monad m => Eff '[m] w -> m w -- | Given a request, either handle it or relay it. handleRelay :: (a -> Eff r w) -> (forall v. t v -> Arr r v w -> Eff r w) -> Eff (t : r) a -> Eff r w -- | Parameterized handleRelay Allows sending along some state to be -- handled for the target effect, or relayed to a handler that can handle -- the target effect. handleRelayS :: s -> (s -> a -> Eff r w) -> (forall v. s -> t v -> (s -> Arr r v w) -> Eff r w) -> Eff (t : r) a -> Eff r w -- | Intercept the request and possibly reply to it, but leave it unhandled interpose :: Member t r => (a -> Eff r w) -> (forall v. t v -> Arr r v w -> Eff r w) -> Eff r a -> Eff r w instance GHC.Base.Functor (Control.Monad.Freer.Internal.Eff r) instance GHC.Base.Applicative (Control.Monad.Freer.Internal.Eff r) instance GHC.Base.Monad (Control.Monad.Freer.Internal.Eff r) instance Data.Open.Union.Member Control.Monad.Freer.Internal.NonDetEff r => GHC.Base.Alternative (Control.Monad.Freer.Internal.Eff r) instance Data.Open.Union.Member Control.Monad.Freer.Internal.NonDetEff r => GHC.Base.MonadPlus (Control.Monad.Freer.Internal.Eff r) -- | An effect to compose functions with the ability to yield. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Coroutine -- | A type representing a yielding of control a: The current type b: The -- input to the continuation function v: The output of the continuation data Yield a b v -- | Lifts a value and a function into the Coroutine effect yield :: (Member (Yield a b) r) => a -> (b -> c) -> Eff r c -- | Status of a thread: done or reporting the value of the type a and -- resuming with the value of type b data Status r a b Done :: Status r a b Continue :: a -> (b -> Eff r (Status r a b)) -> Status r a b -- | Launch a thread and report its status runC :: Eff (Yield a b : r) w -> Eff r (Status r a b) instance GHC.Base.Functor (Control.Monad.Freer.Coroutine.Yield a b) -- | Composable handler for Exception effects. Communicates success/failure -- via an Either type. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Exception -- | Exceptions of the type e; no resumption newtype Exc e v Exc :: e -> Exc e v -- | Throws an error carrying information of type e throwError :: (Member (Exc e) r) => e -> Eff r a -- | Handler for exception effects If there are no exceptions thrown, -- returns Right If exceptions are thrown and not handled, returns Left, -- interrupting the execution of any other effect handlers. runError :: Eff (Exc e : r) a -> Eff r (Either e a) -- | A catcher for Exceptions. Handlers are allowed to rethrow exceptions. catchError :: Member (Exc e) r => Eff r a -> (e -> Eff r a) -> Eff r a -- | Composable handler for logical Cut effects. Implemented in terms of -- Exc effect. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Cut data CutFalse -- | Implementation of logical Cut using Exc effects. cutFalse :: Member (Exc CutFalse) r => Eff r a -- | Composable handler for Fresh effects. This is likely to be of use when -- implementing De Bruijn naming/scopes. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Fresh -- | Fresh effect model data Fresh v -- | Request a fresh effect fresh :: Member Fresh r => Eff r Int -- | Handler for Fresh effects, with an Int for a starting value runFresh' :: Eff (Fresh : r) w -> Int -> Eff r w -- | Composable handler for Reader effects. Handy for encapsulating an -- environment with immutable state for interpreters. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Reader data Reader e v Reader :: Reader e e -- | Request a value for the environment ask :: (Member (Reader e) r) => Eff r e -- | Request a value from the environment and applys as function asks :: (b -> a) -> Eff '[Reader b] a -- | Handler for reader effects runReader :: Eff (Reader e : r) w -> e -> Eff r w -- | Locally rebind the value in the dynamic environment This function is -- like a relay; it is both an admin for Reader requests, and a requestor -- of them local :: Member (Reader e) r => (e -> e) -> Eff r a -> Eff r a -- | Composable handler for State effects. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.State -- | Strict State effects: one can either Get values or Put them data State s v -- | Retrieve state get :: Member (State s) r => Eff r s -- | Store state put :: Member (State s) r => s -> Eff r () -- | Modify state modify :: Member (State s) r => (s -> s) -> Eff r () -- | Handler for State effects runState :: Eff (State s : r) w -> s -> Eff r (w, s) -- | An encapsulated State handler, for transactional semantics The global -- state is updated only if the transactionState finished successfully transactionState :: Member (State s) r => Proxy s -> Eff r w -> Eff r w -- | Writer effects, for writing changes to an attached environment. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Writer -- | Writer effects - send outputs to an effect environment data Writer o x Writer :: o -> Writer o () -- | Send a change to the attached environment tell :: Member (Writer o) r => o -> Eff r () -- | Simple handler for Writer effects runWriter :: Monoid o => Eff (Writer o : r) a -> Eff r (a, o) -- | Composable handler for State effects in terms of Reader/Writer -- effects. This module is more a tutorial on how to compose handlers. It -- is slightly slower than a dedicated State handler. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.StateRW -- | State handler, using Reader/Writer effects runStateR :: Eff (Writer s : (Reader s : r)) w -> s -> Eff r (w, s) data Reader e v -- | Writer effects - send outputs to an effect environment data Writer o x -- | Send a change to the attached environment tell :: Member (Writer o) r => o -> Eff r () -- | Request a value for the environment ask :: (Member (Reader e) r) => Eff r e -- | Composable handler for Trace effects. Trace allows one to debug the -- operation of sequences of effects by outputing to the console. -- -- Using http://okmij.org/ftp/Haskell/extensible/Eff1.hs as a -- starting point. module Control.Monad.Freer.Trace -- | A Trace effect; takes a String and performs output data Trace v -- | Printing a string in a trace trace :: Member Trace r => String -> Eff r () -- | An IO handler for Trace effects runTrace :: Eff '[Trace] w -> IO w module Control.Monad.Freer class (Member' t r (FindElem t r)) => Member t r -- | The Eff representation. -- -- Status of a coroutine (client): * Val: Done with the value of type a * -- E : Sending a request of type Union r with the continuation Arrs r b a data Eff r a -- | Runs a set of Effects. Requires that all effects are consumed. -- Typically composed as follows: > run . runEff1 eff1Arg . runEff2 -- eff2Arg1 eff2Arg2 (program) run :: Eff '[] w -> w -- | send a request and wait for a reply send :: Member t r => t v -> Eff r v -- | A data type for representing nondeterminstic choice data NonDetEff a MZero :: NonDetEff a MPlus :: NonDetEff Bool -- | A handler for nondeterminstic effects makeChoiceA :: Alternative f => Eff (NonDetEff : r) a -> Eff r (f a) msplit :: Member NonDetEff r => Eff r a -> Eff r (Maybe (a, Eff r a))