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