Skip to content

Commit

Permalink
Make strategic function application operators handle strategies corre…
Browse files Browse the repository at this point in the history
…ctly (#61)
  • Loading branch information
konsumlamm authored Jan 21, 2024
1 parent 56fe0ef commit b60237e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Control/Parallel/Strategies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -770,43 +770,39 @@ allowing strategies only as second arguments to @$|@ and @$||@.
-- | Sequential function application. The argument is evaluated using
-- the given strategy before it is given to the function.
($|) :: (a -> b) -> Strategy a -> a -> b
f $| s = \ x -> let z = x `using` s in z `pseq` f z
f $| s = \x -> runEval (f <$> s x)

-- | Parallel function application. The argument is evaluated using
-- the given strategy, in parallel with the function application.
($||) :: (a -> b) -> Strategy a -> a -> b
f $|| s = \ x -> let z = x `using` s in z `par` f z
f $|| s = \x -> runEval (f <$> rparWith s x)

-- | Sequential function composition. The result of
-- the second function is evaluated using the given strategy,
-- and then given to the first function.
(.|) :: (b -> c) -> Strategy b -> (a -> b) -> (a -> c)
(.|) f s g = \ x -> let z = g x `using` s in
z `pseq` f z
(.|) f s g = \x -> runEval (f <$> s (g x))

-- | Parallel function composition. The result of the second
-- function is evaluated using the given strategy,
-- in parallel with the application of the first function.
(.||) :: (b -> c) -> Strategy b -> (a -> b) -> (a -> c)
(.||) f s g = \ x -> let z = g x `using` s in
z `par` f z
(.||) f s g = \x -> runEval (f <$> rparWith s (g x))

-- | Sequential inverse function composition,
-- for those who read their programs from left to right.
-- The result of the first function is evaluated using the
-- given strategy, and then given to the second function.
(-|) :: (a -> b) -> Strategy b -> (b -> c) -> (a -> c)
(-|) f s g = \ x -> let z = f x `using` s in
z `pseq` g z
(-|) f s g = \x -> runEval (g <$> s (f x))

-- | Parallel inverse function composition,
-- for those who read their programs from left to right.
-- The result of the first function is evaluated using the
-- given strategy, in parallel with the application of the
-- second function.
(-||) :: (a -> b) -> Strategy b -> (b -> c) -> (a -> c)
(-||) f s g = \ x -> let z = f x `using` s in
z `par` g z
(-||) f s g = \x -> runEval (g <$> rparWith s (f x))

-- -----------------------------------------------------------------------------
-- Old/deprecated stuff
Expand Down

0 comments on commit b60237e

Please sign in to comment.