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 { blockProcess :: a -> Process b
}
newtype GeneratorBlock a =
GeneratorBlock { runGeneratorBlock :: Block a () -> Process ()
}
instance C.Category Block where
id = Block { blockProcess = return }
x . y = Block { blockProcess = \a -> do { b <- blockProcess y a; blockProcess x b } }
withinBlock :: Process ()
-> Block a a
withinBlock m =
Block { blockProcess = \a -> m >> return a }
processBlock :: (a -> Process b)
-> Block a b
processBlock = Block
traceBlock :: String -> Block a b -> Block a b
traceBlock message x =
Block { blockProcess = \a -> traceProcess message (blockProcess x a) }