{-# options_haddock prune #-}
module Polysemy.Process.Effect.Process where
import Polysemy.Input (Input (Input))
import Polysemy.Output (Output (Output))
import Polysemy.Resume (interpretResumable, restop, type (!!))
import Prelude hiding (send)
data Process i o :: Effect where
Recv :: Process i o m o
Send :: i -> Process i o m ()
makeSem_ ''Process
recv ::
∀ i o r .
Member (Process i o) r =>
Sem r o
send ::
∀ i o r .
Member (Process i o) r =>
i ->
Sem r ()
withProcess ::
∀ param i o r .
Member (Scoped param (Process i o)) r =>
param ->
InterpreterFor (Process i o) r
withProcess :: forall param i o (r :: EffectRow).
Member (Scoped param (Process i o)) r =>
param -> InterpreterFor (Process i o) r
withProcess =
forall param (effect :: Effect) (r :: EffectRow).
Member (Scoped param effect) r =>
param -> InterpreterFor effect r
scoped @param
withProcessOneshot ::
∀ param i o err r .
Member (Scoped param (Process i o !! err)) r =>
param ->
InterpreterFor (Process i o !! err) r
withProcessOneshot :: forall param i o err (r :: EffectRow).
Member (Scoped param (Process i o !! err)) r =>
param -> InterpreterFor (Process i o !! err) r
withProcessOneshot =
forall param (effect :: Effect) (r :: EffectRow).
Member (Scoped param effect) r =>
param -> InterpreterFor effect r
scoped @param
withProcess_ ::
∀ i o r .
Member (Scoped_ (Process i o)) r =>
InterpreterFor (Process i o) r
withProcess_ :: forall i o (r :: EffectRow).
Member (Scoped_ (Process i o)) r =>
InterpreterFor (Process i o) r
withProcess_ =
Sem (Process i o : r) a -> Sem r a
InterpreterFor (Process i o) r
forall (effect :: Effect) (r :: EffectRow).
Member (Scoped_ effect) r =>
InterpreterFor effect r
scoped_
withProcessOneshot_ ::
∀ i o err r .
Member (Scoped_ (Process i o !! err)) r =>
InterpreterFor (Process i o !! err) r
withProcessOneshot_ :: forall i o err (r :: EffectRow).
Member (Scoped_ (Process i o !! err)) r =>
InterpreterFor (Process i o !! err) r
withProcessOneshot_ =
Sem ((Process i o !! err) : r) a -> Sem r a
InterpreterFor (Process i o !! err) r
forall (effect :: Effect) (r :: EffectRow).
Member (Scoped_ effect) r =>
InterpreterFor effect r
scoped_
runProcessIO ::
∀ i o r .
Member (Process i o) r =>
InterpretersFor [Output i, Input o] r
runProcessIO :: forall i o (r :: EffectRow).
Member (Process i o) r =>
InterpretersFor '[Output i, Input o] r
runProcessIO =
(forall (rInitial :: EffectRow) x.
Input o (Sem rInitial) x -> Sem r x)
-> Sem (Input o : r) a -> Sem r a
forall (e :: Effect) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) x. e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret \case
Input o (Sem rInitial) x
Input ->
forall i o (r :: EffectRow). Member (Process i o) r => Sem r o
recv @i @o
(Sem (Input o : r) a -> Sem r a)
-> (Sem (Output i : Input o : r) a -> Sem (Input o : r) a)
-> Sem (Output i : Input o : r) a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(forall (rInitial :: EffectRow) x.
Output i (Sem rInitial) x -> Sem (Input o : r) x)
-> Sem (Output i : Input o : r) a -> Sem (Input o : r) a
forall (e :: Effect) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) x. e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret \case
Output i
o ->
forall i o (r :: EffectRow).
Member (Process i o) r =>
i -> Sem r ()
send @i @o i
o
runProcessOneshotIO ::
∀ i o err r .
Member (Process i o !! err) r =>
InterpretersFor [Output i !! err, Input o !! err] r
runProcessOneshotIO :: forall i o err (r :: EffectRow).
Member (Process i o !! err) r =>
InterpretersFor '[Output i !! err, Input o !! err] r
runProcessOneshotIO =
(forall x (r0 :: EffectRow).
Input o (Sem r0) x -> Sem (Stop err : r) x)
-> InterpreterFor (Input o !! err) r
forall err (eff :: Effect) (r :: EffectRow).
FirstOrder eff "interpretResumable" =>
(forall x (r0 :: EffectRow).
eff (Sem r0) x -> Sem (Stop err : r) x)
-> InterpreterFor (Resumable err eff) r
interpretResumable \case
Input o (Sem r0) x
Input ->
forall err (eff :: Effect) (r :: EffectRow).
Members '[Resumable err eff, Stop err] r =>
InterpreterFor eff r
restop @err @(Process i o) (forall i o (r :: EffectRow). Member (Process i o) r => Sem r o
recv @i @o)
(Sem ((Input o !! err) : r) a -> Sem r a)
-> (Sem (Resumable err (Output i) : (Input o !! err) : r) a
-> Sem ((Input o !! err) : r) a)
-> Sem (Resumable err (Output i) : (Input o !! err) : r) a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(forall x (r0 :: EffectRow).
Output i (Sem r0) x -> Sem (Stop err : (Input o !! err) : r) x)
-> InterpreterFor (Resumable err (Output i)) ((Input o !! err) : r)
forall err (eff :: Effect) (r :: EffectRow).
FirstOrder eff "interpretResumable" =>
(forall x (r0 :: EffectRow).
eff (Sem r0) x -> Sem (Stop err : r) x)
-> InterpreterFor (Resumable err eff) r
interpretResumable \case
Output i
o ->
forall err (eff :: Effect) (r :: EffectRow).
Members '[Resumable err eff, Stop err] r =>
InterpreterFor eff r
restop @err @(Process i o) (forall i o (r :: EffectRow).
Member (Process i o) r =>
i -> Sem r ()
send @i @o i
o)