orc-1.2.1.4: Orchestration-style co-ordination EDSL

StabilityPortability : concurrency
MaintainerJohn Launchbury <john@galois.com>
Safe HaskellNone

Orc.Combinators

Description

 

Synopsis

Documentation

signal :: Orc ()Source

Alternate phrasing of return (), which can be placed at the end of an Orc computation to signal that it has no more values to produce.

cut :: Orc a -> Orc aSource

Cut executes an orc expression, waits for the first result, and then suppresses the rest, including killing any threads involved in computing the remainder.

onlyUntil :: Orc a -> Orc b -> Orc bSource

Executes the computation p and done. Once done returns its first result, kill both computations and returns that result. This discards the results of p.

butAfter :: Orc a -> (Float, Orc a) -> Orc aSource

Immediately executes the computation p, but if it hasn't returned a result in t seconds, execute the computation q and return whichever computations returns a result first (killing the other thread).

timeout :: Float -> a -> Orc a -> Orc aSource

Executes a computation p, but if it hasn't returned a result in n seconds return a instead (killing the p computation).

silent :: Orc a -> Orc bSource

Executes the computation p but suppresses its results.

liftList :: MonadPlus list => [a] -> list aSource

Lifts a list into an Orc monad.

repeating :: Orc a -> Orc aSource

Repeatedly executes the computation p and returns its results. repeating works best when p is single-valued: if p is multivalued Orc will spawn a repeating thread for every result returned, resulting in an exponential blow-up of threads (XXX: I don't think this was actually intended.)

runChan :: Chan a -> Orc a -> IO ()Source

Runs a computation p and writes its results to the channel ch.

sync :: (a -> b -> c) -> Orc a -> Orc b -> Orc cSource

Takes the first result of p, the first result of q, and applies them to f. The computations for p and q are run in parallel.

notBefore :: Orc a -> Float -> Orc aSource

Runs the computation p and returns its first result, but doesn't return before w seconds have elapsed.

syncList :: [Orc a] -> Orc [a]Source

Runs a list of Orc computations ps in parallel until they produce their first result, and returns a list of all these results.

delay :: (RealFrac a, Show a) => a -> Orc ()Source

Wait for a period of w seconds, then continue processing.

printOrc :: Show a => Orc a -> IO ()Source

Runs an Orc computation, eagerly printing out the results of an Orc computation line-by-line.

prompt :: String -> Orc StringSource

Prompts the user for a string. Concurrency-safe.

putStrLine :: String -> Orc ()Source

Writes a string and newline to standard output. Concurrency-safe.

scan :: (a -> s -> s) -> s -> Orc a -> Orc sSource

Analogous to the list scan function, but the order in which the combining function is applied to the results produced by p is nondeterministic.

(<?>) :: Orc a -> Orc a -> Orc aSource

A variant of <+>, pronounced or-else, which performs and returns the results of p, and if p produced no answers go on and performa dn return the results of q.

count :: Orc a -> Orc (Either a Int)Source

For each value produced by p, return a Left a. Once p has finished, return a Right Int containing the number of results produced.

collect :: Orc a -> Orc [a]Source

Collects all of the values of the computation p and delivers them as a list when p is completed.

takeOrc :: Int -> Orc a -> Orc aSource

List-like functions

Runs the computation p and returns the first n results.

dropOrc :: Int -> Orc a -> Orc aSource

Drops the first n results of the computation p, and then returns the rest of the results.

zipOrc :: Orc a -> Orc b -> Orc (a, b)Source

Zips the results of two computations p and q. When one computation finishes, kill the other.

sandbox :: Orc a -> MVar (Maybe a) -> MVar () -> Orc ()Source

Runs the computation p, and repeatedly puts its results (tagged with Just into the vals MVar. Puts Nothing if there are no results left. Stops executing when the end MVar is filled.

echo :: Int -> MVar (Maybe a) -> MVar () -> Orc aSource

The rough inverse of sandbox, repeatedly reads values from the vals MVar until j values have been read or the vals MVar is exhausted (a Nothing is passed). When there are no more values to be returned, fills the end MVar.

zipp :: MVar (Maybe a) -> MVar (Maybe b) -> MVar () -> Orc (a, b)Source

Like echo, repeatedly reads values from the pvals and qvals MVar, returning tuples of the values until one MVar is exhausted. When there are no more values to be returned, fills the end MVar.

publish :: NFData a => a -> Orc aSource

Publish is a hyperstrict form of return. It is useful for combining results from multiple val computations, providing a synchronization point.