garden
Maintainergatlin@niltag.net
Safe HaskellNone
LanguageHaskell2010

Orc

Description

Defines a simple but expressive EDSL for orchestrating parallel and concurrent computations. Based on the Orc language from UT Austin.

Re-implementation of a library from Galois. The Orc type has been re-defined in terms of a delimited continuation monad.

Synopsis

A language for distributed Orchestration

type Orc a = CPS () HIO a Source #

A monad for orchestrating distributed computations via HIO.

runOrc :: Orc a -> IO () Source #

Runs an Orc computation, discarding the (many) results of the computation. See collect on a mechanism for collecting the results of a computation into a list.

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.

Combinators

par :: Orc a -> Orc a -> Orc a Source #

Parallel choice operator that performs the actions of p and q and returns their results as they become available. Also written as |. There is no left-right bias: the ordering between p and q is unspecified.

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 Source #

An associative binary operation

stop :: Orc a Source #

Terminates an Orc computation.

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.

(<+>) :: Orc a -> Orc a -> Orc a Source #

Biased choice operator ("and-then") that performs the action (and returns all the results) of p first, and then once done performs the actions of q.

(<?>) :: Orc a -> Orc a -> Orc a Source #

A variant of <+> ("or-else") which performs and returns the results of p, and if p produced no answers continues to perform and return the results of q.

cut :: Orc a -> Orc a Source #

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

val :: Orc a -> Orc a Source #

An alternate mechanism for eagerly, it fires up a thread for p and returns a lazy thunk that contains the single (trimmed) result of the computation. Be careful to use this function with publish when these lazy values need to be fully evaluated before proceeding further.

eagerly :: Orc a -> Orc (Orc a) Source #

Immediately fires up a thread for p, and then returns a handle to the first result of that thread which is also of type Orc a. An invocation of eagerly is non-blocking, while an invocation of the resulting handle is blocking.

putStrLine :: String -> Orc () Source #

Convenience function to print to stdout in an Orc computation.

echo :: Int -> MVar (Maybe a) -> MVar () -> Orc a Source #

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.

onlyUntil :: Orc a -> Orc b -> Orc b Source #

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

butAfter :: (RealFrac n, Show n) => Orc a -> (n, Orc a) -> Orc a Source #

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

notBefore :: Orc a -> Float -> Orc a Source #

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

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

Wait for a period of w seconds before continuing.

publish :: NFData a => a -> Orc a Source #

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

repeating :: Orc a -> Orc a Source #

Repeatedly executes the computation p and returns its results. repeating works best when p is single-valued: if p is multi-valued Orc will spawn a repeating thread for every result returned, resulting in an exponential blow-up of threads. NB: this behavior may not be intentional

sync :: (a -> b -> c) -> Orc a -> Orc b -> Orc c Source #

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.

List-like utilities

takeOrc :: Int -> Orc a -> Orc a Source #

Runs the computation p and returns the first n results.

dropOrc :: Int -> Orc a -> Orc a Source #

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.

liftList :: MonadPlus list => [a] -> list a Source #

syncList :: [Orc a] -> CPS () HIO [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.

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

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

Re-exports & convenience

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

Provided that the result type can be Shown, this prints the result of an Orc computation.

prompt :: String -> Orc String Source #

Convenience to solicit user input from stdin, via stdout.

(#) :: CPS result m answer -> (answer -> m result) -> m result Source #

shift :: Monad m => ((a -> m r) -> CPS r m r) -> CPS r m a Source #

reset :: Monad m => CPS r m r -> m r Source #

Orphan instances

MonadIO (CPS () HIO) Source # 
Instance details

Methods

liftIO :: IO a -> CPS () HIO a Source #