Copyright | (c) 2008-2010 Galois, Inc. |
---|---|
License | BSD3 |
Maintainer | John Launchbury <john@galois.com> |
Stability | Portability : concurrency |
Safe Haskell | None |
Language | Haskell2010 |
Primitive combinators for the Orc EDSL in Haskell.
Documentation
A monad for many-valued concurrency, external actions and managed
resources. An expression of type Orc a
may perform many actions
and return many results of type a
. The MonadPlus
instance does
not obey the Right-Zero law (p >> stop /= stop
).
module Control.Monad
module Control.Applicative
module Control.Concurrent.MonadIO
Finish the local thread of operations, so that anything sequenced
afterwards is not executed. It satisfies the following law:
stop >>= k == stop
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 to eagerly
is non-blocking, while an invocation of the
resulting handle is blocking. eagerly
satisfies the following
laws:
Par-eagerly:
eagerly p >>= (\x -> k x <|> h) == (eagerly p >>= k) <|> h
Eagerly-swap:
do y <- eagerly p x <- eagerly q k x y == do x <- eagerly q y <- eagerly p k x y
Eagerly-IO:
eagerly (liftIO m) >> p == (liftIO m >> stop) <|> p
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. For example, the following code succeeds immediately:
do x <- val p return x
Whereas this code waits until p
has generated one result before
returning:
do x <- val p publish p