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