Skip to content

Document list strategies that evaluate the spine #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Control/Parallel/Strategies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ parTraversable strat = evalTraversable (rparWith strat)
-- Strategies for lists

-- | Evaluate each element of a list according to the given strategy.
-- Equivalent to 'evalTraversable' at the list type.
-- Equivalent to 'evalTraversable' at the list type.
--
-- __Warning:__ This strategy evaluates the spine of the list
-- and thus does not work on infinite lists.
evalList :: Strategy a -> Strategy [a]
evalList = evalTraversable
-- Alternative explicitly recursive definition:
Expand All @@ -550,14 +553,17 @@ evalList = evalTraversable
-- return (x':xs')

-- | Evaluate each element of a list in parallel according to given strategy.
-- Equivalent to 'parTraversable' at the list type.
-- Equivalent to 'parTraversable' at the list type.
--
-- __Warning:__ This strategy evaluates the spine of the list
-- and thus does not work on infinite lists.
parList :: Strategy a -> Strategy [a]
parList = parTraversable
-- Alternative definition via evalList:
-- parList strat = evalList (rparWith strat)

-- | @'evaListSplitAt' n stratPref stratSuff@ evaluates the prefix
-- (of length @n@) of a list according to @stratPref@ and its the suffix
-- (of length @n@) of a list according to @stratPref@ and the suffix
-- according to @stratSuff@.
evalListSplitAt :: Int -> Strategy [a] -> Strategy [a] -> Strategy [a]
evalListSplitAt n stratPref stratSuff xs
Expand Down Expand Up @@ -598,6 +604,9 @@ parListNth n strat = evalListNth n (rparWith strat)
--
-- This function may be replaced by a more
-- generic clustering infrastructure in the future.
--
-- __Warning:__ This strategy evaluates the spine of the list
-- and thus does not work on infinite lists.
parListChunk :: Int -> Strategy a -> Strategy [a]
parListChunk n strat
| n <= 1 = parList strat
Expand Down Expand Up @@ -630,6 +639,8 @@ evalChunk strat = \end ->
--
-- > parMap strat f = withStrategy (parList strat) . map f
--
-- __Warning:__ This function evaluates the spine of the list
-- and thus does not work on infinite lists.
parMap :: Strategy b -> (a -> b) -> [a] -> [b]
parMap strat f = (`using` parList strat) . map f

Expand Down