module Simulation.Aivika.GPSS.Block
(Block(..),
GeneratorBlock(..),
withinBlock,
processBlock,
traceBlock) where
import Control.Monad
import Control.Monad.Trans
import qualified Control.Category as C
import Simulation.Aivika
newtype Block a b =
Block { forall a b. Block a b -> a -> Process b
blockProcess :: a -> Process b
}
newtype GeneratorBlock a =
GeneratorBlock { forall a. GeneratorBlock a -> Block a () -> Process ()
runGeneratorBlock :: Block a () -> Process ()
}
instance C.Category Block where
id :: forall a. Block a a
id = Block { blockProcess :: a -> Process a
blockProcess = forall (m :: * -> *) a. Monad m => a -> m a
return }
Block b c
x . :: forall b c a. Block b c -> Block a b -> Block a c
. Block a b
y = Block { blockProcess :: a -> Process c
blockProcess = \a
a -> do { b
b <- forall a b. Block a b -> a -> Process b
blockProcess Block a b
y a
a; forall a b. Block a b -> a -> Process b
blockProcess Block b c
x b
b } }
withinBlock :: Process ()
-> Block a a
withinBlock :: forall a. Process () -> Block a a
withinBlock Process ()
m =
Block { blockProcess :: a -> Process a
blockProcess = \a
a -> Process ()
m forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return a
a }
processBlock :: (a -> Process b)
-> Block a b
processBlock :: forall a b. (a -> Process b) -> Block a b
processBlock = forall a b. (a -> Process b) -> Block a b
Block
traceBlock :: String -> Block a b -> Block a b
traceBlock :: forall a b. String -> Block a b -> Block a b
traceBlock String
message Block a b
x =
Block { blockProcess :: a -> Process b
blockProcess = \a
a -> forall a. String -> Process a -> Process a
traceProcess String
message (forall a b. Block a b -> a -> Process b
blockProcess Block a b
x a
a) }