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