{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Polysemy.Methodology
(
Methodology (..),
process,
runMethodologyPure,
runMethodologySem,
cutMethodology,
cutMethodology',
cutMethodology3,
cutMethodology3',
divideMethodology,
divideMethodology',
decideMethodology,
decideMethodology',
decomposeMethodology,
decomposeMethodology',
decomposeMethodology3,
separateMethodologyInitial,
endMethodologyInitial,
separateMethodologyTerminal,
endMethodologyTerminal,
fmapMethodology,
fmapMethodology',
fmap2Methodology,
fmap2Methodology',
pureMethodology,
pureMethodology',
bindMethodology,
bindMethodology',
traverseMethodology,
traverseMethodology',
mconcatMethodology,
mconcatMethodology',
teeMethodologyOutput,
plugMethodologyInput,
runMethodologyAsKVStore,
runMethodologyAsKVStoreWithDefault,
runMethodologyMappendPure,
runMethodologyMappendSem,
traceMethodologyStart,
traceMethodologyEnd,
traceMethodologyAround,
)
where
import Control.Applicative (liftA2)
import Control.Arrow ((>>>))
import Control.Monad (join)
import Data.Foldable (fold)
import Data.Functor ((<&>))
import Data.Kind (Type)
import Polysemy (Members, Sem, intercept, interpret,
makeSem, raise, raiseUnder, reinterpret2,
reinterpret3)
import Polysemy.Input (Input, input)
import Polysemy.KVStore (KVStore, lookupKV)
import Polysemy.Output (Output, output)
import Polysemy.Several (HList (HNil, (:::)))
import Polysemy.Trace (Trace, trace)
type Methodology :: Type -> Type -> (Type -> Type) -> Type -> Type
data Methodology b c m a where
Process :: b -> Methodology b c m c
makeSem ''Methodology
runMethodologyPure ::
forall b c r a.
(b -> c) ->
Sem (Methodology b c ': r) a ->
Sem r a
runMethodologyPure :: forall b c (r :: EffectRow) a.
(b -> c) -> Sem (Methodology b c : r) a -> Sem r a
runMethodologyPure b -> c
f = 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
Process b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ b -> c
f b
b
{-# INLINE runMethodologyPure #-}
runMethodologySem ::
forall b c r a.
(b -> Sem r c) ->
Sem (Methodology b c ': r) a ->
Sem r a
runMethodologySem :: forall b c (r :: EffectRow) a.
(b -> Sem r c) -> Sem (Methodology b c : r) a -> Sem r a
runMethodologySem b -> Sem r c
f = 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
Process b
b -> b -> Sem r c
f b
b
{-# INLINE runMethodologySem #-}
cutMethodology ::
forall b c d r a.
Members
'[ Methodology b c,
Methodology c d
]
r =>
Sem (Methodology b d ': r) a ->
Sem r a
cutMethodology :: forall b c d (r :: EffectRow) a.
Members '[Methodology b c, Methodology c d] r =>
Sem (Methodology b d : r) a -> Sem r a
cutMethodology = 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
Process b
b -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d
{-# INLINE cutMethodology #-}
cutMethodology' ::
forall b c d r a.
Sem (Methodology b d ': r) a ->
Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology' :: forall b c d (r :: EffectRow) a.
Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : r) a
cutMethodology' = forall (e1 :: Effect) (e2 :: Effect) (e3 :: Effect)
(r :: EffectRow) a.
FirstOrder e1 "reinterpret2" =>
(forall (rInitial :: EffectRow) x.
e1 (Sem rInitial) x -> Sem (e2 : e3 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : e3 : r) a
reinterpret2 \case
Process b
b -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d
{-# INLINE cutMethodology' #-}
cutMethodology3 ::
forall b c d e r a.
Members
'[ Methodology b c,
Methodology c d,
Methodology d e
]
r =>
Sem (Methodology b e ': r) a ->
Sem r a
cutMethodology3 :: forall b c d e (r :: EffectRow) a.
Members '[Methodology b c, Methodology c d, Methodology d e] r =>
Sem (Methodology b e : r) a -> Sem r a
cutMethodology3 = 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
Process b
b -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @d @e
{-# INLINE cutMethodology3 #-}
cutMethodology3' ::
forall b c d e r a.
Sem (Methodology b d ': r) a ->
Sem (Methodology b c ': Methodology c d ': Methodology d e ': r) a
cutMethodology3' :: forall b c d e (r :: EffectRow) a.
Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : Methodology d e : r) a
cutMethodology3' = forall (e1 :: Effect) (e2 :: Effect) (e3 :: Effect) (e4 :: Effect)
(r :: EffectRow) a.
FirstOrder e1 "reinterpret3" =>
(forall (rInitial :: EffectRow) x.
e1 (Sem rInitial) x -> Sem (e2 : e3 : e4 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : e3 : e4 : r) a
reinterpret3 \case
Process b
b -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d
{-# INLINE cutMethodology3' #-}
divideMethodology ::
forall b c c' d r a.
Members
'[ Methodology b c,
Methodology b c',
Methodology (c, c') d
]
r =>
Sem (Methodology b d ': r) a ->
Sem r a
divideMethodology :: forall b c c' d (r :: EffectRow) a.
Members
'[Methodology b c, Methodology b c', Methodology (c, c') d] r =>
Sem (Methodology b d : r) a -> Sem r a
divideMethodology = 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
Process b
b -> do
c
c <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
c'
c' <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c' b
b
forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @(c, c') @d (c
c, c'
c')
{-# INLINE divideMethodology #-}
divideMethodology' ::
forall b c c' d r a.
Sem (Methodology b d ': r) a ->
Sem (Methodology b c ': Methodology b c' ': Methodology (c, c') d ': r) a
divideMethodology' :: forall b c c' d (r :: EffectRow) a.
Sem (Methodology b d : r) a
-> Sem
(Methodology b c : Methodology b c' : Methodology (c, c') d : r) a
divideMethodology' = forall (e1 :: Effect) (e2 :: Effect) (e3 :: Effect) (e4 :: Effect)
(r :: EffectRow) a.
FirstOrder e1 "reinterpret3" =>
(forall (rInitial :: EffectRow) x.
e1 (Sem rInitial) x -> Sem (e2 : e3 : e4 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : e3 : e4 : r) a
reinterpret3 \case
Process b
b -> do
c
c <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
c'
c' <- forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c' b
b
forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @(c, c') @d (c
c, c'
c')
{-# INLINE divideMethodology' #-}
decideMethodology ::
forall b c c' d r a.
Members
'[ Methodology b (Either c c'),
Methodology c d,
Methodology c' d
]
r =>
Sem (Methodology b d ': r) a ->
Sem r a
decideMethodology :: forall b c c' d (r :: EffectRow) a.
Members
'[Methodology b (Either c c'), Methodology c d, Methodology c' d]
r =>
Sem (Methodology b d : r) a -> Sem r a
decideMethodology = 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
Process b
b -> do
Either c c'
k <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @(Either c c') b
b
case Either c c'
k of
Left c
c -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d c
c
Right c'
c' -> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c' @d c'
c'
{-# INLINE decideMethodology #-}
decideMethodology' ::
forall b c c' d r a.
Sem (Methodology b d ': r) a ->
Sem (Methodology b (Either c c') ': Methodology c d ': Methodology c' d ': r) a
decideMethodology' :: forall b c c' d (r :: EffectRow) a.
Sem (Methodology b d : r) a
-> Sem
(Methodology b (Either c c')
: Methodology c d : Methodology c' d : r)
a
decideMethodology' = forall (e1 :: Effect) (e2 :: Effect) (e3 :: Effect) (e4 :: Effect)
(r :: EffectRow) a.
FirstOrder e1 "reinterpret3" =>
(forall (rInitial :: EffectRow) x.
e1 (Sem rInitial) x -> Sem (e2 : e3 : e4 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : e3 : e4 : r) a
reinterpret3 \case
Process b
b -> do
Either c c'
k <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @(Either c c') b
b
case Either c c'
k of
Left c
c -> forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c @d c
c
Right c'
c' -> forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall (e :: Effect) (r :: EffectRow) a. Sem r a -> Sem (e : r) a
raise forall a b. (a -> b) -> a -> b
$ forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @c' @d c'
c'
{-# INLINE decideMethodology' #-}
teeMethodologyOutput ::
forall b c r a.
Members
'[ Output c,
Methodology b c
]
r =>
Sem r a ->
Sem r a
teeMethodologyOutput :: forall b c (r :: EffectRow) a.
Members '[Output c, Methodology b c] r =>
Sem r a -> Sem r a
teeMethodologyOutput = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> do
c
k <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
forall o (r :: EffectRow). Member (Output o) r => o -> Sem r ()
output @c c
k
forall (m :: * -> *) a. Monad m => a -> m a
return c
k
{-# INLINE teeMethodologyOutput #-}
plugMethodologyInput ::
forall b c d r a.
Members '[Input b, Methodology (b, c) d] r =>
Sem (Methodology c d ': r) a ->
Sem r a
plugMethodologyInput :: forall b c d (r :: EffectRow) a.
Members '[Input b, Methodology (b, c) d] r =>
Sem (Methodology c d : r) a -> Sem r a
plugMethodologyInput = 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
Process c
b -> do
b
k <- forall i (r :: EffectRow). Member (Input i) r => Sem r i
input @b
forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @(b, c) @d (b
k, c
b)
{-# INLINE plugMethodologyInput #-}
runMethodologyAsKVStore ::
forall k v r a.
Members '[KVStore k v] r =>
Sem (Methodology k (Maybe v) ': r) a ->
Sem r a
runMethodologyAsKVStore :: forall k v (r :: EffectRow) a.
Members '[KVStore k v] r =>
Sem (Methodology k (Maybe v) : r) a -> Sem r a
runMethodologyAsKVStore = 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
Process k
k -> forall k v (r :: EffectRow).
Member (KVStore k v) r =>
k -> Sem r (Maybe v)
lookupKV k
k
{-# INLINE runMethodologyAsKVStore #-}
runMethodologyAsKVStoreWithDefault ::
forall k v r a.
Members '[KVStore k v] r =>
v ->
Sem (Methodology k v ': r) a ->
Sem r a
runMethodologyAsKVStoreWithDefault :: forall k v (r :: EffectRow) a.
Members '[KVStore k v] r =>
v -> Sem (Methodology k v : r) a -> Sem r a
runMethodologyAsKVStoreWithDefault v
d = 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
Process k
k -> do
Maybe x
z <- forall k v (r :: EffectRow).
Member (KVStore k v) r =>
k -> Sem r (Maybe v)
lookupKV k
k
case Maybe x
z of
Just x
a -> forall (m :: * -> *) a. Monad m => a -> m a
return x
a
Maybe x
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return v
d
{-# INLINE runMethodologyAsKVStoreWithDefault #-}
runMethodologyMappendPure ::
forall b c r a.
( Monoid c,
Members '[Methodology b c] r
) =>
(b -> c) ->
Sem r a ->
Sem r a
runMethodologyMappendPure :: forall b c (r :: EffectRow) a.
(Monoid c, Members '[Methodology b c] r) =>
(b -> c) -> Sem r a -> Sem r a
runMethodologyMappendPure b -> c
f = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> (b -> c
f b
b forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
{-# INLINE runMethodologyMappendPure #-}
runMethodologyMappendSem ::
forall b c r a.
( Monoid c,
Members '[Methodology b c] r
) =>
(b -> Sem r c) ->
Sem r a ->
Sem r a
runMethodologyMappendSem :: forall b c (r :: EffectRow) a.
(Monoid c, Members '[Methodology b c] r) =>
(b -> Sem r c) -> Sem r a -> Sem r a
runMethodologyMappendSem b -> Sem r c
f = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>) (b -> Sem r c
f b
b) (forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b)
{-# INLINE runMethodologyMappendSem #-}
decomposeMethodology ::
forall b f c r a.
Members
'[ Methodology b (HList f),
Methodology (HList f) c
]
r =>
Sem (Methodology b c ': r) a ->
Sem r a
decomposeMethodology :: forall b (f :: [*]) c (r :: EffectRow) a.
Members '[Methodology b (HList f), Methodology (HList f) c] r =>
Sem (Methodology b c : r) a -> Sem r a
decomposeMethodology = forall b c d (r :: EffectRow) a.
Members '[Methodology b c, Methodology c d] r =>
Sem (Methodology b d : r) a -> Sem r a
cutMethodology @b @(HList f) @c
{-# INLINE decomposeMethodology #-}
decomposeMethodology' ::
forall b f c r a.
Sem (Methodology b c ': r) a ->
Sem (Methodology b (HList f) ': Methodology (HList f) c ': r) a
decomposeMethodology' :: forall b (f :: [*]) c (r :: EffectRow) a.
Sem (Methodology b c : r) a
-> Sem (Methodology b (HList f) : Methodology (HList f) c : r) a
decomposeMethodology' = forall b c d (r :: EffectRow) a.
Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : r) a
cutMethodology' @b @(HList f) @c
{-# INLINE decomposeMethodology' #-}
decomposeMethodology3 ::
forall b f g c r a.
Members
'[ Methodology b (HList f),
Methodology (HList f) (HList g),
Methodology (HList g) c
]
r =>
Sem (Methodology b c ': r) a ->
Sem r a
decomposeMethodology3 :: forall b (f :: [*]) (g :: [*]) c (r :: EffectRow) a.
Members
'[Methodology b (HList f), Methodology (HList f) (HList g),
Methodology (HList g) c]
r =>
Sem (Methodology b c : r) a -> Sem r a
decomposeMethodology3 = forall b c d e (r :: EffectRow) a.
Members '[Methodology b c, Methodology c d, Methodology d e] r =>
Sem (Methodology b e : r) a -> Sem r a
cutMethodology3 @b @(HList f) @(HList g) @c
{-# INLINE decomposeMethodology3 #-}
separateMethodologyInitial ::
forall b x xs r a.
Members
'[ Methodology b (HList xs),
Methodology b x
]
r =>
Sem (Methodology b (HList (x ': xs)) ': r) a ->
Sem r a
separateMethodologyInitial :: forall b x (xs :: [*]) (r :: EffectRow) a.
Members '[Methodology b (HList xs), Methodology b x] r =>
Sem (Methodology b (HList (x : xs)) : r) a -> Sem r a
separateMethodologyInitial = 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
Process b
b -> do
x
k <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @x b
b
HList xs
k' <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @(HList xs) b
b
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ x
k forall a1 (b :: [*]). a1 -> HList b -> HList (a1 : b)
::: HList xs
k'
{-# INLINE separateMethodologyInitial #-}
endMethodologyInitial ::
Sem (Methodology b (HList '[]) ': r) a ->
Sem r a
endMethodologyInitial :: forall b (r :: EffectRow) a.
Sem (Methodology b (HList '[]) : r) a -> Sem r a
endMethodologyInitial = 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
Process b
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return HList '[]
HNil
{-# INLINE endMethodologyInitial #-}
separateMethodologyTerminal ::
forall x c xs r a.
( Monoid c,
Members
'[ Methodology (HList xs) c,
Methodology x c
]
r
) =>
Sem (Methodology (HList (x ': xs)) c ': r) a ->
Sem r a
separateMethodologyTerminal :: forall x c (xs :: [*]) (r :: EffectRow) a.
(Monoid c,
Members '[Methodology (HList xs) c, Methodology x c] r) =>
Sem (Methodology (HList (x : xs)) c : r) a -> Sem r a
separateMethodologyTerminal = 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
Process (a1
b ::: HList b
bs) -> do
c
k <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @x @c a1
b
c
k' <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @(HList xs) @c HList b
bs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ c
k forall a. Semigroup a => a -> a -> a
<> c
k'
{-# INLINE separateMethodologyTerminal #-}
endMethodologyTerminal ::
Monoid c =>
Sem (Methodology (HList '[]) c ': r) a ->
Sem r a
endMethodologyTerminal :: forall c (r :: EffectRow) a.
Monoid c =>
Sem (Methodology (HList '[]) c : r) a -> Sem r a
endMethodologyTerminal = 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
Process HList '[]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
{-# INLINE endMethodologyTerminal #-}
fmapMethodology ::
forall f b c r a.
( Members '[Methodology b c] r,
Traversable f
) =>
Sem (Methodology (f b) (f c) ': r) a ->
Sem r a
fmapMethodology :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Traversable f) =>
Sem (Methodology (f b) (f c) : r) a -> Sem r a
fmapMethodology = 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
Process f b
b -> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c) f b
b
{-# INLINE fmapMethodology #-}
fmapMethodology' ::
forall f b c r a.
Traversable f =>
Sem (Methodology (f b) (f c) ': r) a ->
Sem (Methodology b c ': r) a
fmapMethodology' :: forall (f :: * -> *) b c (r :: EffectRow) a.
Traversable f =>
Sem (Methodology (f b) (f c) : r) a -> Sem (Methodology b c : r) a
fmapMethodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Traversable f) =>
Sem (Methodology (f b) (f c) : r) a -> Sem r a
fmapMethodology
{-# INLINE fmapMethodology' #-}
fmap2Methodology ::
forall f g b c r a.
( Members '[Methodology b c] r,
Traversable f,
Traversable g
) =>
Sem (Methodology (f (g b)) (f (g c)) ': r) a ->
Sem r a
fmap2Methodology :: forall (f :: * -> *) (g :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Traversable f, Traversable g) =>
Sem (Methodology (f (g b)) (f (g c)) : r) a -> Sem r a
fmap2Methodology = forall (f :: * -> *) b c (r :: EffectRow) a.
Traversable f =>
Sem (Methodology (f b) (f c) : r) a -> Sem (Methodology b c : r) a
fmapMethodology' @f @(g b) @(g c) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Traversable f) =>
Sem (Methodology (f b) (f c) : r) a -> Sem r a
fmapMethodology @g @b @c
{-# INLINE fmap2Methodology #-}
fmap2Methodology' ::
forall f g b c r a.
(Traversable f, Traversable g) =>
Sem (Methodology (f (g b)) (f (g c)) ': r) a ->
Sem (Methodology b c ': r) a
fmap2Methodology' :: forall (f :: * -> *) (g :: * -> *) b c (r :: EffectRow) a.
(Traversable f, Traversable g) =>
Sem (Methodology (f (g b)) (f (g c)) : r) a
-> Sem (Methodology b c : r) a
fmap2Methodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) (g :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Traversable f, Traversable g) =>
Sem (Methodology (f (g b)) (f (g c)) : r) a -> Sem r a
fmap2Methodology
{-# INLINE fmap2Methodology' #-}
pureMethodology ::
forall f b c r a.
(Members '[Methodology b c] r, Applicative f) =>
Sem (Methodology b (f c) ': r) a ->
Sem r a
pureMethodology :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Applicative f) =>
Sem (Methodology b (f c) : r) a -> Sem r a
pureMethodology = 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
Process b
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
{-# INLINE pureMethodology #-}
pureMethodology' ::
forall f b c r a.
Applicative f =>
Sem (Methodology b (f c) ': r) a ->
Sem (Methodology b c ': r) a
pureMethodology' :: forall (f :: * -> *) b c (r :: EffectRow) a.
Applicative f =>
Sem (Methodology b (f c) : r) a -> Sem (Methodology b c : r) a
pureMethodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Applicative f) =>
Sem (Methodology b (f c) : r) a -> Sem r a
pureMethodology
{-# INLINE pureMethodology' #-}
bindMethodology ::
forall f b c r a.
( Members '[Methodology b (f c)] r,
Traversable f,
Monad f
) =>
Sem (Methodology (f b) (f c) ': r) a ->
Sem r a
bindMethodology :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b (f c)] r, Traversable f, Monad f) =>
Sem (Methodology (f b) (f c) : r) a -> Sem r a
bindMethodology = 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
Process f b
b -> forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @(f c)) f b
b
{-# INLINE bindMethodology #-}
bindMethodology' ::
forall f b c r a.
(Traversable f, Monad f) =>
Sem (Methodology (f b) (f c) ': r) a ->
Sem (Methodology b (f c) ': r) a
bindMethodology' :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Traversable f, Monad f) =>
Sem (Methodology (f b) (f c) : r) a
-> Sem (Methodology b (f c) : r) a
bindMethodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b (f c)] r, Traversable f, Monad f) =>
Sem (Methodology (f b) (f c) : r) a -> Sem r a
bindMethodology
{-# INLINE bindMethodology' #-}
traverseMethodology ::
forall t f b c r a.
( Members '[Methodology b (f c)] r,
Traversable t,
Applicative f
) =>
Sem (Methodology (t b) (f (t c)) ': r) a ->
Sem r a
traverseMethodology :: forall (t :: * -> *) (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b (f c)] r, Traversable t, Applicative f) =>
Sem (Methodology (t b) (f (t c)) : r) a -> Sem r a
traverseMethodology = 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
Process t b
b -> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @(f c)) t b
b
{-# INLINE traverseMethodology #-}
traverseMethodology' ::
forall t f b c r a.
(Traversable t, Applicative f) =>
Sem (Methodology (t b) (f (t c)) ': r) a ->
Sem (Methodology b (f c) ': r) a
traverseMethodology' :: forall (t :: * -> *) (f :: * -> *) b c (r :: EffectRow) a.
(Traversable t, Applicative f) =>
Sem (Methodology (t b) (f (t c)) : r) a
-> Sem (Methodology b (f c) : r) a
traverseMethodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (t :: * -> *) (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b (f c)] r, Traversable t, Applicative f) =>
Sem (Methodology (t b) (f (t c)) : r) a -> Sem r a
traverseMethodology
{-# INLINE traverseMethodology' #-}
mconcatMethodology ::
forall f b c r a.
( Members '[Methodology b c] r,
Monoid c,
Traversable f
) =>
Sem (Methodology (f b) c ': r) a ->
Sem r a
mconcatMethodology :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Monoid c, Traversable f) =>
Sem (Methodology (f b) c : r) a -> Sem r a
mconcatMethodology = 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
Process f b
b -> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c) f b
b forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
{-# INLINE mconcatMethodology #-}
mconcatMethodology' ::
forall f b c r a.
(Monoid c, Traversable f) =>
Sem (Methodology (f b) c ': r) a ->
Sem (Methodology b c ': r) a
mconcatMethodology' :: forall (f :: * -> *) b c (r :: EffectRow) a.
(Monoid c, Traversable f) =>
Sem (Methodology (f b) c : r) a -> Sem (Methodology b c : r) a
mconcatMethodology' = forall (e2 :: Effect) (e1 :: Effect) (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) b c (r :: EffectRow) a.
(Members '[Methodology b c] r, Monoid c, Traversable f) =>
Sem (Methodology (f b) c : r) a -> Sem r a
mconcatMethodology
{-# INLINE mconcatMethodology' #-}
traceMethodologyStart ::
forall b c r a.
Members
'[ Methodology b c,
Trace
]
r =>
(b -> String) ->
Sem r a ->
Sem r a
traceMethodologyStart :: forall b c (r :: EffectRow) a.
Members '[Methodology b c, Trace] r =>
(b -> String) -> Sem r a -> Sem r a
traceMethodologyStart b -> String
f = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> forall (r :: EffectRow). Member Trace r => String -> Sem r ()
trace (b -> String
f b
b) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
{-# INLINE traceMethodologyStart #-}
traceMethodologyEnd ::
forall b c r a.
Members
'[ Methodology b c,
Trace
]
r =>
(c -> String) ->
Sem r a ->
Sem r a
traceMethodologyEnd :: forall b c (r :: EffectRow) a.
Members '[Methodology b c, Trace] r =>
(c -> String) -> Sem r a -> Sem r a
traceMethodologyEnd c -> String
f = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> do
c
c <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
forall (r :: EffectRow). Member Trace r => String -> Sem r ()
trace forall a b. (a -> b) -> a -> b
$ c -> String
f c
c
forall (m :: * -> *) a. Monad m => a -> m a
return c
c
{-# INLINE traceMethodologyEnd #-}
traceMethodologyAround ::
forall b c r a.
Members
'[ Methodology b c,
Trace
]
r =>
(b -> String) ->
(c -> String) ->
Sem r a ->
Sem r a
traceMethodologyAround :: forall b c (r :: EffectRow) a.
Members '[Methodology b c, Trace] r =>
(b -> String) -> (c -> String) -> Sem r a -> Sem r a
traceMethodologyAround b -> String
f c -> String
g = forall (e :: Effect) (r :: EffectRow) a.
(Member e r, FirstOrder e "intercept") =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem r a -> Sem r a
intercept @(Methodology b c) \case
Process b
b -> do
forall (r :: EffectRow). Member Trace r => String -> Sem r ()
trace forall a b. (a -> b) -> a -> b
$ b -> String
f b
b
c
c <- forall b c (r :: EffectRow).
Member (Methodology b c) r =>
b -> Sem r c
process @b @c b
b
forall (r :: EffectRow). Member Trace r => String -> Sem r ()
trace forall a b. (a -> b) -> a -> b
$ c -> String
g c
c
forall (m :: * -> *) a. Monad m => a -> m a
return c
c
{-# INLINE traceMethodologyAround #-}