data-effects-0.4.2.0: A basic framework for effect systems based on effects represented by GADTs.
Copyright(c) 2024-2025 Sayo contributors
LicenseMPL-2.0 (see the file LICENSE)
Maintainerymdfield@outlook.jp
Safe HaskellNone
LanguageGHC2021

Data.Effect.Concurrent.Parallel

Description

Effects for parallel computations.

Synopsis

Documentation

data Parallel (a :: Type -> Type) b 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 b1 b (a :: Type -> Type). (a1 -> b1 -> b)

    A function that aggregates the two execution results.

  • -> a a1

    The first action to be executed in parallel.

  • -> a b1

    The second action to be executed in parallel.

  • -> Parallel a b
     

Instances

Instances details
PolyHFunctor Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

HFunctor Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

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

type FormOf Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type LabelOf Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type OrderOf Parallel Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

data Halt (a :: Type -> Type) b where Source #

An effect that blocks a computation indefinitely.

Constructors

Halt :: forall (a :: Type -> Type) b. Halt a b

Blocks a computation indefinitely.

Instances

Instances details
FirstOrder Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

PolyHFunctor Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

HFunctor Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

hfmap :: (forall x. f x -> g x) -> Halt f a -> Halt g a #

type FormOf Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type LabelOf Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type OrderOf Halt Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

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

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

Constructors

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

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

Instances

Instances details
PolyHFunctor Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

HFunctor Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

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

type FormOf Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type LabelOf Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type OrderOf Race Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

halt :: forall a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Halt :> es) => f a Source #

Blocks a computation indefinitely.

halt' :: forall {k} (key :: k) a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Has key Halt es) => f a Source #

Blocks a computation indefinitely.

halt'' :: forall {k} (tag :: k) a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Tagged tag Halt :> es) => f a Source #

Blocks a computation indefinitely.

halt'_ :: forall a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, In Halt es) => f a Source #

Blocks a computation indefinitely.

liftP2 Source #

Arguments

:: forall a b c1 f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c2 :: (Type -> Type) -> Constraint). (Free c2 ff, f ~ Eff ff es, Parallel :> es) 
=> (a -> b -> c1) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c1 

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 c1 f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c2 :: (Type -> Type) -> Constraint). (Free c2 ff, f ~ Eff ff es, Has key Parallel es) 
=> (a -> b -> c1) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c1 

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 c1 f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c2 :: (Type -> Type) -> Constraint). (Free c2 ff, f ~ Eff ff es, Tagged tag Parallel :> es) 
=> (a -> b -> c1) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c1 

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 a b c1 f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c2 :: (Type -> Type) -> Constraint). (Free c2 ff, f ~ Eff ff es, In Parallel es) 
=> (a -> b -> c1) 
-> f a 
-> f b

The second action to be executed in parallel.

-> f c1 

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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Race :> es) => 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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Has key Race es) => 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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Tagged tag Race :> es) => 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 a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, In Race es) => 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 (ff :: (Type -> Type) -> Type -> Type) (es :: [Effect]) a Source #

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

Constructors

Concurrently 

Fields

Instances

Instances details
(Race :> es, Halt :> es, Parallel :> es, Applicative (Eff ff es), Free c ff) => Alternative (Concurrently ff es) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

empty :: Concurrently ff es a #

(<|>) :: Concurrently ff es a -> Concurrently ff es a -> Concurrently ff es a #

some :: Concurrently ff es a -> Concurrently ff es [a] #

many :: Concurrently ff es a -> Concurrently ff es [a] #

(Parallel :> es, Applicative (Eff ff es), Free c ff) => Applicative (Concurrently ff es) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

pure :: a -> Concurrently ff es a #

(<*>) :: Concurrently ff es (a -> b) -> Concurrently ff es a -> Concurrently ff es b #

liftA2 :: (a -> b -> c0) -> Concurrently ff es a -> Concurrently ff es b -> Concurrently ff es c0 #

(*>) :: Concurrently ff es a -> Concurrently ff es b -> Concurrently ff es b #

(<*) :: Concurrently ff es a -> Concurrently ff es b -> Concurrently ff es a #

Functor (Eff ff es) => Functor (Concurrently ff es) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

fmap :: (a -> b) -> Concurrently ff es a -> Concurrently ff es b #

(<$) :: a -> Concurrently ff es b -> Concurrently ff es a #

liftP3 Source #

Arguments

