Skip to content

Commit f29c963

Browse files
committed
Make strategic function application operators handle strategies correctly (#61)
1 parent 2a7be62 commit f29c963

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Control/Parallel/Strategies.hs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -794,43 +794,39 @@ allowing strategies only as second arguments to @$|@ and @$||@.
794794
-- | Sequential function application. The argument is evaluated using
795795
-- the given strategy before it is given to the function.
796796
($|) :: (a -> b) -> Strategy a -> a -> b
797-
f $| s = \ x -> let z = x `using` s in z `pseq` f z
797+
f $| s = \x -> runEval (f <$> s x)
798798

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

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

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

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

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

835831
-- -----------------------------------------------------------------------------
836832
-- Old/deprecated stuff

0 commit comments

Comments
 (0)