-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A monad for extensible effects and primitives for unrestricted composability of applications -- @package transient @version 0.1.0.2 -- | See http://github.com/agocorona/transient everithing in this -- module is exported in order to allow extensibility. module Transient.Base (!>) :: b -> b1 -> b data TransIO x Transient :: StateT EventF IO (Maybe x) -> TransIO x runTrans :: TransIO x -> StateT EventF IO (Maybe x) type SData = () type EventId = Int type TransientIO = TransIO data EventF EventF :: TransientIO a -> [b -> TransientIO b] -> Map TypeRep SData -> Int -> ThreadId -> Bool -> Maybe EventF -> TVar [EventF] -> Maybe (P Int) -> EventF xcomp :: EventF -> TransientIO a fcomp :: EventF -> [b -> TransientIO b] mfData :: EventF -> Map TypeRep SData mfSequence :: EventF -> Int threadId :: EventF -> ThreadId freeTh :: EventF -> Bool parent :: EventF -> Maybe EventF children :: EventF -> TVar [EventF] maxThread :: EventF -> Maybe (P Int) type P = IORef newp :: a -> IO (IORef a) (=:) :: MonadIO m => IORef a -> (a -> a) -> m () addr :: a -> String type StateIO = StateT EventF IO runTransient :: TransientIO x -> IO (Maybe x, EventF) -- | get the continuation context: closure, continuation, state, child -- threads etc getCont :: MonadState EventF m => m EventF -- | run the continuation context runCont :: EventF -> StateIO () -- | compose a list of continuations compose :: (Monad f, Alternative f) => [a1 -> f a1] -> a1 -> f a -- | run the closure (the x in 'x >>= f') of the current -- bind operation. runClosure :: EventF -> StateIO (Maybe a) -- | run the continuation (the f in 'x >> f') of the current -- bind operation runContinuation :: EventF -> a -> StateIO (Maybe b) -- | dynamic serializable data for logging data IDynamic IDyns :: String -> IDynamic IDynamic :: a -> IDynamic type Recover = Bool type CurrentPointer = [LogElem] type LogEntries = [LogElem] data LogElem WaitRemote :: LogElem Exec :: LogElem Step :: IDynamic -> LogElem data Log Log :: Recover -> CurrentPointer -> LogEntries -> Log data RemoteStatus WasRemote :: RemoteStatus NoRemote :: RemoteStatus -- | a sinonym of empty that can be used in a monadic expression. it stop -- the computation stop :: TransientIO a -- | set the current closure and continuation for the current statement setEventCont :: TransientIO a -> (a -> TransientIO b) -> StateIO () -- | reset the closure and continuation. remove inner binds than the -- prevous computations may have stacked in the list of continuations. resetEventCont :: Maybe a -> StateIO () waitQSemB :: (Ord a, Num a) => IORef a -> IO Bool signalQSemB :: Num a => IORef a -> IO () -- | set the maximun number of threads for a procedure. It is useful for -- the threads :: Int -> TransientIO a -> TransientIO a -- | delete all the previous childs generated by the expressions and -- continue execution of the current thread. oneThread :: TransientIO a -> TransientIO a -- | The threads generated in the process passed as parameter will not be -- killed. freeThreads :: TransientIO a -> TransientIO a -- | The threads will be killed when the parent thread dies. That is the -- default This can be invoked to revert the effect of freeThreads hookedThreads :: TransientIO a -> TransientIO a -- | kill all the child processes killChilds :: TransientIO () -- | Get the session data for the desired type if there is any. getSessionData :: (MonadState EventF m, Typeable a) => m (Maybe a) -- | getSessionData 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" --getSData :: Typeable a => TransIO a -- | set session data for this type. retrieved with getSessionData orr -- getSData setSessionData :: (MonadState EventF m, Typeable a) => a -> m () -- | a shorter name for setSessionData setSData :: (MonadState EventF m, Typeable a) => a -> m () delSessionData :: (MonadState EventF m, Typeable * a) => a -> m () delSData :: (MonadState EventF m, Typeable a) => a -> m () -- | generator of identifiers genNewId :: MonadIO m => MonadState EventF m => m Int refSequence :: IORef Int data Loop Once :: Loop Loop :: Loop Multithread :: Loop -- | variant of parallel that repeatedly executes the IO computation -- and kill the previously created childs waitEvents :: IO b -> TransientIO b -- | variant of + parallel` that execute the IO computation once, and kill -- the previous child threads async :: IO b -> TransientIO b spawn :: IO b -> TransientIO b data EventValue EventValue :: SData -> EventValue -- | return empty to the current thread and launch the IO action in a new -- thread and attaches the continuation after it. if the result of the -- action is Right the process is repeated. if not, it finish. -- -- If the maximum number of threads, set with threads has been -- reached parallel perform the work sequentially, in the current -- thread. -- -- when finish, increase the counter of threads available, if there is a -- limitation of them. parallel :: IO (Either b b) -> TransientIO b loop :: EventF -> IO (Either a a1) -> IO () free :: ThreadId -> EventF -> IO (Maybe EventF) addThread :: EventF -> EventF -> IO () -- | kill all the threads associated with the continuation context killChildren :: EventF -> IO () type EventSetter eventdata response = (eventdata -> IO response) -> IO () type ToReturn response = IO response -- | deinvert an event handler. The first parameter is the event handler to -- be deinverted 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 react :: Typeable eventdata => EventSetter eventdata response -> ToReturn response -> TransientIO eventdata getLineRef :: TVar (Maybe a) roption :: MVar [t] -- | install a event receiver that wait for a string and trigger the -- continuation when this string arrives. option :: (Typeable b, Show b, Read b, Eq b) => b -> [Char] -> TransientIO b -- | 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, input only wait for one valid -- response input :: (Typeable a, Read a) => (a -> Bool) -> TransientIO a -- | non blocking getLine with a validator getLine' :: (Typeable * a, Read a) => (a -> Bool) -> IO a reads1 :: (Typeable * a, Read a) => String -> [(a, String)] inputLoop :: IO () rexit :: MVar a stay :: IO a -- | keep the main thread running, initiate the asynchronous keyboard input -- and execute the transient computation. keep :: TransientIO x -> IO b -- | force the finalization of the main thread and thus, all the -- application exit :: TransientIO a -- | alternative operator for maybe values. Used in infix mode onNothing :: Monad m => m (Maybe b) -> m b -> m b instance Typeable EventF instance Typeable Log instance Typeable RemoteStatus instance Typeable EventValue instance Read LogElem instance Show LogElem instance Eq RemoteStatus instance Eq Loop instance MonadIO TransientIO instance Monad TransientIO instance Monoid a => Monoid (TransientIO a) instance MonadPlus TransientIO instance Alternative TransientIO instance Read IDynamic instance Show IDynamic instance Applicative TransientIO instance Functor TransientIO instance MonadState EventF TransientIO module Transient.EVars newtype EVars EVars :: (IORef (Map Int [EventF])) -> EVars data EVar a EVar :: Int -> (IORef (Maybe a)) -> EVar a newEVar :: TransientIO (EVar a) readEVar :: EVar a -> TransIO a writeEVar :: EVar t -> t -> TransIO () instance Typeable EVars -- | -- https://www.fpcomplete.com/user/agocorona/the-hardworking-programmer-ii-practical-backtracking-to-undo-actions module Transient.Backtrack -- | register an action that will be executed when backtracking registerUndo :: TransientIO a -> TransientIO a -- | the secod parameter will be executed when backtracking onUndo :: TransientIO a -> TransientIO a -> TransientIO a -- | execute backtracking. It execute the registered actions in reverse -- order. -- -- If the backtracking flag is changed the flow proceed forward from that -- point on. -- -- If the backtrack stack is finished or undoCut executed, undo -- will stop. undo :: TransientIO a -- | restart the flow forward from this point on retry :: TransientIO () -- | assures that backtracking will not go further back undoCut :: TransientIO () instance Typeable Backtrack module Transient.Logged fromIDyn :: (Read a, Show a, Typeable a) => IDynamic -> a toIDyn :: (Typeable * a, Show a, Read a) => a -> IDynamic -- | synonymous of step logged :: (Show a, Read a, Typeable a) => TransientIO a -> TransientIO a -- | write the result of the computation in the log and return it. but if -- there is data in the internal log, it read the data from the log and -- do not execute the computation. -- -- It accept nested step's. The effect is that if the outer step is -- executed completely the log of the inner steps are erased. If it is -- not the case, the inner steps are logged this reduce the log of large -- computations to the minimum. That is a feature not present in the -- package Workflow. -- --
-- r <- step $ do -- step this :: TransIO () -- step that :: TransIO () -- step thatOther -- liftIO $ print r ---- -- when print is executed, the log is just the value of r. -- -- but when thatOther is executed the log is: [Exec,(), ()] step :: (Show a, Read a, Typeable a) => TransientIO a -> TransientIO a -- | see -- https://www.fpcomplete.com/user/agocorona/moving-haskell-processes-between-nodes-transient-effects-iv module Transient.Move -- | install in a remote node a haskell package with an executable -- transient service initialized with listen the package, the git -- repository and the main exectable must have the same name installService :: HostName -> PortID -> t -> [Char] -> TransIO () -- | continue the execution in a new node all the previous actions from -- listen to this statement must have been logged beamTo :: HostName -> PortID -> TransientIO () -- | execute in the remote node a process with the same execution state all -- the previous actions from listen to this statement must have -- been logged forkTo :: HostName -> PortID -> TransientIO () -- | executes an action in another node. all the previous actions from -- listen to this statement must have been logged callTo :: (Show a, Read a, Typeable a) => HostName -> PortID -> TransIO a -> TransIO a -- | A connectionless version of callTo for long running remote calls callTo' :: (Show a, Read a, Typeable a) => HostName -> PortID -> TransIO a -> TransIO a data Connection Connection :: PortID -> Handle -> Socket -> Connection -- | Wait for messages and replay the rest of the monadic sequence with the -- log received. listen :: PortID -> TransIO () -- | init a Transient process in a interactive as well as in a replay mode. -- It is intended for twin processes that interact among them in -- different nodes. beamInit :: PortID -> TransIO a -> IO b data Node Node :: HostName -> PortID -> Maybe (Handle, Socket, HostName, PortID) -> Node host :: Node -> HostName port :: Node -> PortID connection :: Node -> Maybe (Handle, Socket, HostName, PortID) nodeList :: TVar [Node] myNode :: IORef (Maybe a) setMyNode :: MonadIO m => t -> t1 -> m () getMyNode :: TransIO x getNodes :: TransIO [Node] addNodes :: [Node] -> TransIO () -- | execute a Transient action in each of the nodes connected. The results -- are aggregated with mappend clustered :: (Typeable a, Show a, Read a) => Monoid a => TransIO a -> TransIO a -- | a connectionless version of clustered for long running remote -- computations. Not tested clustered' :: (Typeable * b, Show b, Read b) => TransIO b -> TransientIO [b] -- | Connect to a new node to another. The other node will notify about -- this connection to all the nodes connected to him. the new connected -- node will receive the list of connected nodes the nodes will be -- updated with this list. it can be retrieved with getNodes connect :: HostName -> PortID -> HostName -> PortID -> TransientIO () instance Typeable Connection instance Typeable Node instance Ord PortID instance Typeable PortID instance Read PortID instance Eq Node instance Read Node instance Show Node instance Read PortNumber -- | see -- https://www.fpcomplete.com/user/agocorona/beautiful-parallel-non-determinism-transient-effects-iii module Transient.Indeterminism -- | slurp a list of values and process them in parallel . To limit the -- number of processing threads, use threads choose :: [a] -> TransientIO a -- | alternative definition with more parallelism choose' :: [a] -> TransientIO a -- | execute a process and get the first n solutions. if the process end -- without finding the number of solutions requested, it return the fond -- ones if he find the number of solutions requested, it kill the threads -- of the process and return It works monitoring the solutions found and -- the number of active threads. If the first parameter is 0, collect -- will return all the results collect :: Int -> TransientIO a -> TransientIO [a] -- | group the output of a possible multithreaded process in groups of n -- elements. group :: Int -> TransientIO a -> TransientIO [a]