:: forall a b c d (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (con :: (Type -> Type) -> Constraint). (Parallel :> es, Free con ff) 
=> (a -> b -> c -> d)

A function that aggregates the three execution results.

-> Eff ff es a

The first action to be executed in parallel.

-> Eff ff es b

The second action to be executed in parallel.

-> Eff ff es c

The third action to be executed in parallel.

-> Eff ff es d 

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

data Poll (a :: Type -> Type) b 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 b1 (a :: Type -> Type) b. (a1 -> Maybe b1 -> a (Either b a1))

    A function for folding.

  • -> a a1

    The first action to be executed in parallel.

  • -> a b1

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

  • -> Poll a b
     

Instances

Instances details
HFunctor Poll Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

Methods

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

type FormOf Poll Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type LabelOf Poll Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type OrderOf Poll Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

poldl Source #

Arguments

:: forall a b r f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Poll :> es) 
=> (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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Has key Poll es) 
=> (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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Tagged tag Poll :> es) 
=> (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 a b r f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, In Poll es) 
=> (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

:: forall a b (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Poll :> es, Applicative (Eff ff es), Free c ff) 
=> Eff ff es a

The action that controls the cancellation.

-> Eff ff es b

The action to be canceled.

-> Eff ff es (a, Maybe b) 

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

cancelBy Source #

Arguments

:: forall a b (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Poll :> es, Applicative (Eff ff es), Free c ff) 
=> Eff ff es a

The action to be canceled.

-> Eff ff es b

The action that controls the cancellation.

-> Eff ff es (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) (a :: Type -> Type) b where Source #

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

Constructors

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

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

Instances

Instances details
PolyHFunctor (For t) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

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

Defined in Data.Effect.Concurrent.Parallel

Methods

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

type FormOf (For t) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type FormOf (For t) = 'Polynomial
type LabelOf (For t) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type LabelOf (For t) = ForLabel
type OrderOf (For t) Source # 
Instance details

Defined in Data.Effect.Concurrent.Parallel

type OrderOf (For t) = 'HigherOrder

for :: forall t a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, For t :> es) => 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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Has key (For t) es) => 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 (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, Tagged tag (For t) :> es) => t (f a) -> f (t a) Source #

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

for'_ :: forall t a f (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Free c ff, f ~ Eff ff es, In (For t) es) => t (f a) -> f (t a) Source #

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

forToParallel :: forall (t :: Type -> Type) a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Parallel :> es, Traversable t, Applicative (Eff ff es), Free c ff) => For t (Eff ff es) a -> Eff ff es a Source #

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

runConcurrentIO :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (UnliftIO :> es, Emb IO :> es, forall (es' :: [Effect]). Monad (Eff ff es'), Free c ff) => Eff ff (Parallel ': (Race ': (Poll ': (Halt ': es)))) a -> Eff ff es a Source #

runParallelIO :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (UnliftIO :> es, Emb IO :> es, Monad (Eff ff es), Free c ff) => Eff ff (Parallel ': es) a -> Eff ff es a Source #

parallelToIO :: forall (m :: Type -> Type). MonadUnliftIO m => Parallel ~~> m Source #

runPollIO :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Emb IO :> es, UnliftIO :> es, Monad (Eff ff es), Free c ff) => Eff ff (Poll ': es) a -> Eff ff es a Source #

runRaceIO :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Emb IO :> es, UnliftIO :> es, Monad (Eff ff es), Free c ff) => Eff ff (Race ': es) a -> Eff ff es a Source #

runHaltIO :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Emb IO :> es, Monad (Eff ff es), Free c ff) => Eff ff (Halt ': es) a -> Eff ff es a Source #

raceToIO :: forall (m :: Type -> Type). MonadUnliftIO m => Race ~~> m Source #

pollToIO :: forall (m :: Type -> Type). MonadUnliftIO m => Poll ~~> m Source #

haltToIO :: forall (m :: Type -> Type). MonadIO m => Halt ~~> m Source #

runParallelAsSequential :: forall a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Applicative (Eff ff es), Free c ff) => Eff ff (Parallel ': es) a -> Eff ff es a Source #

parallelToSequential :: forall (ff :: (Type -> Type) -> Type -> Type) (es :: [Effect]). Applicative (Eff ff es) => Parallel ~~> Eff ff es Source #

runForAsParallel :: forall (t :: Type -> Type) a (es :: [Effect]) (ff :: (Type -> Type) -> Type -> Type) (c :: (Type -> Type) -> Constraint). (Parallel :> es, Traversable t, Applicative (Eff ff es), Free c ff) => Eff ff (For t ': es) a -> Eff ff es a Source #