{-# LANGUAGE Trustworthy #-}
module Cleff.Output
(
Output (..)
,
output
,
outputToListState, outputToWriter, ignoreOutput, runOutputEff
) where
import Cleff
import Cleff.State
import Cleff.Writer
data Output o :: Effect where
Output :: o -> Output o m ()
makeEffect ''Output
outputToListState :: Eff (Output o ': es) ~> Eff (State [o] ': es)
outputToListState :: Eff (Output o : es) a -> Eff (State [o] : es) a
outputToListState = Handler (Output o) (State [o] : es)
-> Eff (Output o : es) ~> Eff (State [o] : es)
forall (e' :: (Type -> Type) -> Type -> Type)
(e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]).
Handler e (e' : es) -> Eff (e : es) ~> Eff (e' : es)
reinterpret \case
Output x -> ([o] -> [o]) -> Eff (State [o] : es) ()
forall s (es :: [(Type -> Type) -> Type -> Type]).
(State s :> es) =>
(s -> s) -> Eff es ()
modify (o
x o -> [o] -> [o]
forall a. a -> [a] -> [a]
:)
{-# INLINE outputToListState #-}
outputToWriter :: (o -> o') -> Eff (Output o ': es) ~> Eff (Writer o' ': es)
outputToWriter :: (o -> o') -> Eff (Output o : es) ~> Eff (Writer o' : es)
outputToWriter o -> o'
f = Handler (Output o) (Writer o' : es)
-> Eff (Output o : es) ~> Eff (Writer o' : es)
forall (e' :: (Type -> Type) -> Type -> Type)
(e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]).
Handler e (e' : es) -> Eff (e : es) ~> Eff (e' : es)
reinterpret \case
Output x -> o' -> Eff (Writer o' : es) ()
forall w (es :: [(Type -> Type) -> Type -> Type]).
(Writer w :> es) =>
w -> Eff es ()
tell (o' -> Eff (Writer o' : es) ()) -> o' -> Eff (Writer o' : es) ()
forall a b. (a -> b) -> a -> b
$ o -> o'
f o
x
{-# INLINE outputToWriter #-}
ignoreOutput :: Eff (Output o ': es) ~> Eff es
ignoreOutput :: Eff (Output o : es) a -> Eff es a
ignoreOutput = Handler (Output o) es -> Eff (Output o : es) ~> Eff es
forall (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]).
Handler e es -> Eff (e : es) ~> Eff es
interpret \case
Output _ -> () -> Eff es ()
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ()
{-# INLINE ignoreOutput #-}
runOutputEff :: (o -> Eff es ()) -> Eff (Output o ': es) ~> Eff es
runOutputEff :: (o -> Eff es ()) -> Eff (Output o : es) ~> Eff es
runOutputEff o -> Eff es ()
m = Handler (Output o) es -> Eff (Output o : es) ~> Eff es
forall (e :: (Type -> Type) -> Type -> Type)
(es :: [(Type -> Type) -> Type -> Type]).
Handler e es -> Eff (e : es) ~> Eff es
interpret \case
Output x -> o -> Eff es ()
m o
x
{-# INLINE runOutputEff #-}