Maintainer | gatlin@niltag.net |
---|---|

Safe Haskell | Safe-Inferred |

Language | Haskell2010 |

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

- type Orc = CPS () HIO
- runOrc :: Orc a -> IO ()
- collect :: Orc a -> Orc [a]
- par :: Orc a -> Orc a -> Orc a
- (<|>) :: Alternative f => f a -> f a -> f a
- stop :: Orc a
- signal :: Orc ()
- (<+>) :: Orc a -> Orc a -> Orc a
- (<?>) :: Orc a -> Orc a -> Orc a
- cut :: Orc a -> Orc a
- val :: Orc a -> Orc a
- eagerly :: Orc a -> Orc (Orc a)
- putStrLine :: String -> Orc ()
- echo :: Int -> MVar (Maybe a) -> MVar () -> Orc a
- onlyUntil :: Orc a -> Orc b -> Orc b
- butAfter :: (RealFrac n, Show n) => Orc a -> (n, Orc a) -> Orc a
- notBefore :: Orc a -> Float -> Orc a
- delay :: (RealFrac a, Show a) => a -> Orc ()
- publish :: NFData a => a -> Orc a
- repeating :: Orc a -> Orc a
- sync :: (a -> b -> c) -> Orc a -> Orc b -> Orc c
- takeOrc :: Int -> Orc a -> Orc a
- dropOrc :: Int -> Orc a -> Orc a
- zipOrc :: Orc a -> Orc b -> Orc (a, b)
- liftList :: MonadPlus list => [a] -> list a
- syncList :: [Orc a] -> CPS () HIO [a]
- runChan :: Chan a -> Orc a -> IO ()
- printOrc :: Show a => Orc a -> IO ()
- prompt :: String -> Orc String
- (#) :: CPS result m answer -> (answer -> m result) -> m result
- shift :: Monad m => ((a -> m r) -> CPS r m r) -> CPS r m a
- reset :: Monad m => CPS r m r -> m r

# A language for distributed Orchestration

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

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.

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.

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.

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

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.

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`

.