-- |
-- Module     : Simulation.Aivika.GPSS.Block.Assign
-- Copyright  : Copyright (c) 2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.2
--
-- This module defines the GPSS block ASSIGN.
--
module Simulation.Aivika.GPSS.Block.Assign
       (assignBlock,
        assignBlockM) where

import Simulation.Aivika
import Simulation.Aivika.GPSS.Block
import Simulation.Aivika.GPSS.Transact

-- | This is the GPSS construct
--
-- @ASSIGN A,B,C@
assignBlock :: (a -> b)
               -- ^ the transform
               -> Block (Transact a) (Transact b)
assignBlock :: (a -> b) -> Block (Transact a) (Transact b)
assignBlock a -> b
f =
  Block :: forall a b. (a -> Process b) -> Block a b
Block { blockProcess :: Transact a -> Process (Transact b)
blockProcess = \Transact a
a -> Transact b -> Process (Transact b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Transact a -> (a -> b) -> Transact b
forall a b. Transact a -> (a -> b) -> Transact b
assignTransactValue Transact a
a a -> b
f) }

-- | This is the GPSS construct
--
-- @ASSIGN A,B,C@
assignBlockM :: (a -> Process b)
                -- ^ the transform computation
                -> Block (Transact a) (Transact b)
assignBlockM :: (a -> Process b) -> Block (Transact a) (Transact b)
assignBlockM a -> Process b
f =
  Block :: forall a b. (a -> Process b) -> Block a b
Block { blockProcess :: Transact a -> Process (Transact b)
blockProcess = \Transact a
a -> Transact a -> (a -> Process b) -> Process (Transact b)
forall (c :: * -> *) a b.
Monad c =>
Transact a -> (a -> c b) -> c (Transact b)
assignTransactValueM Transact a
a a -> Process b
f }