module Simulation.Aivika.Trans.GPSS.Block.Test
(awaitingTestBlock,
awaitingTestBlockM,
transferringTestBlock,
transferringTestBlockM) where
import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.GPSS.Block
awaitingTestBlock :: MonadDES m
=> (a -> Signalable m Bool)
-> Block m a a
{-# INLINABLE awaitingTestBlock #-}
awaitingTestBlock :: (a -> Signalable m Bool) -> Block m a a
awaitingTestBlock a -> Signalable m Bool
f =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m a
blockProcess = \a
a ->
do let s :: Signalable m Bool
s = a -> Signalable m Bool
f a
a
loop :: Process m ()
loop =
do Bool
f <- Event m Bool -> Process m Bool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Bool -> Process m Bool) -> Event m Bool -> Process m Bool
forall a b. (a -> b) -> a -> b
$ Signalable m Bool -> Event m Bool
forall (m :: * -> *) a. Signalable m a -> Event m a
readSignalable Signalable m Bool
s
if Bool
f
then () -> Process m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do Signal m () -> Process m ()
forall (m :: * -> *) a. MonadDES m => Signal m a -> Process m a
processAwait (Signal m () -> Process m ()) -> Signal m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Signalable m Bool -> Signal m ()
forall (m :: * -> *) a. Signalable m a -> Signal m ()
signalableChanged_ Signalable m Bool
s
Process m ()
loop
Process m ()
loop
a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
}
awaitingTestBlockM :: MonadDES m
=> (a -> Process m (Signalable m Bool))
-> Block m a a
{-# INLINABLE awaitingTestBlockM #-}
awaitingTestBlockM :: (a -> Process m (Signalable m Bool)) -> Block m a a
awaitingTestBlockM a -> Process m (Signalable m Bool)
f =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m a
blockProcess = \a
a ->
do Signalable m Bool
s <- a -> Process m (Signalable m Bool)
f a
a
let loop :: Process m ()
loop =
do Bool
f <- Event m Bool -> Process m Bool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Bool -> Process m Bool) -> Event m Bool -> Process m Bool
forall a b. (a -> b) -> a -> b
$ Signalable m Bool -> Event m Bool
forall (m :: * -> *) a. Signalable m a -> Event m a
readSignalable Signalable m Bool
s
if Bool
f
then () -> Process m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do Signal m () -> Process m ()
forall (m :: * -> *) a. MonadDES m => Signal m a -> Process m a
processAwait (Signal m () -> Process m ()) -> Signal m () -> Process m ()
forall a b. (a -> b) -> a -> b
$ Signalable m Bool -> Signal m ()
forall (m :: * -> *) a. Signalable m a -> Signal m ()
signalableChanged_ Signalable m Bool
s
Process m ()
loop
Process m ()
loop
a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
}
transferringTestBlock :: MonadDES m
=> (a -> Bool)
-> Block m a ()
-> Block m a a
{-# INLINABLE transferringTestBlock #-}
transferringTestBlock :: (a -> Bool) -> Block m a () -> Block m a a
transferringTestBlock a -> Bool
pred Block m a ()
block =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m a
blockProcess = \a
a ->
do let f :: Bool
f = a -> Bool
pred a
a
if Bool
f
then a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
else Process m () -> Process m a
forall (m :: * -> *) a. MonadDES m => Process m () -> Process m a
transferProcess (Block m a () -> a -> Process m ()
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m a ()
block a
a)
}
transferringTestBlockM :: MonadDES m
=> (a -> Process m Bool)
-> Block m a ()
-> Block m a a
{-# INLINABLE transferringTestBlockM #-}
transferringTestBlockM :: (a -> Process m Bool) -> Block m a () -> Block m a a
transferringTestBlockM a -> Process m Bool
pred Block m a ()
block =
Block :: forall (m :: * -> *) a b. (a -> Process m b) -> Block m a b
Block { blockProcess :: a -> Process m a
blockProcess = \a
a ->
do Bool
f <- a -> Process m Bool
pred a
a
if Bool
f
then a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
else Process m () -> Process m a
forall (m :: * -> *) a. MonadDES m => Process m () -> Process m a
transferProcess (Block m a () -> a -> Process m ()
forall (m :: * -> *) a b. Block m a b -> a -> Process m b
blockProcess Block m a ()
block a
a)
}