Skip to content
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

Implementation of seqBifoldable #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions Control/Seq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Control.Seq

-- * Sequential strategies for foldable data types
, seqFoldable -- :: Foldable t => Strategy a -> Strategy (t a)
, seqBifoldable -- :: Bifoldable p => Strategy a -> Strategy b -> Strategy (p a b)
, seqMap -- :: Strategy k -> Strategy v -> Strategy (Map k v)
, seqArray -- :: Ix i => Strategy a -> Strategy (Array i a)
, seqArrayBounds -- :: Ix i => Strategy i -> Strategy (Array i a)
Expand All @@ -64,6 +65,7 @@ import Data.Foldable (toList)
#else
import Data.Foldable (Foldable, toList)
#endif
import Data.Bifoldable (Bifoldable (bifoldMap))
import Data.Map (Map)
import qualified Data.Map (toList)
#if !((__GLASGOW_HASKELL__ >= 711) && MIN_VERSION_array(0,5,1))
Expand Down Expand Up @@ -146,6 +148,11 @@ seqFoldable strat = seqList strat . toList

{-# SPECIALISE seqFoldable :: Strategy a -> Strategy [a] #-}

-- | Evaluate the elements of a bifoldable data structure according to
-- the given strategy
seqBifoldable :: Bifoldable p => Strategy a -> Strategy b -> Strategy (p a b)
seqBifoldable = bifoldMap
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, the Monoid () instance doesn't force anything.

This should work:

Suggested change
seqBifoldable = bifoldMap
seqBifoldable strat1 strat2 = bifoldr (\x acc -> strat1 x `seq` acc) (\y acc -> strat2 y `seq` acc) ()


-- | Evaluate the elements of an array according to the given strategy.
-- Evaluation of the array bounds may be triggered as a side effect.
#if (__GLASGOW_HASKELL__ >= 711) && MIN_VERSION_array(0,5,1)
Expand Down
1 change: 1 addition & 0 deletions parallel.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
build-depends:
array >= 0.3 && < 0.6,
base >= 4.3 && < 4.17,
bifunctor ,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a bound and only be used for GHC < 8.2 (since Bifoldable is included in base since GHC 8.2 / base-4.10). The most liberal bounds should be fine, since we only use bifoldr (at least in my suggestion).

Suggested change
bifunctor ,
bifunctors >= 0.1 && < 5.7,

bifunctor is a deprecated package that doesn't even export the stuff we're using.

containers >= 0.4 && < 0.7,
deepseq >= 1.1 && < 1.5

Expand Down