module Simulation.Aivika.Trans.GPSS.Block.Split
(splitBlock) where
import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.GPSS.Block
import Simulation.Aivika.Trans.GPSS.Transact
splitBlock :: MonadDES m
=> [Block m (Transact m a) ()]
-> Block m (Transact m a) (Transact m a)
{-# INLINABLE splitBlock #-}
splitBlock :: [Block m (Transact m a) ()]
-> Block m (Transact m a) (Transact m a)
splitBlock [Block m (Transact m a) ()]
blocks =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: Transact m a -> Process m (Transact m a)
blockProcess = \Transact m a
a ->
do let loop :: [Block m (Transact m a) ()] -> Event m ()
loop [] = () -> Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
loop (Block m (Transact m a) ()
transfer: [Block m (Transact m a) ()]
transfers) =
do Transact m a
a' <- Simulation m (Transact m a) -> Event m (Transact m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Transact m a) -> Event m (Transact m a))
-> Simulation m (Transact m a) -> Event m (Transact m a)
forall a b. (a -> b) -> a -> b
$ Transact m a -> Simulation m (Transact m a)
forall (m :: * -> *) a.
MonadDES m =>
Transact m a -> Simulation m (Transact m a)
splitTransact Transact m a
a
Transact m a -> Process m () -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Transact m a -> Process m () -> Event m ()
transferTransact Transact m a
a' (Process m () -> Event m ()) -> Process m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
Block m (Transact m a) () -> Transact m a -> Process m ()
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m (Transact m a) ()
transfer Transact m a
a'
[Block m (Transact m a) ()] -> Event m ()
loop [Block m (Transact m a) ()]
transfers
Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ [Block m (Transact m a) ()] -> Event m ()
loop [Block m (Transact m a) ()]
blocks
Transact m a -> Process m (Transact m a)
forall (m :: * -> *) a. Monad m => a -> m a
return Transact m a
a
}