data-effects-0.3.0.1: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2024 Sayo Koyoneda
LicenseMPL-2.0 (see the file LICENSE)
Maintainer[email protected]
Safe HaskellNone
LanguageGHC2021

Data.Effect.Concurrent.Parallel

Description

Effects for parallel computations.

Synopsis

Documentation

data Parallel (f :: Type -> Type) a where Source #

An Applicative-based effect for executing computations in parallel.

Constructors

LiftP2

Executes two actions in parallel and blocks until both are complete. Finally, aggregates the execution results based on the specified function.

Fields

  • :: forall a1 b a (f :: Type -> Type). (a1 -> b -> a)

    A function that aggregates the two execution results.

  • -> f a1

    The first action to be executed in parallel.

  • -> f b

    The second action to be executed in parallel.

  • -> Parallel f a
     

Instances

Instances details
() => HFunctor Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> Parallel f :-> Parallel g #

data Halt a where Source #

An effect that blocks a computation indefinitely.

Constructors

Halt :: forall a. Halt a

Blocks a computation indefinitely.

data Race (f :: Type -> Type) a where Source #

An effect that adopts the result of the computation that finishes first among two computations and cancels the other.

Constructors

Race :: forall (f :: Type -> Type) a. f a -> f a -> Race f a

Adopts the result of the computation that finishes first among two computations and cancels the other.

Instances

Instances details
() => HFunctor Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> Race f :-> Race g #

pattern LHalt :: forall a f a1. () => forall. (a ~ a1, ()) => LiftFOE Halt f a Source #

halt :: forall a f. SendFOE Halt f => f a Source #

Blocks a computation indefinitely.

halt' :: forall {k} (tag :: k) a f. SendFOE (Tag Halt tag) f => f a Source #

Blocks a computation indefinitely.

halt'' :: forall {k} (key :: k) a f. SendFOEBy key Halt f => f a Source #

Blocks a computation indefinitely.

liftP2 Source #

Arguments

:: forall a b c f. SendHOE Parallel f 
=> (a -> b -> c) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c 

Executes two actions in parallel and blocks until both are complete. Finally, aggregates the execution results based on the specified function.

liftP2' Source #

Arguments

:: forall {k} (tag :: k) a b c f. SendHOE (TagH Parallel tag) f 
=> (a -> b -> c) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c 

Executes two actions in parallel and blocks until both are complete. Finally, aggregates the execution results based on the specified function.

liftP2'' Source #

Arguments

:: forall {k} (key :: k) a b c f. SendHOEBy key Parallel f 
=> (a -> b -> c) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c 

Executes two actions in parallel and blocks until both are complete. Finally, aggregates the execution results based on the specified function.

race :: forall a f. SendHOE Race f => f a -> f a -> f a Source #

Adopts the result of the computation that finishes first among two computations and cancels the other.

race' :: forall {k} (tag :: k) a f. SendHOE (TagH Race tag) f => f a -> f a -> f a Source #

Adopts the result of the computation that finishes first among two computations and cancels the other.

race'' :: forall {k} (key :: k) a f. SendHOEBy key Race f => f a -> f a -> f a Source #

Adopts the result of the computation that finishes first among two computations and cancels the other.

newtype Concurrently (f :: k -> Type) (a :: k) Source #

A wrapper that allows using the Parallel effect in the form of Applicative / Alternative instances.

Constructors

Concurrently 

Fields

Instances

Instances details
(Race <<: f, Halt <: f, Parallel <<: f, Applicative f) => Alternative (Concurrently f) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

empty :: Concurrently f a #

(<|>) :: Concurrently f a -> Concurrently f a -> Concurrently f a #

some :: Concurrently f a -> Concurrently f [a] #

many :: Concurrently f a -> Concurrently f [a] #

(Parallel <<: f, Applicative f) => Applicative (Concurrently f) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

pure :: a -> Concurrently f a #

(<*>) :: Concurrently f (a -> b) -> Concurrently f a -> Concurrently f b #

liftA2 :: (a -> b -> c) -> Concurrently f a -> Concurrently f b -> Concurrently f c #

(*>) :: Concurrently f a -> Concurrently f b -> Concurrently f b #

(<*) :: Concurrently f a -> Concurrently f b -> Concurrently f a #

Functor f => Functor (Concurrently f) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

fmap :: (a -> b) -> Concurrently f a -> Concurrently f b #

(<$) :: a -> Concurrently f b -> Concurrently f a #

liftP3 Source #

Arguments

:: (Parallel <<: f, Applicative f) 
=> (a -> b -> c -> d)

A function that aggregates the three execution results.

-> f a

The first action to be executed in parallel.

