Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data TransIO x = Transient {}
- type TransientIO = TransIO
- keep :: Typeable a => TransIO a -> IO (Maybe a)
- keep' :: Typeable a => TransIO a -> IO (Maybe a)
- stop :: Alternative m => m stopped
- option :: (Typeable b, Show b, Read b, Eq b) => b -> String -> TransIO b
- input :: (Typeable a, Read a, Show a) => (a -> Bool) -> String -> TransIO a
- exit :: Typeable a => a -> TransIO a
- async :: IO b -> TransIO b
- waitEvents :: IO b -> TransIO b
- spawn :: IO a -> TransIO a
- parallel :: IO (StreamData b) -> TransIO (StreamData b)
- sample :: Eq a => IO a -> Int -> TransIO a
- react :: Typeable eventdata => ((eventdata -> IO response) -> IO ()) -> IO response -> TransIO eventdata
- setState :: (MonadState EventF m, Typeable a) => a -> m ()
- setData :: (MonadState EventF m, Typeable a) => a -> m ()
- getState :: Typeable a => TransIO a
- getSData :: Typeable a => TransIO a
- getData :: (MonadState EventF m, Typeable a) => m (Maybe a)
- delState :: (MonadState EventF m, Typeable a) => a -> m ()
- delData :: (MonadState EventF m, Typeable a) => a -> m ()
- modifyData :: (MonadState EventF m, Typeable a) => (Maybe a -> Maybe a) -> m ()
- modifyState :: (MonadState EventF m, Typeable a) => (Maybe a -> Maybe a) -> m ()
- try :: TransIO a -> TransIO a
- threads :: Int -> TransIO a -> TransIO a
- addThreads :: Int -> TransIO ()
- freeThreads :: TransIO a -> TransIO a
- hookedThreads :: TransIO a -> TransIO a
- oneThread :: TransIO a -> TransIO a
- killChilds :: TransIO ()
- (**>) :: AdditionalOperators m => m a -> m b -> m b
- (<**) :: AdditionalOperators m => m a -> m b -> m a
- (<***) :: AdditionalOperators m => m a -> m b -> m a
- (<|) :: TransIO a -> TransIO b -> TransIO a
- onException :: Exception e => (e -> TransIO ()) -> TransIO ()
- cutExceptions :: TransientIO ()
- continue :: TransIO ()
- data StreamData a
- = SMore a
- | SLast a
- | SDone
- | SError SomeException
- genId :: MonadState EventF m => m Int
The Monad
Monad TransIO Source # | |
Functor TransIO Source # | |
Applicative TransIO Source # | |
MonadIO TransIO Source # | |
Alternative TransIO Source # | |
MonadPlus TransIO Source # | |
AdditionalOperators TransIO Source # | |
MonadState EventF TransIO Source # | |
(Num a, Eq a) => Num (TransIO a) Source # | |
Monoid a => Monoid (TransIO a) Source # | |
type TransientIO = TransIO Source #
Running the monad
stop :: Alternative m => m stopped Source #
A sinonym of empty that can be used in a monadic expression. it stop the
computation and execute the next alternative computation (composed with <|>
)
input
option :: (Typeable b, Show b, Read b, Eq b) => b -> String -> TransIO b Source #
Install a event receiver that wait for a string and trigger the continuation when this string arrives.
input :: (Typeable a, Read a, Show a) => (a -> Bool) -> String -> TransIO a Source #
Validates an input entered in the keyboard in non blocking mode. non blocking means that
the user can enter also anything else to activate other option
unlike option
, wich watch continuously, input only wait for one valid response
exit :: Typeable a => a -> TransIO a Source #
Force the finalization of the main thread and thus, all the Transient block (and the application if there is no more code)
Asynchronous operations
waitEvents :: IO b -> TransIO b Source #
Variant of parallel
that repeatedly executes the IO computation without end
parallel :: IO (StreamData b) -> TransIO (StreamData b) Source #
Return empty to the current thread and execute the IO action in a new thread. When the IO action returns, the transient computation continues with this value as the result The IO action may be re-executed or not depending on the result. So parallel can spawn any number of threads/results.
If the maximum number of threads, set with threads
has been reached parallel
perform
the work sequentially, in the current thread.
So parallel
means that 'it can be parallelized if there are thread available'
if there is a limitation of threads, when a thread finish, the counter of threads available
is increased so another parallel
can make use of it.
The behaviour of parallel
depend on StreamData
; If SMore
, parallel
will excute again the
IO action. With SLast
, SDone
and SError
, parallel
will not repeat the IO action anymore.
sample :: Eq a => IO a -> Int -> TransIO a Source #
Executes an IO action each certain interval of time and return his value if it changes
react :: Typeable eventdata => ((eventdata -> IO response) -> IO ()) -> IO response -> TransIO eventdata Source #
De-invert an event handler.
The first parameter is the setter of the event handler to be deinverted. Usually it is the primitive provided by a framework to set an event handler
the second parameter is the value to return to the event handler. Usually it is `return()`
it configures the event handler by calling the setter of the event handler with the current continuation
State management
setData :: (MonadState EventF m, Typeable a) => a -> m () Source #
Set session data for this type. retrieved with getData or getSData Note that this is data in a state monad, that means that the update only affect downstream in the monad execution. it is not a global state neither a per user or per thread state it is a monadic state like the one of a state monad.
getSData :: Typeable a => TransIO a Source #
getData specialized for the Transient monad. if Nothing, the monadic computation does not continue.
If there is no such data, getSData
silently stop the computation.
That may or may not be the desired behaviour.
To make sure that this does not get unnoticed, use this construction:
getSData <|> error "no data"
To have the same semantics and guarantees than get
, use a default value:
getInt= getSData <|> return (0 :: Int)
The default value (0 in this case) has the same role than the initial value in a state monad.
The difference is that you can define as many get
as you need for all your data types.
To distingish two data with the same types, use newtype definitions.
getData :: (MonadState EventF m, Typeable a) => m (Maybe a) Source #
Get the state data for the desired type if there is any.
modifyData :: (MonadState EventF m, Typeable a) => (Maybe a -> Maybe a) -> m () Source #
Modify state data. It accept a function that get the current state (if exist) as parameter. The state will be deleted or changed depending on function result
modifyState :: (MonadState EventF m, Typeable a) => (Maybe a -> Maybe a) -> m () Source #
Synonym for modifyData
Thread management
threads :: Int -> TransIO a -> TransIO a Source #
Set the maximun number of threads for a procedure. It is useful to limit the
parallelization of transient code that uses parallel
spawn
and waitEvents
addThreads :: Int -> TransIO () Source #
Assure that at least there are n threads available
freeThreads :: TransIO a -> TransIO a Source #
The threads generated in the process passed as parameter will not be killed by `kill*` primitives.
Since there is no thread control, the application run slightly faster.
hookedThreads :: TransIO a -> TransIO a Source #
The threads will be killed when the parent thread dies. That is the default.
This can be invoked to revert the effect of freeThreads
oneThread :: TransIO a -> TransIO a Source #
Delete all the previous child threads generated by the expression taken as parameter and continue execution of the current thread.
killChilds :: TransIO () Source #
kill all the child threads of the current thread
Additional operators
(**>) :: AdditionalOperators m => m a -> m b -> m b Source #
Executes the second operand even if the frist return empty. A normal imperative (monadic) sequence uses the operator (>>) which in the Transient monad does not execute the next operand if the previous one return empty.
(<**) :: AdditionalOperators m => m a -> m b -> m a Source #
Forces the execution of the second operand even if the first stop. It does not execute the second operand as result of internal events occuring in the first operand. Return the first result
(<***) :: AdditionalOperators m => m a -> m b -> m a Source #
Forces the execution of the second operand even if the first stop. Return the first result. The second operand is executed also when internal events happens in the first operand and it returns something
(<|) :: TransIO a -> TransIO b -> TransIO a Source #
When the first operand is an asynchronous operation, the second operand is executed once (one single time) when the first completes his first asyncronous operation.
This is useful for spawning asynchronous or distributed tasks that are singletons and that should start when the first one is set up.
for example a streaming where the event receivers are acivated before the senders.
exceptions
onException :: Exception e => (e -> TransIO ()) -> TransIO () Source #
When a exception is produced anywhere after this statement, the handler is executed. | handlers are executed Last in first out.
cutExceptions :: TransientIO () Source #
stop the backtracking mechanism from executing further handlers
Utilities
data StreamData a Source #
Async calls
Read a => Read (StreamData a) Source # | |
Show a => Show (StreamData a) Source # | |