module Control.Monad.Hefty.Except (
module Control.Monad.Hefty.Except,
module Data.Effect.Except,
)
where
import Control.Monad.Hefty (
AlgHandler,
Eff,
FOEs,
In,
interposeInWith,
interpret,
interpretBy,
(&),
type (~~>),
)
import Data.Effect.Except
runExcept :: forall e es a. (FOEs es) => Eff (Catch e ': Throw e ': es) a -> Eff es (Either e a)
runExcept :: forall e (es :: [Effect]) a.
FOEs es =>
Eff (Catch e : Throw e : es) a -> Eff es (Either e a)
runExcept = Eff (Throw e : es) a -> Eff es (Either e a)
forall e (es :: [Effect]) a.
FOEs es =>
Eff (Throw e : es) a -> Eff es (Either e a)
runThrow (Eff (Throw e : es) a -> Eff es (Either e a))
-> (Eff (Catch e : Throw e : es) a -> Eff (Throw e : es) a)
-> Eff (Catch e : Throw e : es) a
-> Eff es (Either e a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff (Catch e : Throw e : es) a -> Eff (Throw e : es) a
forall e (es :: [Effect]) a.
(In (Throw e) es, FOEs es) =>
Eff (Catch e : es) a -> Eff es a
runCatch
{-# INLINE runExcept #-}
runThrow :: forall e es a. (FOEs es) => Eff (Throw e ': es) a -> Eff es (Either e a)
runThrow :: forall e (es :: [Effect]) a.
FOEs es =>
Eff (Throw e : es) a -> Eff es (Either e a)
runThrow = (a -> Eff es (Either e a))
-> AlgHandler
(Throw e) (Eff (Throw e : es)) (Eff Freer es) (Either e a)
-> Eff (Throw e : es) a
-> Eff es (Either e a)
forall (e :: Effect) (es :: [Effect]) ans a.
(KnownOrder e, FOEs es) =>
(a -> Eff es ans)
-> AlgHandler e (Eff (e : es)) (Eff es) ans
-> Eff (e : es) a
-> Eff es ans
interpretBy (Either e a -> Eff es (Either e a)
forall a. a -> Eff Freer es a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either e a -> Eff es (Either e a))
-> (a -> Either e a) -> a -> Eff es (Either e a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either e a
forall a b. b -> Either a b
Right) Throw e (Eff (Throw e : es)) x
-> (x -> Eff es (Either e a)) -> Eff es (Either e a)
AlgHandler
(Throw e) (Eff (Throw e : es)) (Eff Freer es) (Either e a)
forall e (f :: * -> *) (g :: * -> *) a.
Applicative g =>
AlgHandler (Throw e) f g (Either e a)
handleThrow
{-# INLINE runThrow #-}
runCatch :: forall e es a. (Throw e `In` es, FOEs es) => Eff (Catch e ': es) a -> Eff es a
runCatch :: forall e (es :: [Effect]) a.
(In (Throw e) es, FOEs es) =>
Eff (Catch e : es) a -> Eff es a
runCatch = (Catch e ~~> Eff Freer es)
-> Eff Freer (Catch e : es) a -> Eff Freer es a
forall (e :: Effect) (es :: [Effect]) (ff :: Effect) a
(c :: (* -> *) -> Constraint).
(KnownOrder e, Free c ff) =>
(e ~~> Eff ff es) -> Eff ff (e : es) a -> Eff ff es a
interpret Catch e (Eff Freer es) x -> Eff es x
Catch e ~~> Eff Freer es
forall e (es :: [Effect]).
(In (Throw e) es, FOEs es) =>
Catch e ~~> Eff es
handleCatch
{-# INLINE runCatch #-}
handleThrow :: forall e f g a. (Applicative g) => AlgHandler (Throw e) f g (Either e a)
handleThrow :: forall e (f :: * -> *) (g :: * -> *) a.
Applicative g =>
AlgHandler (Throw e) f g (Either e a)
handleThrow (Throw e
e) x -> g (Either e a)
_ = Either e a -> g (Either e a)
forall a. a -> g a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either e a -> g (Either e a)) -> Either e a -> g (Either e a)
forall a b. (a -> b) -> a -> b
$ e -> Either e a
forall a b. a -> Either a b
Left e
e
{-# INLINE handleThrow #-}
handleCatch :: forall e es. (Throw e `In` es, FOEs es) => Catch e ~~> Eff es
handleCatch :: forall e (es :: [Effect]).
(In (Throw e) es, FOEs es) =>
Catch e ~~> Eff es
handleCatch (Catch Eff es x
action e -> Eff es x
hdl) = Eff es x
action Eff es x -> (Eff es x -> Eff es x) -> Eff es x
forall a b. a -> (a -> b) -> b
& AlgHandler (Throw e) (Eff es) (Eff es) x -> Eff es x -> Eff es x
forall (e :: Effect) (es :: [Effect]) a.
(In e es, FOEs es) =>
AlgHandler e (Eff es) (Eff es) a -> Eff es a -> Eff es a
interposeInWith \(Throw e
e) x -> Eff es x
_ -> e -> Eff es x
hdl e
e
{-# INLINE handleCatch #-}