{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE RankNTypes         #-}
{-# LANGUAGE TypeApplications   #-}
{-# LANGUAGE TypeOperators      #-}
{-

Interface to beam ecosystem used by the PAB to store contracts.

-}
module Plutus.PAB.Db.Beam (runBeamStoreAction) where

import Cardano.BM.Trace (Trace)
import Control.Monad.Freer (Eff, interpret, reinterpret, runM, subsume, type (~>))
import Control.Monad.Freer.Delay (DelayEffect, handleDelayEffect)
import Control.Monad.Freer.Error (Error, handleError, runError, throwError)
import Control.Monad.Freer.Extras (LogMsg, mapLog)
import Control.Monad.Freer.Extras.Beam (BeamError)
import Control.Monad.Freer.Extras.Beam.Effects (BeamEffect, handleBeam)
import Control.Monad.Freer.Extras.Beam.Postgres qualified as Postgres (runBeam)
import Control.Monad.Freer.Extras.Beam.Sqlite qualified as Sqlite (runBeam)
import Control.Monad.Freer.Extras.Modify qualified as Modify
import Control.Monad.Freer.Reader (Reader, runReader)
import Data.Aeson (FromJSON, ToJSON)
import Data.Pool (Pool)
import Data.Typeable (Typeable)
import Database.Beam.Postgres (Postgres)
import Database.Beam.Sqlite (Sqlite)
import Plutus.PAB.Db.Beam.ContractStore (handleContractStore)
import Plutus.PAB.Effects.Contract (ContractStore)
import Plutus.PAB.Effects.Contract.Builtin (Builtin, HasDefinitions)
import Plutus.PAB.Monitoring.Monitoring (convertLog, handleLogMsgTrace)
import Plutus.PAB.Monitoring.PABLogMsg (PABLogMsg (..), PABMultiAgentMsg (..))
import Plutus.PAB.Types (DBConnection (..), PABError (..))

-- | Run the ContractStore and ContractDefinitionStore effects on the
--   configured database.
runBeamStoreAction ::
    forall a b.
    ( ToJSON a
    , FromJSON a
    , HasDefinitions a
    , Typeable a
    )
    => DBConnection --Pool Postgres.Connection
    -> Trace IO (PABLogMsg (Builtin a))
    -> Eff '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO] b
    -> IO (Either PABError b)
runBeamStoreAction :: DBConnection
-> Trace IO (PABLogMsg (Builtin a))
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
runBeamStoreAction (PostgresPool Pool Connection
pool) Trace IO (PABLogMsg (Builtin a))
trace =
    Pool Connection
-> Trace IO (PABLogMsg (Builtin a))
-> (BeamEffect Postgres
    ~> Eff
         '[Reader (Pool Connection), Error BeamError, Error PABError, IO])
-> (ContractStore (Builtin a)
    ~> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect Postgres, Reader (Pool Connection), Error BeamError,
           Error PABError, IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
forall p dbt a b.
Pool p
-> Trace IO (PABLogMsg (Builtin a))
-> (BeamEffect dbt
    ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO])
-> (ContractStore (Builtin a)
    ~> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
           IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
run Pool Connection
pool Trace IO (PABLogMsg (Builtin a))
trace
        ((Trace IO BeamLog
 -> Pg
    ~> Eff
         '[Reader (Pool Connection), Error BeamError, Error PABError, IO])
-> Trace IO BeamLog
-> BeamEffect Postgres
   ~> Eff
        '[Reader (Pool Connection), Error BeamError, Error PABError, IO]
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> Pg
   ~> Eff
        '[Reader (Pool Connection), Error BeamError, Error PABError, IO]
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> Pg ~> Eff effs
Postgres.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
        (forall a (effs :: [* -> *]).
(FromBackendRow Postgres Text, FromBackendRow Postgres Bool,
 FromBackendRow Postgres SqlNull,
 HasSqlValueSyntax (Synt Postgres) (Maybe Text),
 HasSqlValueSyntax (Synt Postgres) Text,
 HasSqlValueSyntax (Synt Postgres) Bool,
 HasSqlEqualityCheck Postgres Text,
 HasSqlEqualityCheck Postgres Bool, HasQBuilder Postgres,
 Member (BeamEffect Postgres) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
forall dbt a (effs :: [* -> *]).
(FromBackendRow dbt Text, FromBackendRow dbt Bool,
 FromBackendRow dbt SqlNull,
 HasSqlValueSyntax (Synt dbt) (Maybe Text),
 HasSqlValueSyntax (Synt dbt) Text,
 HasSqlValueSyntax (Synt dbt) Bool, HasSqlEqualityCheck dbt Text,
 HasSqlEqualityCheck dbt Bool, HasQBuilder dbt,
 Member (BeamEffect dbt) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
handleContractStore @Postgres)
runBeamStoreAction (SqlitePool Pool Connection
pool) Trace IO (PABLogMsg (Builtin a))
trace =
    Pool Connection
-> Trace IO (PABLogMsg (Builtin a))
-> (BeamEffect Sqlite
    ~> Eff
         '[Reader (Pool Connection), Error BeamError, Error PABError, IO])
-> (ContractStore (Builtin a)
    ~> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect Sqlite, Reader (Pool Connection), Error BeamError,
           Error PABError, IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
forall p dbt a b.
Pool p
-> Trace IO (PABLogMsg (Builtin a))
-> (BeamEffect dbt
    ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO])
-> (ContractStore (Builtin a)
    ~> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
           IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
run Pool Connection
pool Trace IO (PABLogMsg (Builtin a))
trace
        ((Trace IO BeamLog
 -> SqliteM
    ~> Eff
         '[Reader (Pool Connection), Error BeamError, Error PABError, IO])
-> Trace IO BeamLog
-> BeamEffect Sqlite
   ~> Eff
        '[Reader (Pool Connection), Error BeamError, Error PABError, IO]
forall dbt (dbM :: * -> *) (effs :: [* -> *]).
(BeamSqlBackend dbt, MonadBeam dbt dbM,
 BeamHasInsertOnConflict dbt) =>
(Trace IO BeamLog -> dbM ~> Eff effs)
-> Trace IO BeamLog -> BeamEffect dbt ~> Eff effs
handleBeam Trace IO BeamLog
-> SqliteM
   ~> Eff
        '[Reader (Pool Connection), Error BeamError, Error PABError, IO]
forall (effs :: [* -> *]).
(LastMember IO effs, Member (Reader (Pool Connection)) effs) =>
Trace IO BeamLog -> SqliteM ~> Eff effs
Sqlite.runBeam ((BeamLog -> PABLogMsg (Builtin a))
-> Trace IO (PABLogMsg (Builtin a)) -> Trace IO BeamLog
forall a b (m :: * -> *). (a -> b) -> Trace m b -> Trace m a
convertLog (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent (PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> (BeamLog -> PABMultiAgentMsg (Builtin a))
-> BeamLog
-> PABLogMsg (Builtin a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamLog -> PABMultiAgentMsg (Builtin a)
forall t. BeamLog -> PABMultiAgentMsg t
BeamLogItem) Trace IO (PABLogMsg (Builtin a))
trace))
        (forall a (effs :: [* -> *]).
(FromBackendRow Sqlite Text, FromBackendRow Sqlite Bool,
 FromBackendRow Sqlite SqlNull,
 HasSqlValueSyntax (Synt Sqlite) (Maybe Text),
 HasSqlValueSyntax (Synt Sqlite) Text,
 HasSqlValueSyntax (Synt Sqlite) Bool,
 HasSqlEqualityCheck Sqlite Text, HasSqlEqualityCheck Sqlite Bool,
 HasQBuilder Sqlite, Member (BeamEffect Sqlite) effs,
 Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
forall dbt a (effs :: [* -> *]).
(FromBackendRow dbt Text, FromBackendRow dbt Bool,
 FromBackendRow dbt SqlNull,
 HasSqlValueSyntax (Synt dbt) (Maybe Text),
 HasSqlValueSyntax (Synt dbt) Text,
 HasSqlValueSyntax (Synt dbt) Bool, HasSqlEqualityCheck dbt Text,
 HasSqlEqualityCheck dbt Bool, HasQBuilder dbt,
 Member (BeamEffect dbt) effs, Member (Error PABError) effs,
 Member (LogMsg (PABMultiAgentMsg (Builtin a))) effs, ToJSON a,
 FromJSON a, HasDefinitions a, Typeable a) =>
ContractStore (Builtin a) ~> Eff effs
handleContractStore @Sqlite)

run :: forall p dbt a b
    .  Pool p
    -> Trace IO (PABLogMsg (Builtin a))
    -> BeamEffect dbt ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO]
    -> ContractStore (Builtin a) ~> Eff '[ LogMsg (PABMultiAgentMsg (Builtin a))
                                          , DelayEffect
                                          , IO
                                          , BeamEffect dbt
                                          , Reader (Pool p)
                                          , Error BeamError
                                          , Error PABError
                                          , IO
                                          ]
    -> Eff '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO] b
    -> IO (Either PABError b)
run :: Pool p
-> Trace IO (PABLogMsg (Builtin a))
-> (BeamEffect dbt
    ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO])
-> (ContractStore (Builtin a)
    ~> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
           IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
run Pool p
pool Trace IO (PABLogMsg (Builtin a))
trace BeamEffect dbt
~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO]
hBeam ContractStore (Builtin a)
~> Eff
     '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
       BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
hContractStore =
    Eff '[IO] (Either PABError b) -> IO (Either PABError b)
forall (m :: * -> *) a. Monad m => Eff '[m] a -> m a
runM
    (Eff '[IO] (Either PABError b) -> IO (Either PABError b))
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff '[IO] (Either PABError b))
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> IO (Either PABError b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff '[Error PABError, IO] b -> Eff '[IO] (Either PABError b)
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> Eff effs (Either e a)
runError
    (Eff '[Error PABError, IO] b -> Eff '[IO] (Either PABError b))
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff '[Error PABError, IO] b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff '[IO] (Either PABError b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Eff '[Error BeamError, Error PABError, IO] b
 -> (BeamError -> Eff '[Error PABError, IO] b)
 -> Eff '[Error PABError, IO] b)
-> (BeamError -> Eff '[Error PABError, IO] b)
-> Eff '[Error BeamError, Error PABError, IO] b
-> Eff '[Error PABError, IO] b
forall a b c. (a -> b -> c) -> b -> a -> c
flip Eff '[Error BeamError, Error PABError, IO] b
-> (BeamError -> Eff '[Error PABError, IO] b)
-> Eff '[Error PABError, IO] b
forall e (effs :: [* -> *]) a.
Eff (Error e : effs) a -> (e -> Eff effs a) -> Eff effs a
handleError (PABError -> Eff '[Error PABError, IO] b
forall e (effs :: [* -> *]) a.
Member (Error e) effs =>
e -> Eff effs a
throwError (PABError -> Eff '[Error PABError, IO] b)
-> (BeamError -> PABError)
-> BeamError
-> Eff '[Error PABError, IO] b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BeamError -> PABError
BeamEffectError)
    (Eff '[Error BeamError, Error PABError, IO] b
 -> Eff '[Error PABError, IO] b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff '[Error BeamError, Error PABError, IO] b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff '[Error PABError, IO] b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pool p
-> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO] b
-> Eff '[Error BeamError, Error PABError, IO] b
forall r (effs :: [* -> *]) a.
r -> Eff (Reader r : effs) a -> Eff effs a
runReader Pool p
pool
    (Eff '[Reader (Pool p), Error BeamError, Error PABError, IO] b
 -> Eff '[Error BeamError, Error PABError, IO] b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO] b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff '[Error BeamError, Error PABError, IO] b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BeamEffect dbt
 ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO])
-> Eff
     '[BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
   ~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO]
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret BeamEffect dbt
~> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO]
hBeam
    (Eff
   '[BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
     IO]
   b
 -> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO] b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
           IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff '[Reader (Pool p), Error BeamError, Error PABError, IO] b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (effs :: [* -> *]).
Member IO effs =>
Eff (IO : effs) ~> Eff effs
forall (eff :: * -> *) (effs :: [* -> *]).
Member eff effs =>
Eff (eff : effs) ~> Eff effs
subsume @IO
    (Eff
   '[IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
     Error PABError, IO]
   b
 -> Eff
      '[BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
        IO]
      b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
           Error PABError, IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff
     '[BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
     b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff
  '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
    Error BeamError, Error PABError, IO]
  b
-> Eff
     '[IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
       Error PABError, IO]
     b
forall (effs :: [* -> *]) (m :: * -> *).
(LastMember m effs, MonadIO m) =>
Eff (DelayEffect : effs) ~> Eff effs
handleDelayEffect
    (Eff
   '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
     Error BeamError, Error PABError, IO]
   b
 -> Eff
      '[IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
        Error PABError, IO]
      b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
           Error BeamError, Error PABError, IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff
     '[IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
       Error PABError, IO]
     b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg (PABLogMsg (Builtin a))
 ~> Eff
      '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
        Error BeamError, Error PABError, IO])
-> Eff
     '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
       Reader (Pool p), Error BeamError, Error PABError, IO]
   ~> Eff
        '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
          Error BeamError, Error PABError, IO]
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret (Trace IO (PABLogMsg (Builtin a))
-> LogMsg (PABLogMsg (Builtin a))
   ~> Eff
        '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
          Error BeamError, Error PABError, IO]
forall a (m :: * -> *) (effs :: [* -> *]).
(LastMember m effs, MonadIO m) =>
Trace m a -> LogMsg a ~> Eff effs
handleLogMsgTrace Trace IO (PABLogMsg (Builtin a))
trace)
    (Eff
   '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
     Reader (Pool p), Error BeamError, Error PABError, IO]
   b
 -> Eff
      '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
        Error BeamError, Error PABError, IO]
      b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
           Reader (Pool p), Error BeamError, Error PABError, IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff
     '[DelayEffect, IO, BeamEffect dbt, Reader (Pool p),
       Error BeamError, Error PABError, IO]
     b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogMsg (PABMultiAgentMsg (Builtin a))
 ~> Eff
      '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
        Reader (Pool p), Error BeamError, Error PABError, IO])
-> Eff
     '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
       BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
   ~> Eff
        '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
          Reader (Pool p), Error BeamError, Error PABError, IO]
