-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | An Alternative to Monad Transformers
--   
--   This package introduces datatypes for typeclass-constrained effects,
--   as an alternative to monad-transformer based (datatype-constrained)
--   approach of multi-layered effects. For more information, see the
--   original paper at
--   <a>http://okmij.org/ftp/Haskell/extensible/exteff.pdf</a>. Any help is
--   appreciated!
@package extensible-effects
@version 2.4.0.0


-- | Open unions (type-indexed co-products) for extensible effects All
--   operations are constant-time, and there is no Typeable constraint
--   
--   This is a variation of OpenUion5.hs, which relies on overlapping
--   instances instead of closed type families. Closed type families have
--   their problems: overlapping instances can resolve even for unground
--   types, but closed type families are subject to a strict apartness
--   condition.
--   
--   This implementation is very similar to OpenUnion1.hs, but without the
--   annoying Typeable constraint. We sort of emulate it:
--   
--   Our list r of open union components is a small Universe. Therefore, we
--   can use the Typeable-like evidence in that universe. We hence can
--   define
--   
--   <pre>
--   data Union r v where
--     Union :: t v -&gt; TRep t r -&gt; Union r v -- t is existential
--   </pre>
--   
--   where
--   
--   <pre>
--   data TRep t r where
--     T0 :: TRep t (t ': r)
--     TS :: TRep t r -&gt; TRep (any ': r)
--   </pre>
--   
--   Then Member is a type class that produces TRep Taken literally it
--   doesn't seem much better than OpenUinion41.hs. However, we can cheat
--   and use the index of the type t in the list r as the TRep. (We will
--   need UnsafeCoerce then).
--   
--   The interface is the same as of other OpenUnion*.hs
module Data.OpenUnion

-- | The data constructors of Union are not exported
--   
--   Strong Sum (Existential with the evidence) is an open union t is can
--   be a GADT and hence not necessarily a Functor. Int is the index of t
--   in the list r; that is, the index of t in the universe r
data Union (r :: [* -> *]) v
inj :: Member t r => t v -> Union r v
prj :: Member t r => Union r v -> Maybe (t v)
decomp :: Union (t : r) v -> Either (Union r v) (t v)
class (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)

-- | This class is used for emulating monad transformers
class Member t r => SetMember (tag :: k -> * -> *) (t :: * -> *) r | tag r -> t
weaken :: Union r w -> Union (any : r) w
instance forall k (t1 :: * -> *) (t2 :: * -> *) (p :: GHC.Types.Bool) (tag :: k -> * -> *) (r :: [* -> *]). (Data.OpenUnion.EQU t1 t2 p, Data.OpenUnion.MemberU' p tag t1 (t2 : r)) => Data.OpenUnion.SetMember tag t1 (t2 : r)
instance forall k (tag :: k -> * -> *) (e :: k) (r :: [* -> *]). Data.OpenUnion.MemberU' 'GHC.Types.True tag (tag e) (tag e : r)
instance forall k (t :: * -> *) (t' :: * -> *) (r :: [* -> *]) (tag :: k -> * -> *). (Data.OpenUnion.Member t (t' : r), Data.OpenUnion.SetMember tag t r) => Data.OpenUnion.MemberU' 'GHC.Types.False tag t (t' : r)
instance forall k (a :: k). Data.OpenUnion.EQU a a 'GHC.Types.True
instance forall k (p :: GHC.Types.Bool) (a :: k) (b :: k). p ~ 'GHC.Types.False => Data.OpenUnion.EQU a b p
instance t ~ s => Data.OpenUnion.Member t '[s]
instance Data.OpenUnion.FindElem t r => Data.OpenUnion.Member t r
instance Data.OpenUnion.FindElem t (t : r)
instance forall a (t :: * -> *) (r :: [a]) (t' :: a). Data.OpenUnion.FindElem t r => Data.OpenUnion.FindElem t (t' : r)
instance (TypeError ...) => Data.OpenUnion.FindElem t '[]


-- | A monadic library for communication between a handler and its client,
--   the administered computation
--   
--   Original work available at
--   <a>http://okmij.org/ftp/Haskell/extensible/tutorial.html</a>. This
--   module implements extensible effects as an alternative to monad
--   transformers, as described in
--   <a>http://okmij.org/ftp/Haskell/extensible/exteff.pdf</a> and
--   <a>http://okmij.org/ftp/Haskell/extensible/more.pdf</a>.
--   
--   Extensible Effects are implemented as typeclass constraints on an
--   Eff[ect] datatype. A contrived example can be found under
--   <a>Control.Eff.Example</a>. To run the effects, consult the tests.
module Control.Eff

-- | 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 <tt>a</tt> to <tt>b</tt> that is a
--   composition of one or more effectful functions. The paremeter r
--   describes the overall effect.
--   
--   The composition members are accumulated in a type-aligned queue. Using
--   a newtype here enables us to define <tt>Category</tt> and
--   <tt>Arrow</tt> instances.
newtype Arrs r a b
Arrs :: (FTCQueue (Eff r) a b) -> Arrs r a b

-- | <a>Arrs</a> can be composed and have a natural identity.

-- | As the name suggests, <a>Arrs</a> also has an <tt>Arrow</tt> instance.
first :: Arr r a b -> Arr r (a, c) (b, c)

-- | convert single effectful arrow into composable type. i.e., convert
--   <a>Arr</a> to <a>Arrs</a>
singleK :: Arr r a b -> Arrs r a b

-- | Application to the `generalized effectful function' Arrs r b w, i.e.,
--   convert <a>Arrs</a> to <a>Arr</a>
qApp :: forall r b w. Arrs r b w -> Arr r b w

-- | Syntactic sugar for <a>qApp</a>
(^$) :: forall r b w. Arrs r b w -> Arr r b w

-- | Lift a function to an arrow
arr :: (a -> b) -> Arrs r a b

-- | The identity arrow
ident :: Arrs r a a

-- | Arrow composition
comp :: Arrs r a b -> Arrs r b c -> Arrs r a c

-- | Common pattern: append <a>Arr</a> to <a>Arrs</a>
(^|>) :: Arrs r a b -> Arr r b c -> Arrs r a c

-- | The Eff monad (not a transformer!). It is a fairly standard coroutine
--   monad where the type <tt>r</tt> is the type of effects that can be
--   handled, and the missing type <tt>a</tt> (from the type application)
--   is the type of value that is returned. It is NOT a Free monad! There
--   are no Functor constraints.
--   
--   The two constructors denote the status of a coroutine (client): done
--   with the value of type a, or sending a request of type Union r with
--   the continuation Arrs r b a. Expressed another way: an <a>Eff</a> can
--   either be a value (i.e., <a>Val</a> case), or an effect of type
--   <tt><a>Union</a> r</tt> producing another <a>Eff</a> (i.e., <a>E</a>
--   case). The result is that an <a>Eff</a> can produce an arbitrarily
--   long chain of <tt><a>Union</a> r</tt> effects, terminated with a pure
--   value.
--   
--   Potentially, inline Union into E
data Eff r a
Val :: a -> Eff r a
E :: (Union r b) -> (Arrs r b a) -> Eff r a

-- | Compose effectful arrows (and possibly change the effect!)
qComp :: Arrs r a b -> (Eff r b -> Eff r' c) -> Arr r' a c

-- | Compose effectful arrows (and possibly change the effect!)
qComps :: Arrs r a b -> (Eff r b -> Eff r' c) -> Arrs r' a c

-- | Eff is still a monad and a functor (and Applicative) (despite the lack
--   of the Functor constraint)

-- | Send a request and wait for a reply (resulting in an effectful
--   computation).
send :: Member t r => t v -> Eff r v

-- | The initial case, no effects. Get the result from a pure computation.
--   
--   The type of run ensures that all effects must be handled: only pure
--   computations may be run.
run :: Eff '[] w -> w

-- | A convenient pattern: given a request (open union), either handle it
--   or relay it.
handle_relay :: (a -> Eff r w) -> (forall v. t v -> Arr r v w -> Eff r w) -> Eff (t : r) a -> Eff r w

-- | Parameterized handle_relay
handle_relay_s :: 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

-- | Add something like Control.Exception.catches? It could be useful for
--   control with cut.
--   
--   Intercept the request and possibly reply to it, but leave it unhandled
--   (that's why we use the same r all throuout)
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 Control.Category.Category (Control.Eff.Arrs r)
instance Control.Arrow.Arrow (Control.Eff.Arrs r)
instance GHC.Base.Functor (Control.Eff.Eff r)
instance GHC.Base.Applicative (Control.Eff.Eff r)
instance GHC.Base.Monad (Control.Eff.Eff r)


-- | Strict write-only state
module Control.Eff.Writer.Strict

-- | The Writer monad
--   
--   In MTL's Writer monad, the told value must have a |Monoid| type. Our
--   writer has no such constraints. If we write a |Writer|-like
--   interpreter to accumulate the told values in a monoid, it will have
--   the |Monoid w| constraint then
data Writer w v
[Tell] :: !w -> Writer w ()

-- | Write a new value.
tell :: Member (Writer w) r => w -> Eff r ()

-- | Transform the state being produced.
censor :: forall w a r. Member (Writer w) r => (w -> w) -> Eff r a -> Eff r a

-- | Handle Writer requests, using a user-provided function to accumulate
--   values, hence no Monoid constraints.
runWriter :: (w -> b -> b) -> b -> Eff (Writer w : r) a -> Eff r (a, b)

-- | Handle Writer requests by taking the first value provided.
runFirstWriter :: Eff (Writer w : r) a -> Eff r (a, Maybe w)

-- | Handle Writer requests by overwriting previous values.
runLastWriter :: Eff (Writer w : r) a -> Eff r (a, Maybe w)

-- | Handle Writer requests, using a List to accumulate values.
runListWriter :: Eff (Writer w : r) a -> Eff r (a, [w])

-- | Handle Writer requests, using a Monoid instance to accumulate values.
runMonoidWriter :: (Monoid w) => Eff (Writer w : r) a -> Eff r (a, w)


-- | Lazy write-only state
module Control.Eff.Writer.Lazy

-- | The Writer monad
--   
--   In MTL's Writer monad, the told value must have a |Monoid| type. Our
--   writer has no such constraints. If we write a |Writer|-like
--   interpreter to accumulate the told values in a monoid, it will have
--   the |Monoid w| constraint then
data Writer w v
[Tell] :: w -> Writer w ()

-- | Write a new value.
tell :: Member (Writer w) r => w -> Eff r ()

-- | Transform the state being produced.
censor :: forall w a r. Member (Writer w) r => (w -> w) -> Eff r a -> Eff r a

-- | Handle Writer requests, using a user-provided function to accumulate
--   values, hence no Monoid constraints.
runWriter :: (w -> b -> b) -> b -> Eff (Writer w : r) a -> Eff r (a, b)

-- | Handle Writer requests by taking the first value provided.
runFirstWriter :: Eff (Writer w : r) a -> Eff r (a, Maybe w)

-- | Handle Writer requests by overwriting previous values.
runLastWriter :: Eff (Writer w : r) a -> Eff r (a, Maybe w)

-- | Handle Writer requests, using a List to accumulate values.
runListWriter :: Eff (Writer w : r) a -> Eff r (a, [w])

-- | Handle Writer requests, using a Monoid instance to accumulate values.
runMonoidWriter :: (Monoid w) => Eff (Writer w : r) a -> Eff r (a, w)


-- | A Trace effect for debugging
module Control.Eff.Trace

-- | Trace effect for debugging
data Trace v
[Trace] :: String -> Trace ()

-- | Print a string as a trace.
trace :: Member Trace r => String -> Eff r ()

-- | Run a computation producing Traces. The handler for IO request: a
--   terminal handler
runTrace :: Eff '[Trace] w -> IO w


-- | On-demand state computation: example taken from Edward Kmett's comment
--   here:
--   <a>http://www.reddit.com/r/haskell/comments/387ex0/are_extensible_effects_a_complete_replacement_for/crt1pzm</a>
--   
--   Extensible effects make it clear that where the computation is delayed
--   and they do maintain the degree of extensibility (the delayed
--   computation must be effect-closed, but the whole computation does not
--   have to be).
module Control.Eff.State.LazyState

-- | Define a new effect for state on-demand (in ExtEff, the state is by
--   default strict -- as it should be if we want the predictable
--   performance and effect sequencing)
data LazyState s v
[LGet] :: LazyState s s
[LPut] :: s -> LazyState s ()
[Delay] :: Eff '[LazyState s] a -> LazyState s a

-- | Primitive state operations
lget :: Member (LazyState s) r => Eff r s
lput :: Member (LazyState s) r => s -> Eff r ()
lmodify :: (Member (LazyState s) r, Member (LazyState t) r) => (t -> s) -> Eff r ()
onDemand :: Member (LazyState s) r => Eff '[LazyState s] v -> Eff r v

-- | The handler
runStateLazy :: s -> Eff (LazyState s : r) a -> Eff r (a, s)

-- | Backwards state The overall state is represented with two attributes:
--   the inherited getAttr and the synthesized putAttr. At the root node,
--   putAttr becomes getAttr, tying the knot. As usual, the inherited
--   attribute is the argument (i.e., the <tt>environment</tt>) and the
--   synthesized is the result of the handler |go| below.
runStateBack0 :: Eff '[LazyState s] a -> (a, s)

-- | Another implementation, exploring Haskell's laziness to make putAttr
--   also technically inherited, to accumulate the sequence of updates.
--   This implementation is compatible with deep handlers, and lets us play
--   with different notions of <tt>backwardness</tt>
runStateBack :: Eff '[LazyState s] a -> (a, s)


-- | Strict read-only state
module Control.Eff.Reader.Strict

-- | The Reader monad
--   
--   The request for a value of type e from the current environment This
--   can be expressed as a GADT because the type of values returned in
--   response to a (Reader e a) request is not any a; we expect in reply
--   the value of type <tt>e</tt>, the value from the environment. So, the
--   return type is restricted: 'a ~ e'
--   
--   One can also define this as
--   
--   <pre>
--   data Reader e v = (e ~ v) =&gt; Reader
--   </pre>
--   
--   ^ without GADTs, using explicit coercion as is done here.
--   
--   <pre>
--   newtype Reader e v = Reader (e-&gt;v)
--   </pre>
--   
--   ^ In the latter case, when we make the request, we make it as Reader
--   id. So, strictly speaking, GADTs are not really necessary.
data Reader e v
[Reader] :: Reader e e

-- | Get the current value from a Reader. The signature is inferred (when
--   using NoMonomorphismRestriction).
ask :: (Member (Reader e) r) => Eff r e

-- | 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 :: forall e a r. Member (Reader e) r => (e -> e) -> Eff r a -> Eff r a

-- | Request the environment value using a transformation function.
reader :: (Member (Reader e) r) => (e -> a) -> Eff r a

-- | The handler of Reader requests. The return type shows that all Reader
--   requests are fully handled.
runReader :: Eff (Reader e : r) w -> e -> Eff r w


-- | Strict state effect
module Control.Eff.State.Strict

-- | State, strict
--   
--   Initial design: The state request carries with it the state mutator
--   function We can use this request both for mutating and getting the
--   state. But see below for a better design!
--   
--   <pre>
--   data State s v where
--     State :: (s-&gt;s) -&gt; State s s
--   </pre>
--   
--   In this old design, we have assumed that the dominant operation is
--   modify. Perhaps this is not wise. Often, the reader is most nominant.
--   
--   See also below, for decomposing the State into Reader and Writer!
--   
--   The conventional design of State
data State s v
[Get] :: State s s
[Put] :: !s -> State s ()

-- | Return the current value of the state. The signatures are inferred
get :: Member (State s) r => Eff r s

-- | Write a new value of the state.
put :: Member (State s) r => s -> Eff r ()
runState' :: Eff (State s : r) w -> s -> Eff r (w, s)

-- | Run a State effect
runState :: Eff (State s : r) w -> s -> Eff r (w, s)

-- | Transform the state with a function.
modify :: (Member (State s) r) => (s -> s) -> Eff r ()

-- | Run a State effect, discarding the final state.
evalState :: Eff (State s : r) w -> s -> Eff r w

-- | Run a State effect and return the final state.
execState :: Eff (State s : r) w -> s -> Eff r s

-- | An encapsulated State handler, for transactional semantics The global
--   state is updated only if the transactionState finished successfully
data TxState s
TxState :: TxState s
transactionState :: forall s r w. Member (State s) r => TxState s -> Eff r w -> Eff r w

-- | A different representation of State: decomposing State into mutation
--   (Writer) and Reading. We don't define any new effects: we just handle
--   the existing ones. Thus we define a handler for two effects together.
runStateR :: Eff (Writer s : (Reader s : r)) w -> s -> Eff r (w, s)


-- | Lazy read-only state
module Control.Eff.Reader.Lazy

-- | The Reader monad
--   
--   The request for a value of type e from the current environment This
--   can be expressed as a GADT because the type of values returned in
--   response to a (Reader e a) request is not any a; we expect in reply
--   the value of type <tt>e</tt>, the value from the environment. So, the
--   return type is restricted: 'a ~ e'
--   
--   One can also define this as
--   
--   <pre>
--   data Reader e v = (e ~ v) =&gt; Reader
--   </pre>
--   
--   ^ without GADTs, using explicit coercion as is done here.
--   
--   <pre>
--   newtype Reader e v = Reader (e-&gt;v)
--   </pre>
--   
--   ^ In the latter case, when we make the request, we make it as Reader
--   id. So, strictly speaking, GADTs are not really necessary.
data Reader e v
[Reader] :: Reader e e

-- | Get the current value from a Reader. The signature is inferred (when
--   using NoMonomorphismRestriction).
ask :: (Member (Reader e) r) => Eff r e

-- | 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 :: forall e a r. Member (Reader e) r => (e -> e) -> Eff r a -> Eff r a

-- | Request the environment value using a transformation function.
reader :: (Member (Reader e) r) => (e -> a) -> Eff r a

-- | The handler of Reader requests. The return type shows that all Reader
--   requests are fully handled.
runReader :: Eff (Reader e : r) w -> e -> Eff r w


-- | Lazy state effect
module Control.Eff.State.Lazy

-- | State, lazy (i.e., on-demand)
--   
--   Extensible effects make it clear that where the computation is delayed
--   (which I take as an advantage) and they do maintain the degree of
--   extensibility (the delayed computation must be effect-closed, but the
--   whole computation does not have to be).
data State s v
[Get] :: State s s
[Put] :: s -> State s ()
[Delay] :: Eff '[State s] a -> State s a

-- | Return the current value of the state. The signatures are inferred
get :: Member (State s) r => Eff r s

-- | Write a new value of the state.
put :: Member (State s) r => s -> Eff r ()
onDemand :: Member (State s) r => Eff '[State s] v -> Eff r v
runState' :: Eff (State s : r) w -> s -> Eff r (w, s)

-- | Run a State effect
runState :: Eff (State s : r) w -> s -> Eff r (w, s)

-- | Transform the state with a function.
modify :: (Member (State s) r) => (s -> s) -> Eff r ()

-- | Run a State effect, discarding the final state.
evalState :: Eff (State s : r) w -> s -> Eff r w

-- | Run a State effect and return the final state.
execState :: Eff (State s : r) w -> s -> Eff r s

-- | A different representation of State: decomposing State into mutation
--   (Writer) and Reading. We don't define any new effects: we just handle
--   the existing ones. Thus we define a handler for two effects together.
runStateR :: Eff (Writer s : (Reader s : r)) w -> s -> Eff r (w, s)

-- | Backwards state The overall state is represented with two attributes:
--   the inherited getAttr and the synthesized putAttr. At the root node,
--   putAttr becomes getAttr, tying the knot. As usual, the inherited
--   attribute is the argument (i.e., the <tt>environment</tt>) and the
--   synthesized is the result of the handler |go| below.
runStateBack0 :: Eff '[State s] a -> (a, s)

-- | A different notion of <tt>backwards</tt> is realized if we change the
--   Put handler slightly. How?
--   
--   Another implementation, exploring Haskell's laziness to make putAttr
--   also technically inherited, to accumulate the sequence of updates.
--   This implementation is compatible with deep handlers, and lets us play
--   with different notions of <tt>backwardness</tt>
runStateBack :: Eff '[State s] a -> (a, s)


-- | Operational Monad (<a>https://wiki.haskell.org/Operational</a>)
--   implemented with extensible effects.
module Control.Eff.Operational

-- | Lift values to an effect. You can think this is a generalization of
--   <tt>Lift</tt>.
data Program instr v
[Singleton] :: instr a -> Program instr a

-- | Lift a value to a monad.
singleton :: (Member (Program instr) r) => instr a -> Eff r a

-- | Convert values using given interpreter to effects.
runProgram :: forall f r a. (forall x. f x -> Eff r x) -> Eff (Program f : r) a -> Eff r a


-- | Another implementation of nondeterministic choice effect
module Control.Eff.NdetEff

-- | A different implementation, more directly mapping to MonadPlus
--   interface
data NdetEff a
[MZero] :: NdetEff a
[MPlus] :: NdetEff Bool

-- | An interpreter The following is very simple, but leaks a lot of memory
--   The cause probably is mapping every failure to empty It takes then a
--   lot of timne and space to store those empty
makeChoiceA0 :: Alternative f => Eff (NdetEff : r) a -> Eff r (f a)

-- | A different implementation, more involved but faster and taking much
--   less (100 times) less memory. The benefit of the effect framework is
--   that we can have many interpreters.
makeChoiceA :: Alternative f => Eff (NdetEff : r) a -> Eff r (f a)
msplit :: Member NdetEff r => Eff r a -> Eff r (Maybe (a, Eff r a))
ifte :: Member NdetEff r => Eff r a -> (a -> Eff r b) -> Eff r b -> Eff r b
once :: Member NdetEff r => Eff r a -> Eff r a
instance Data.OpenUnion.Member Control.Eff.NdetEff.NdetEff r => GHC.Base.Alternative (Control.Eff.Eff r)
instance Data.OpenUnion.Member Control.Eff.NdetEff.NdetEff r => GHC.Base.MonadPlus (Control.Eff.Eff r)


-- | Lifting primitive Monad types to effectful computations. We only allow
--   a single Lifted Monad because Monads aren't commutative (e.g. Maybe
--   (IO a) is functionally distinct from IO (Maybe a)).
module Control.Eff.Lift

-- | Lifting: emulating monad transformers
newtype Lift m a
Lift :: (m a) -> Lift m a

-- | We make the Lift layer to be unique, using SetMember
lift :: (SetMember Lift (Lift m) r) => m a -> Eff r a

-- | The handler of Lift requests. It is meant to be terminal: we only
--   allow a single Lifted Monad.
runLift :: Monad m => Eff '[Lift m] w -> m w

-- | Catching of dynamic exceptions See the problem in
--   <a>http://okmij.org/ftp/Haskell/misc.html#catch-MonadIO</a>
catchDynE :: forall e a r. (SetMember Lift (Lift IO) r, Exception e) => Eff r a -> (e -> Eff r a) -> Eff r a


-- | Example usage of <a>Control.Eff.Operational</a>.
module Control.Eff.Operational.Example

-- | Define data using GADTs.
data Jail a
[Print] :: String -> Jail ()
[Scan] :: Jail String
prog :: Member (Program Jail) r => Eff r ()

-- | Then, implements interpreters from the data to effects.
adventIO :: (SetMember Lift (Lift IO) r) => Jail a -> Eff r a
adventPure :: (Member (Writer String) r, Member (State [String]) r) => Jail a -> Eff r a


-- | Create unique Enumerable values.
module Control.Eff.Fresh

-- | Create unique Enumerable values.
data Fresh v
[Fresh] :: Fresh Int

-- | Produce a value that has not been previously produced.
fresh :: Member Fresh r => Eff r Int

-- | Run an effect requiring unique values.
runFresh' :: Eff (Fresh : r) w -> Int -> Eff r w


-- | Exception-producing and exception-handling effects
module Control.Eff.Exception

-- | Exceptions
--   
--   exceptions of the type e; no resumption
newtype Exc e v
Exc :: e -> Exc e v
type Fail = Exc ()

-- | Throw an exception in an effectful computation. The type is inferred.
throwError :: (Member (Exc e) r) => e -> Eff r a

-- | Makes an effect fail, preventing future effects from happening.
die :: Member Fail r => Eff r a

-- | Run a computation that might produce an exception.
runError :: Eff (Exc e : r) a -> Eff r (Either e a)

-- | Runs a failable effect, such that failed computation return
--   <a>Nothing</a>, and <a>Just</a> the return value on success.
runFail :: Eff (Fail : r) a -> Eff r (Maybe a)

-- | Run a computation that might produce exceptions, and give it a way to
--   deal with the exceptions that come up. The handler is allowed to
--   rethrow the exception
catchError :: Member (Exc e) r => Eff r a -> (e -> Eff r a) -> Eff r a

-- | Add a default value (i.e. failure handler) to a fallible computation.
--   This hides the fact that a failure happened.
onFail :: Eff (Fail : r) a -> Eff r a -> Eff r a

-- | Run a computation until it produces an exception, and convert and
--   throw that exception in a new context.
rethrowError :: (Member (Exc e') r) => (e -> e') -> Eff (Exc e : r) a -> Eff r a

-- | Treat Lefts as exceptions and Rights as return values.
liftEither :: (Member (Exc e) r) => Either e a -> Eff r a

-- | <a>liftEither</a> in a lifted Monad
liftEitherM :: (Member (Exc e) r, SetMember Lift (Lift m) r) => m (Either e a) -> Eff r a

-- | Lift a maybe into the <a>Fail</a> effect, causing failure if it's
--   <a>Nothing</a>.
liftMaybe :: Member Fail r => Maybe a -> Eff r a

-- | <a>liftMaybe</a> in a lifted Monad
liftMaybeM :: (Member Fail r, SetMember Lift (Lift m) r) => m (Maybe a) -> Eff r a

-- | Ignores a failure event. Since the event can fail, you cannot inspect
--   its return type, because it has none on failure. To inspect it, use
--   <a>runFail</a>.
ignoreFail :: Eff (Fail : r) a -> Eff r ()


-- | Example usage of <a>Control.Eff</a>
module Control.Eff.Example

-- | The datatype for the example from the paper. See the tests for the
--   example
newtype TooBig
TooBig :: Int -> TooBig

-- | specialization to tell the type of the exception
runErrBig :: Eff (Exc TooBig : r) a -> Eff r (Either TooBig a)

-- | Multiple Reader effects
sum2 :: Member (Reader Int) r => Member (Reader Float) r => Eff r Float

-- | Write the elements of a list of numbers, in order.
writeAll :: (Member (Writer a) e) => [a] -> Eff e ()

-- | Add a list of numbers to the current state.
sumAll :: (Num a, Member (State a) e) => [a] -> Eff e ()

-- | Write a list of numbers and add them to the current state.
writeAndAdd :: (Member (Writer a) e, Member (State a) e, Num a) => [a] -> Eff e ()

-- | Sum a list of numbers.
sumEff :: (Num a) => [a] -> a

-- | Safely get the last element of a list. Nothing for empty lists; Just
--   the last element otherwise.
lastEff :: [a] -> Maybe a

-- | Get the last element and sum of a list
lastAndSum :: (Num a) => [a] -> (Maybe a, a)
data Move x
[Move] :: Move ()
handUp :: Eff (Move : r) a -> Eff r a
handDown :: Eff (Move : r) a -> Eff r a
instance GHC.Show.Show Control.Eff.Example.TooBig
instance GHC.Classes.Eq Control.Eff.Example.TooBig


-- | Coroutines implemented with extensible effects
module Control.Eff.Coroutine

-- | Co-routines The interface is intentionally chosen to be the same as in
--   transf.hs
--   
--   | The yield request: reporting a value of type e and suspending the
--   coroutine. Resuming with the value of type b
data Yield a b v
[Yield] :: a -> Yield a b b

-- | Yield a value of type a and suspend the coroutine.
yield :: (Member (Yield a b) r) => a -> Eff r b

-- | Launch a thread and report its status
runC :: Eff (Yield a b : r) w -> Eff r (Y r a b)

-- | Status of a thread: done or reporting the value of the type a (For
--   simplicity, a co-routine reports a value but accepts unit)
--   
--   Type parameter <tt>r</tt> is the effect we're yielding from.
--   
--   Type parameter <tt>a</tt> is the type that is yielded.
--   
--   Type parameter <tt>w</tt> is the type of the value returned from the
--   coroutine when it has completed.
data Y r a w
Y :: a -> (w -> Eff r (Y r a w)) -> Y r a w
Done :: Y r a w


-- | Nondeterministic choice effect
module Control.Eff.Choose

-- | Non-determinism (choice)
--   
--   choose lst non-deterministically chooses one value from the lst choose
--   [] thus corresponds to failure Unlike Reader, Choose is not a GADT
--   because the type of values returned in response to a (Choose a)
--   request is just a, without any constraints.
newtype Choose a
Choose :: [a] -> Choose a

-- | choose lst non-deterministically chooses one value from the lst choose
--   [] thus corresponds to failure
choose :: Member Choose r => [a] -> Eff r a

-- | Run a nondeterministic effect, returning all values.
makeChoice :: forall a r. Eff (Choose : r) a -> Eff r [a]

-- | MonadPlus-like operators are expressible via choose
mzero' :: Member Choose r => Eff r a

-- | MonadPlus-like operators are expressible via choose
mplus' :: Member Choose r => Eff r a -> Eff r a -> Eff r a
instance Data.OpenUnion.Member Control.Eff.Choose.Choose r => GHC.Base.Alternative (Control.Eff.Eff r)
instance Data.OpenUnion.Member Control.Eff.Choose.Choose r => GHC.Base.MonadPlus (Control.Eff.Eff r)


-- | An example of non-trivial interaction of effects, handling of two
--   effects together Non-determinism with control (cut) For the
--   explanation of cut, see Section 5 of Hinze ICFP 2000 paper. Hinze
--   suggests expressing cut in terms of cutfalse:
--   
--   <pre>
--   = return () `mplus` cutfalse
--   where
--    cutfalse :: m a
--   </pre>
--   
--   satisfies the following laws:
--   
--   <pre>
--   cutfalse &gt;&gt;= k  = cutfalse              (F1)
--   cutfalse | m    = cutfalse              (F2)
--   </pre>
--   
--   (note: <tt>m `<tt>mplus</tt>` cutfalse</tt> is different from
--   <tt>cutfalse `<tt>mplus</tt>` m</tt>). In other words, cutfalse is the
--   left zero of both bind and mplus.
--   
--   Hinze also introduces the operation <tt><a>call</a> :: m a -&gt; m
--   a</tt> that delimits the effect of cut: <tt><a>call</a> m</tt>
--   executes m. If the cut is invoked in m, it discards only the choices
--   made since m was called. Hinze postulates the axioms of <a>call</a>:
--   
--   <pre>
--   call false = false                          (C1)
--   call (return a | m) = return a | call m     (C2)
--   call (m | cutfalse) = call m                (C3)
--   call (lift m &gt;&gt;= k) = lift m &gt;&gt;= (call . k) (C4)
--   </pre>
--   
--   <tt><a>call</a> m</tt> behaves like <tt>m</tt> except any cut inside
--   <tt>m</tt> has only a local effect, he says.
--   
--   Hinze noted a problem with the "mechanical" derivation of backtracing
--   monad transformer with cut: no axiom specifying the interaction of
--   call with bind; no way to simplify nested invocations of call.
--   
--   We use exceptions for cutfalse Therefore, the law <tt>cutfalse
--   &gt;&gt;= k = cutfalse</tt> is satisfied automatically since all
--   exceptions have the above property.
module Control.Eff.Cut
data CutFalse
CutFalse :: CutFalse
cutfalse :: Member (Exc CutFalse) r => Eff r a

-- | The interpreter -- it is like reify . reflect with a twist. Compare
--   this implementation with the huge implementation of call in Hinze 2000
--   (Figure 9). Each clause corresponds to the axiom of call or cutfalse.
--   All axioms are covered.
--   
--   The code clearly expresses the intuition that call watches the choice
--   points of its argument computation. When it encounteres a cutfalse
--   request, it discards the remaining choicepoints. It completely handles
--   CutFalse effects but not non-determinism
call :: forall a r. Member Choose r => Eff (Exc CutFalse : r) a -> Eff r a
