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