module Simulation.Aivika.Trans.GPSS.Block.Loop
(loopBlock,
loopBlockM) where
import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.GPSS.Block
loopBlock :: MonadDES m
=> (a -> (b, Bool))
-> Block m b ()
-> Block m a b
{-# INLINABLE loopBlock #-}
loopBlock :: (a -> (b, Bool)) -> Block m b () -> Block m a b
loopBlock a -> (b, Bool)
f Block m b ()
block =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m b
blockProcess = \a
a ->
do let (b
b, Bool
c) = a -> (b, Bool)
f a
a
if Bool
c
then b -> Process m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
else Process m () -> Process m b
forall (m :: * -> *) a. MonadDES m => Process m () -> Process m a
transferProcess (Block m b () -> b -> Process m ()
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m b ()
block b
b)
}
loopBlockM :: MonadDES m
=> (a -> Process m (b, Bool))
-> Block m b ()
-> Block m a b
{-# INLINABLE loopBlockM #-}
loopBlockM :: (a -> Process m (b, Bool)) -> Block m b () -> Block m a b
loopBlockM a -> Process m (b, Bool)
f Block m b ()
block =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m b
blockProcess = \a
a ->
do (b
b, Bool
c) <- a -> Process m (b, Bool)
f a
a
if Bool
c
then b -> Process m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
else Process m () -> Process m b
forall (m :: * -> *) a. MonadDES m => Process m () -> Process m a
transferProcess (Block m b () -> b -> Process m ()
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m b ()
block b
b)
}