forall (f :: * -> *) (g :: * -> *) (effs :: [* -> *]).
(f ~> Eff (g : effs)) -> Eff (f : effs) ~> Eff (g : effs)
reinterpret ((PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a))
-> LogMsg (PABMultiAgentMsg (Builtin a))
   ~> Eff
        '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
          Reader (Pool p), Error BeamError, Error PABError, IO]
forall a b (effs :: [* -> *]).
Member (LogMsg b) effs =>
(a -> b) -> LogMsg a ~> Eff effs
mapLog PABMultiAgentMsg (Builtin a) -> PABLogMsg (Builtin a)
forall t. PABMultiAgentMsg t -> PABLogMsg t
SMultiAgent)
    (Eff
   '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
     BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
     IO]
   b
 -> Eff
      '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
        Reader (Pool p), Error BeamError, Error PABError, IO]
      b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
           BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
           IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff
     '[LogMsg (PABLogMsg (Builtin a)), DelayEffect, IO, BeamEffect dbt,
       Reader (Pool p), Error BeamError, Error PABError, IO]
     b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ContractStore (Builtin a)
 ~> Eff
      '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
        BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
        IO])
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
       Error PABError, IO]
   ~> Eff
        '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
          BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
          IO]
forall (eff :: * -> *) (effs :: [* -> *]).
(eff ~> Eff effs) -> Eff (eff : effs) ~> Eff effs
interpret ContractStore (Builtin a)
~> Eff
     '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
       BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
hContractStore
    (Eff
   '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
     DelayEffect, IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
     Error PABError, IO]
   b
 -> Eff
      '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
        BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
        IO]
      b)
-> (Eff
      '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
        DelayEffect, IO]
      b
    -> Eff
         '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
           DelayEffect, IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
           Error PABError, IO]
         b)
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO]
     b
-> Eff
     '[LogMsg (PABMultiAgentMsg (Builtin a)), DelayEffect, IO,
       BeamEffect dbt, Reader (Pool p), Error BeamError, Error PABError,
       IO]
     b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Eff
  '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
    DelayEffect, IO]
  b
-> Eff
     '[ContractStore (Builtin a), LogMsg (PABMultiAgentMsg (Builtin a)),
       DelayEffect, IO, BeamEffect dbt, Reader (Pool p), Error BeamError,
       Error PABError, IO]
     b
forall (effs :: [* -> *]) (as :: [* -> *]).
CanWeakenEnd as effs =>
Eff as ~> Eff effs
Modify.raiseEnd