-> f b

The second action to be executed in parallel.

-> f c

The third action to be executed in parallel.

-> f d 

Executes three actions in parallel and blocks until all are complete. Finally, aggregates the execution results based on the specified function.

data Poll (f :: Type -> Type) a where Source #

An effect that realizes polling and cancellation of actions running in parallel.

Constructors

Poldl

Performs polling on an action running in parallel in the form of a fold.

First, the parallel execution of two actions begins.

When the execution of the first action completes, polling on the second action is performed at that point, and the result is passed to the folding function. If the function returns Left, the folding terminates and it becomes the final result. If the second action is not yet complete, it is canceled. If the function returns Right, the folding continues, and the same process repeats.

Fields

  • :: forall a1 b (f :: Type -> Type) a. (a1 -> Maybe b -> f (Either a a1))

    A function for folding.

  • -> f a1

    The first action to be executed in parallel.

  • -> f b

    The second action to be executed in parallel; the target of polling.

  • -> Poll f a
     

Instances

Instances details
() => HFunctor Poll Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> Poll f :-> Poll g #

poldl Source #

Arguments

:: forall a b r f. SendHOE Poll f 
=> (a -> Maybe b -> f (Either r a)) 
-> f a 
-> f b

The second action to be executed in parallel; the target of polling.

-> f r 

Performs polling on an action running in parallel in the form of a fold.

First, the parallel execution of two actions begins.

When the execution of the first action completes, polling on the second action is performed at that point, and the result is passed to the folding function. If the function returns Left, the folding terminates and it becomes the final result. If the second action is not yet complete, it is canceled. If the function returns Right, the folding continues, and the same process repeats.

poldl' Source #

Arguments

:: forall {k} (tag :: k) a b r f. SendHOE (TagH Poll tag) f 
=> (a -> Maybe b -> f (Either r a)) 
-> f a 
-> f b

The second action to be executed in parallel; the target of polling.

-> f r 

Performs polling on an action running in parallel in the form of a fold.

First, the parallel execution of two actions begins.

When the execution of the first action completes, polling on the second action is performed at that point, and the result is passed to the folding function. If the function returns Left, the folding terminates and it becomes the final result. If the second action is not yet complete, it is canceled. If the function returns Right, the folding continues, and the same process repeats.

poldl'' Source #

Arguments

:: forall {k} (key :: k) a b r f. SendHOEBy key Poll f 
=> (a -> Maybe b -> f (Either r a)) 
-> f a 
-> f b

The second action to be executed in parallel; the target of polling.

-> f r 

Performs polling on an action running in parallel in the form of a fold.

First, the parallel execution of two actions begins.

When the execution of the first action completes, polling on the second action is performed at that point, and the result is passed to the folding function. If the function returns Left, the folding terminates and it becomes the final result. If the second action is not yet complete, it is canceled. If the function returns Right, the folding continues, and the same process repeats.

cancels Source #

Arguments

:: (Poll <<: f, Applicative f) 
=> f a

The action that controls the cancellation.

-> f b

The action to be canceled.

-> f (a, Maybe b) 

Executes two actions in parallel. If the first action completes before the second, the second action is canceled.

cancelBy Source #

Arguments

:: (Poll <<: f, Applicative f) 
=> f a

The action to be canceled.

-> f b

The action that controls the cancellation.

-> f (Maybe a, b) 

Executes two actions in parallel. If the second action completes before the first, the first action is canceled.

data For (t :: Type -> Type) (f :: Type -> Type) a where Source #

An effect for parallel computations based on a Traversable container t.

Constructors

For :: forall (t :: Type -> Type) (f :: Type -> Type) a1. t (f a1) -> For t f (t a1)

Executes in parallel the actions stored within a Traversable container t.

Instances

Instances details
Functor t => HFunctor (For t) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). (f :-> g) -> For t f :-> For t g #

for :: forall t a f. SendHOE (For t) f => t (f a) -> f (t a) Source #

Executes in parallel the actions stored within a Traversable container t.

for' :: forall {k} (tag :: k) t a f. SendHOE (TagH (For t) tag) f => t (f a) -> f (t a) Source #

Executes in parallel the actions stored within a Traversable container t.

for'' :: forall {k} (key :: k) t a f. SendHOEBy key (For t) f => t (f a) -> f (t a) Source #

Executes in parallel the actions stored within a Traversable container t.

forToParallel :: forall (f :: Type -> Type) (t :: Type -> Type). (Parallel <<: f, Traversable t, Applicative f) => For t f ~> f Source #

Converts the Traversable container-based parallel computation effect For into the Applicative-based parallel computation effect Parallel.