Safe Haskell | None |
---|---|
Language | Haskell2010 |
See http://github.com/agocorona/transient everithing in this module is exported in order to allow extensibility.
- (!>) :: Show a => b -> a -> b
- data TransIO x = Transient {}
- type SData = ()
- type EventId = Int
- type TransientIO = TransIO
- data EventF = EventF {}
- type Effects = forall a b c. TransIO a -> TransIO a -> (a -> TransIO b) -> StateIO (StateIO (Maybe c) -> StateIO (Maybe c), Maybe a)
- type StateIO = StateT EventF IO
- runTransient :: TransIO x -> IO (Maybe x, EventF)
- getCont :: TransIO EventF
- runCont :: EventF -> StateIO (Maybe a)
- getContinuations :: StateIO [a -> TransIO b]
- compose :: (Monad f, Alternative f) => [a1 -> f a1] -> a1 -> f a
- runClosure :: EventF -> StateIO (Maybe a)
- runContinuation :: EventF -> a -> StateIO (Maybe b)
- setContinuation :: TransIO a -> (a -> TransIO b) -> [c -> TransIO c] -> StateIO ()
- runContinuations :: [a -> TransIO b] -> c -> TransIO d
- restoreStack :: MonadState EventF m => [b -> TransIO b] -> m ()
- data IDynamic
- type Recover = Bool
- type CurrentPointer = [LogElem]
- type LogEntries = [LogElem]
- data LogElem
- data Log = Log Recover CurrentPointer LogEntries
- data RemoteStatus
- stop :: Alternative m => m a
- (<**) :: TransIO a -> TransIO b -> TransIO a
- atEnd :: TransIO a -> TransIO b -> TransIO a
- (<***) :: TransIO a -> TransIO b -> TransIO a
- atEnd' :: TransIO a -> TransIO b -> TransIO a
- setEventCont :: TransIO a -> (a -> TransIO b) -> StateIO EventF
- resetEventCont :: MonadState EventF m => Maybe t1 -> t -> m (a -> a)
- tailsafe :: [t] -> [t]
- baseEffects :: Effects
- waitQSemB :: (Num a, Ord a) => IORef a -> IO Bool
- signalQSemB :: Num a => IORef a -> IO ()
- threads :: Int -> TransIO a -> TransIO a
- oneThread :: TransientIO a -> TransientIO a
- addThreads' :: Int -> TransIO ()
- addThreads :: Int -> TransIO ()
- freeThreads :: TransIO a -> TransIO a
- hookedThreads :: TransIO a -> TransIO a
- killChilds :: TransientIO ()
- getData :: (MonadState EventF m, Typeable a) => m (Maybe a)
- getSData :: Typeable a => TransIO a
- setData :: (MonadState EventF m, Typeable a) => a -> m ()
- setSData :: (MonadState EventF m, Typeable a) => a -> m ()
- delSessionData :: (Typeable * a, MonadState EventF m) => a -> m ()
- delSData :: (MonadState EventF m, Typeable a) => a -> m ()
- genId :: MonadState EventF m => m Int
- getPrevId :: MonadState EventF m => m Int
- data StreamData a
- = SMore a
- | SLast a
- | SDone
- | SError SomeException
- waitEvents :: IO b -> TransIO b
- waitEvents' :: IO b -> TransIO b
- async :: IO b -> TransIO b
- spawn :: IO b -> TransIO b
- parallel :: IO (StreamData b) -> TransIO (StreamData b)
- loop :: EventF -> IO (StreamData t) -> IO ()
- forkFinally1 :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
- free :: ThreadId -> EventF -> IO (Maybe EventF)
- hangThread :: EventF -> EventF -> IO ()
- killChildren :: EventF -> IO ()
- type EventSetter eventdata response = (eventdata -> IO response) -> IO ()
- type ToReturn response = IO response
- react :: Typeable eventdata => EventSetter eventdata response -> ToReturn response -> TransIO eventdata
- getLineRef :: TVar (Maybe a)
- roption :: MVar [t]
- option :: (Typeable b, Show b, Read b, Eq b) => b -> String -> TransIO b
- input :: (Typeable a, Read a) => (a -> Bool) -> TransIO a
- getLine' :: (Read a, Typeable * a) => (a -> Bool) -> IO a
- reads1 :: (Typeable * a, Read a) => String -> [(a, String)]
- inputLoop :: IO b
- processLine :: String -> IO ()
- rexit :: MVar a
- stay :: IO b
- keep :: TransIO a -> IO a
- keep' :: TransIO a -> IO a
- exit :: a -> TransIO a
- exit' :: MonadIO m => a -> m ()
- onNothing :: Monad m => m (Maybe b) -> m b -> m b
Documentation
type TransientIO = TransIO Source #
type Effects = forall a b c. TransIO a -> TransIO a -> (a -> TransIO b) -> StateIO (StateIO (Maybe c) -> StateIO (Maybe c), Maybe a) Source #
getCont :: TransIO EventF Source #
get the continuation context: closure, continuation, state, child threads etc
getContinuations :: StateIO [a -> TransIO b] Source #
warning: radiactive untyped stuff. handle with care
compose :: (Monad f, Alternative f) => [a1 -> f a1] -> a1 -> f a Source #
compose a list of continuations
runClosure :: EventF -> StateIO (Maybe a) Source #
run the closure (the x
in 'x >>= f') of the current bind operation.
runContinuation :: EventF -> a -> StateIO (Maybe b) Source #
run the continuation (the f
in 'x >>= f') of the current bind operation
runContinuations :: [a -> TransIO b] -> c -> TransIO d Source #
run a chain of continuations. It is up to the programmer to assure by construction that
each continuation type-check with the next, that the parameter type match the input of the first
continuation.
Normally this makes sense if it stop the current flow with stop
after the invocation
restoreStack :: MonadState EventF m => [b -> TransIO b] -> m () Source #
dynamic serializable data for logging
type CurrentPointer = [LogElem] Source #
type LogEntries = [LogElem] Source #
data RemoteStatus Source #
stop :: Alternative m => m a Source #
a sinonym of empty that can be used in a monadic expression. it stop the computation
(<**) :: TransIO a -> TransIO b -> TransIO a infixr 1 Source #
forces the execution of the second operand even if the first stop. Return the first result (experimental)
(<***) :: TransIO a -> TransIO b -> TransIO a infixr 1 Source #
forces the execution of the second operand if the first fails only if the first operand is executed normally, that is , it is not a reexecution consequence of an internal event on it. Return the first result
setEventCont :: TransIO a -> (a -> TransIO b) -> StateIO EventF Source #
set the current closure and continuation for the current statement
resetEventCont :: MonadState EventF m => Maybe t1 -> t -> m (a -> a) Source #
reset the closure and continuation. remove inner binds than the previous computations may have stacked in the list of continuations. resetEventCont :: Maybe a -> EventF -> StateIO (TransIO b -> TransIO b)
Threads
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
oneThread :: TransientIO a -> TransientIO a Source #
delete all the previous childs generated by the expressions and continue execution of the current thread.
addThreads' :: Int -> TransIO () Source #
add n threads to the limit of threads. If there is no limit, it set it
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.
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
killChilds :: TransientIO () Source #
kill all the child processes
extensible state: session data management
getData :: (MonadState EventF m, Typeable a) => m (Maybe a) Source #
Get the state data for the desired type if there is any.
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"
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.
delSessionData :: (Typeable * a, MonadState EventF m) => a -> m () Source #
genId :: MonadState EventF m => m Int Source #
generator of identifiers that are unique withing the current monadic sequence They are not unique in the whole program.
data StreamData a Source #
async calls
Read a => Read (StreamData a) Source # | |
Show a => Show (StreamData a) Source # | |
waitEvents :: IO b -> TransIO b Source #
variant of parallel
that repeatedly executes the IO computation and kill the previously created childs
It is useful in single threaded problems where each event discard the computations spawned by previous events
waitEvents' :: IO b -> TransIO b Source #
async :: IO b -> TransIO b Source #
variant of parallel
that execute the IO computation once, and kill the previous child threads
spawn :: IO b -> TransIO b Source #
variant that spawn free threads. Since there is no thread control, this is faster
parallel :: IO (StreamData b) -> TransIO (StreamData b) Source #
return empty to the current thread, in new thread, execute the IO action,
this IO action modify an internal buffer. then, executes the closure where parallel
is located
In this new execution, since the buffer is filled, parallel
return the content of this buffer.
Then it launch the continuation after it with this new value returned by the closure.
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.
forkFinally1 :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId Source #
killChildren :: EventF -> IO () Source #
kill all the child threads associated with the continuation context
type EventSetter eventdata response = (eventdata -> IO response) -> IO () Source #
react :: Typeable eventdata => EventSetter eventdata response -> ToReturn response -> TransIO eventdata Source #
deinvert an event handler. The first parameter is the event handler setter to be deinverted. Usually it is the primitive provided by a framework to set an event handler
the second is the value to return to the event handler it configures the event handler by calling the first parameter, that set the event handler, with the current continuation
non-blocking keyboard input
getLineRef :: TVar (Maybe a) Source #
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) => (a -> Bool) -> 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
getLine' :: (Read a, Typeable * a) => (a -> Bool) -> IO a Source #
non blocking getLine
with a validator
processLine :: String -> IO () Source #
keep' :: TransIO a -> IO a Source #
same than keep
but do not initiate the asynchronous keyboard input.
Useful for debugging
exit :: 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)
onNothing :: Monad m => m (Maybe b) -> m b -> m b Source #
alternative operator for maybe values. Used in infix mode