diff --git a/.travis.yml b/.travis.yml
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,1 +1,61 @@
-language: haskell
+# NB: don't set `language: haskell` here
+
+# See also https://github.com/hvr/multi-ghc-travis for more information
+env:
+ # we have to use CABALVER=1.16 for GHC<7.6 as well, as there's
+ # no package for earlier cabal versions in the PPA
+ - GHCVER=7.4.2 CABALVER=1.16
+ - GHCVER=7.6.3 CABALVER=1.16
+ - GHCVER=7.8.4 CABALVER=1.18
+ - GHCVER=7.10.1 CABALVER=1.22
+ - GHCVER=head CABALVER=1.22
+
+matrix:
+  allow_failures:
+   - env: GHCVER=head CABALVER=1.22
+
+# Note: the distinction between `before_install` and `install` is not
+#       important.
+before_install:
+ - travis_retry sudo add-apt-repository -y ppa:hvr/ghc
+ - travis_retry sudo apt-get update
+ - travis_retry sudo apt-get install cabal-install-$CABALVER ghc-$GHCVER
+ - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
+ - cabal --version
+
+install:
+ - travis_retry cabal update
+ - cabal install --only-dependencies
+ - travis_retry sudo apt-get -q -y install hlint || cabal install hlint
+
+# Here starts the actual work to be performed for the package under
+# test; any command which exits with a non-zero exit code causes the
+# build to fail.
+script:
+ # -v2 provides useful information for debugging
+ - cabal configure -v2
+
+ # this builds all libraries and executables
+ # (including tests/benchmarks)
+ - cabal build
+
+ # tests that a source-distribution can be generated
+ - cabal sdist
+
+ # check that the generated source-distribution can be built & installed
+ - export SRC_TGZ=$(cabal info . | awk '{print $2 ".tar.gz";exit}') ;
+   cd dist/;
+   if [ -f "$SRC_TGZ" ]; then
+      cabal install --force-reinstalls "$SRC_TGZ";
+   else
+      echo "expected '$SRC_TGZ' not found";
+      exit 1;
+   fi
+
+notifications:
+  irc:
+    channels:
+      - "irc.freenode.org#haskell-lens"
+    skip_join: true
+    template:
+      - "\x0313speculation\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"
diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown
--- a/CHANGELOG.markdown
+++ b/CHANGELOG.markdown
@@ -1,3 +1,10 @@
+/1.5.0.2/
+
+ * Build warning-free on GHC 7.10+
+ * Added an HLint configuration
+ * Removed a redundant constraint from the type of `sequenceByA_`.
+ * Removed a redundant `Monad m` constraint from `instance MonadSpec (ContT r m)`.
+
 /1.5/
 
  * Removed the use of `tag-bits`. This enables the API to be `Trustworthy`.
diff --git a/Control/Concurrent/Speculation.hs b/Control/Concurrent/Speculation.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation.hs
+++ /dev/null
@@ -1,160 +0,0 @@
-{-# LANGUAGE CPP #-}
-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
-{-# LANGUAGE Trustworthy #-}
-#endif
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Concurrent.Speculation
--- Copyright   :  (C) 2008-2011 Edward Kmett,
--- License     :  BSD-style (see the file LICENSE)
---
--- Maintainer  :  Edward Kmett <ekmett@gmail.com>
--- Stability   :  provisional
--- Portability :  portable
---
-----------------------------------------------------------------------------
-module Control.Concurrent.Speculation
-    (
-    -- * Speculative application
-      spec
-    , specBy
-    , specOn
-    -- * Speculative application with transactional rollback
-    , specSTM
-    , specOnSTM
-    , specBySTM
-    ) where
-
-import Control.Concurrent.STM
-import Control.Concurrent.Speculation.Internal (returning)
-import Control.Monad (liftM2, unless)
-import Data.Function (on)
-import GHC.Conc
-
--- * Basic speculation
-
--- | @'spec' g f a@ evaluates @f g@ while forcing @a@, if @g == a@ then @f g@ is returned, otherwise @f a@ is evaluated and returned. Furthermore, if the argument has already been evaluated or are not running on the threaded runtime, we skip the @f g@ computation entirely. If a good guess at the value of @a@ is available, this is one way to induce parallelism in an otherwise sequential task. However, if the guess isn\'t available more cheaply than the actual answer, then this saves no work and if the guess is wrong, you risk evaluating the function twice. Under high load or in a runtime with access to a single capability, since 'f g' is computed via the spark queue, the speculation will be skipped and you will obtain the same answer as 'f $! a'.
---
---The best-case timeline looks like:
---
--- > foreground: [----- a -----]
--- > foreground:               [-]    (check g == a)
--- > spark:         [----- f g -----]
--- > overall:    [--- spec g f a ---]
---
--- The worst-case timeline looks like:
---
--- > foreground: [----- a -----]
--- > foreground:               [-]               (check g == a)
--- > foreground:                 [---- f a ----]
--- > spark:         [----- f g -----]
--- > overall:    [-------- spec g f a ---------]
---
--- Note that, if @f g@ takes longer than a to compute, in the HEAD release of GHC, @f g@ will be collected and killed during garbage collection.
---
--- > foreground: [----- a -----]
--- > foreground:               [-]               (check g == a)
--- > foreground:                 [---- f a ----]
--- > spark:         [---- f g ----######         (#'s mark when this spark is collectable)
--- > overall:    [--------- spec g f a --------]
--- 
--- Under high load:
---
--- > foreground: [----- a -----]
--- > foreground:               [-]               (check g == a)
--- > foreground:                 [---- f a ----]
--- > overall:    [-------- spec g f a ---------]
---
--- Compare these to the timeline of @f $! a@:
---
--- > foreground: [----- a -----]
--- > foreground:               [---- f a ----]
--- > orverall:   [---------- f $! a ---------]
-
-spec :: Eq a => a -> (a -> b) -> a -> b
-spec = specBy (==)
-{-# INLINE spec #-}
-
--- | 'spec' with a user defined comparison function
-specBy :: (a -> a -> Bool) -> a -> (a -> b) -> a -> b
-specBy cmp guess f a
-  | numCapabilities == 1 = f $! a
-  | otherwise = speculation `par`
-    if cmp guess a
-    then speculation
-    else f a
-  where speculation = f guess
-{-# INLINE specBy #-}
-
--- | 'spec' comparing by projection onto another type
-specOn :: Eq c => (a -> c) -> a -> (a -> b) -> a -> b
-specOn = specBy . on (==)
-{-# INLINE specOn #-}
-
--- * STM-based speculation
-
--- | @'specSTM' g f a@ evaluates @fg = do g' <- g; f g'@, while forcing @a@, then if @g' == a@ then @fg@ is returned. Otherwise the side-effects of @fg@ are rolled back and @f a@ is evaluated. @g@ is allowed to be a monadic action, so that we can kickstart the computation of @a@ earlier. Under high load, or when we are not using the parallel runtime, the speculation is avoided, to enable this to more closely approximate the runtime profile of spec.
---
--- If the argument @a@ is already evaluated, we don\'t bother to perform @f g@ at all.
---
--- If a good guess at the value of @a@ is available, this is one way to induce parallelism in an otherwise sequential task.
---
--- However, if the guess isn\'t available more cheaply than the actual answer then this saves no work, and if the guess is
--- wrong, you risk evaluating the function twice.
---
--- The best-case timeline looks like:
---
--- > foreground: [--- g >>= f ---]
--- > spark:          [------- a -------]
--- > foreground:                       [-] (compare g' == a)
--- > overall:    [---- specSTM g f a ----]
---
--- The worst-case timeline looks like:
---
--- > foreground: [---- g >>= f ----]
--- > spark:         [------- a -------]
--- > foreground:                      [-] (check if g' == a)
--- > foreground:                        [--] (rollback)
--- > foreground:                           [------ f a ------]
--- > overall:    [------------ specSTM g f a ----------------]
---
--- Under high load, 'specSTM' degrades less gracefully than 'spec':
---
--- > foreground: [---- g >>= f ----]
--- > spark:                        [------- a -------]
--- > foreground:                                     [-] (check if g' == a)
--- > foreground:                                       [--] (rollback)
--- > foreground:                                          [------ f a ------]
--- > overall:    [--------------------specSTM g f a ------------------------]
---
--- Compare these to the timeline of @f $! a@:
---
--- > foreground: [------- a -------]
--- > foreground:                   [------ f a ------]
---
-
-specSTM :: Eq a => STM a -> (a -> STM b) -> a -> STM b
-specSTM = specBySTM (returning (==))
-{-# INLINE specSTM #-}
-
--- | 'specSTM' using a user defined comparison function
-specBySTM :: (a -> a -> STM Bool) -> STM a -> (a -> STM b) -> a -> STM b
-specBySTM cmp mguess f a = do
-  sparks <- unsafeIOToSTM numSparks
-  if sparks < numCapabilities
-    then a `par` do
-      guess <- mguess
-      result <- f guess
-      -- rendezvous with a
-      matching <- cmp guess a
-      unless matching retry
-      return result
-     `orElse`
-      f a
-    else f $! a
-{-# INLINE specBySTM #-}
-
--- | @'specBySTM' . 'on' (==)@
-specOnSTM :: Eq c => (a -> STM c) -> STM a -> (a -> STM b) -> a -> STM b
-specOnSTM = specBySTM . on (liftM2 (==))
-{-# INLINE specOnSTM #-}
diff --git a/Control/Concurrent/Speculation/Class.hs b/Control/Concurrent/Speculation/Class.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation/Class.hs
+++ /dev/null
@@ -1,40 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Concurrent.Speculation.Class
--- Copyright   :  (C) 2011 Edward Kmett, Jake McArthur
--- License     :  BSD-style (see the file LICENSE)
---
--- Maintainer  :  Edward Kmett <ekmett@gmail.com>
--- Stability   :  provisional
--- Portability :  portable
---
--- Versions of the combinators from the 'speculation' package
--- with the signature rearranged to enable them to be used
--- directly as actions in the 'Cont' and 'ContT' monads
--- or any other 'Codensity'-shaped monad.
-----------------------------------------------------------------------------
-module Control.Concurrent.Speculation.Class where
-
-import Control.Monad.Trans.Cont
-import Control.Concurrent.Speculation
-import Data.Function (on)
-
-class MonadSpec m where
-  -- | @spec@ with a user supplied comparison function
-  specByM :: (a -> a -> Bool) -> a -> a -> m a
-
--- | When a is unevaluated, @'spec' g a@ evaluates the current continuation 
--- with @g@ while testing if @g@ '==' @a@, if they differ, it re-evalutes the
--- continuation with @a@. If @a@ was already evaluated, the continuation is
--- just directly applied to @a@ instead.
-specM :: (MonadSpec m, Eq a) => a -> a -> m a
-specM = specByM (==)
-
--- | @spec'@ with a user supplied comparison function
-specOnM :: (MonadSpec m, Eq c) => (a -> c) -> a -> a -> m a
-specOnM = specByM . on (==)
-
--- * Basic speculation
-
-instance Monad m => MonadSpec (ContT r m) where
-  specByM f g a = ContT $ \k -> specBy f g k a
diff --git a/Control/Concurrent/Speculation/Foldable.hs b/Control/Concurrent/Speculation/Foldable.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation/Foldable.hs
+++ /dev/null
@@ -1,416 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-module Control.Concurrent.Speculation.Foldable
-    ( 
-    -- * Speculative folds
-      fold, foldBy
-    , foldMap, foldMapBy
-    , foldr, foldrBy
-    , foldl, foldlBy
-    , foldr1, foldr1By
-    , foldl1, foldl1By
-    -- ** Speculative monadic folds
-    , foldrM, foldrByM
-    , foldlM, foldlByM
-    -- * Speculative transactional monadic folds
-    , foldrSTM, foldrBySTM
-    , foldlSTM, foldlBySTM
-    -- * Folding actions
-    -- ** Applicative actions
-    , traverse_, traverseBy_
-    , for_, forBy_
-    , sequenceA_, sequenceByA_
-    , asum, asumBy
-    -- ** Monadic actions
-    , mapM_, mapByM_
-    , forM_, forByM_
-    , sequence_, sequenceBy_
-    , msum, msumBy
-    -- ** Speculative transactional monadic actions
-    , mapSTM_, forSTM_, sequenceSTM_
-    -- * Specialized folds
-    , toList, toListBy
-    , concat, concatBy
-    , concatMap, concatMapBy
-    , all, any, and, or
-    , sum, sumBy
-    , product, productBy
-    , maximum, maximumBy
-    , minimum, minimumBy
-    -- * Searches
-    , elem, elemBy
-    , notElem, notElemBy
-    , find, findBy
-    ) where
-
-import Prelude hiding 
-    (foldl, foldl1, foldr, foldr1
-    , any, all, and, or, mapM_, sequence_
-    , elem, notElem, sum, product
-    , minimum, maximum, concat, concatMap
-    )
-
-import Data.Monoid
-import Data.Ix ()
-import Data.Function (on)
-import Data.Foldable (Foldable)
-import qualified Data.Foldable as Foldable
-import Control.Concurrent.STM
-import Control.Concurrent.Speculation
-import Control.Concurrent.Speculation.Internal
-import Control.Applicative
-import Control.Monad hiding (mapM_, msum, forM_, sequence_)
-
--- | Given a valid estimator @g@, @'fold' g f xs@ yields the same answer as @'fold' f xs@.
--- 
--- @g n@ should supply an estimate of the value of the monoidal summation over the last @n@ elements of the container.
--- 
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
--- provide increased opportunities for parallelism.
-
-fold :: (Foldable f, Monoid m, Eq m) => (Int -> m) -> f m -> m
-fold = foldBy (==)
-{-# INLINE fold #-}
-
--- | 'fold' using 'specBy'
-foldBy :: (Foldable f, Monoid m) => (m -> m -> Bool) -> (Int -> m) -> f m -> m
-foldBy cmp g = foldrBy cmp g mappend mempty
-{-# INLINE foldBy #-}
-
--- | Given a valid estimator @g@, @'foldMap' g f xs@ yields the same answer as @'foldMap' f xs@.
--- 
--- @g n@ should supply an estimate of the value of the monoidal summation over the last @n@ elements of the container.
--- 
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
--- provide increased opportunities for parallelism.
-
-foldMap :: (Foldable f, Monoid m, Eq m) => (Int -> m) -> (a -> m) -> f a -> m
-foldMap = foldMapBy (==)
-{-# INLINE foldMap #-}
-
--- | 'foldMap' using 'specBy'
-foldMapBy :: (Foldable f, Monoid m) => (m -> m -> Bool) -> (Int -> m) -> (a -> m) -> f a -> m
-foldMapBy cmp g f = foldrBy cmp g (mappend . f) mempty
-{-# INLINE foldMapBy #-}
-
-
-foldr :: (Foldable f, Eq b) => (Int -> b) -> (a -> b -> b) -> b -> f a -> b
-foldr = foldrBy (==)
-{-# INLINE foldr #-}
-
--- | Given a valid estimator @g@, @'foldr' g f z xs@ yields the same answer as @'foldr'' f z xs@.
---
--- @g n@ should supply an estimate of the value returned from folding over the last @n@ elements of the container.
---
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
--- provide increased opportunities for parallelism.
-foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> f a -> b
-foldrBy cmp g f z = extractAcc . Foldable.foldr mf (Acc 0 z)
-  where
-    mf a (Acc n b) = Acc (n + 1) (specBy cmp (g n) (f a) b)
-{-# INLINE foldrBy #-}
-
-
-{-
--- Variations:
--- These variations are not used because the values ot the left shouldn't affect the intermediate state of a right fold.
---
--- this version receiveds both the number of values remaining and the number so far
-
-foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> Int -> b) -> (a -> b -> b) -> b -> f a -> b
-foldrBy cmp g f z xs = Foldable.foldr mf (Acc 0 (const z)) xs 0
-  where 
-    mf a (Acc r b) !l = let l' = l + 1 in Acc (r + 1) (specBy cmp (g l') (f a) (b l'))
-{-# INLINE foldrBy #-}
-
--- this estimator receives the number of values to the left of the summation. 
-foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> f a -> b
-foldrBy cmp g f z xs = Foldable.foldr mf (const z) xs 0
-  where 
-    mf a b !i = let i' = i + 1 in specBy cmp (g i') (f a) (b i')
-{-# INLINE foldrBy #-}
--}
-
-foldlM :: (Foldable f, Monad m, Eq (m b)) => (Int -> m b) -> (b -> a -> m b) -> m b -> f a -> m b
-foldlM = foldlByM (==)
-{-# INLINE foldlM #-}
-
-foldlByM ::  (Foldable f, Monad m) => (m b -> m b -> Bool) -> (Int -> m b) -> (b -> a -> m b) -> m b -> f a -> m b
-foldlByM  cmp g f mz = liftM extractAcc . Foldable.foldl go (liftM (Acc 0) mz) 
-  where
-    go mia b = do
-      Acc n a <- mia
-      a' <- specBy cmp (g n) (>>= (`f` b)) (return a)
-      return (Acc (n + 1) a')
-{-# INLINE foldlByM #-}
-
-foldrM :: (Foldable f, Monad m, Eq (m b)) => (Int -> m b) -> (a -> b -> m b) -> m b -> f a -> m b
-foldrM = foldrByM (==)
-{-# INLINE foldrM #-}
-
-foldrByM :: (Foldable f, Monad m) => (m b -> m b -> Bool) -> (Int -> m b) -> (a -> b -> m b) -> m b -> f a -> m b
-foldrByM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz) 
-  where
-    go a mib = do
-      Acc n b <- mib
-      b' <- specBy cmp (g n) (>>= f a) (return b)
-      return (Acc (n + 1) b')
-{-# INLINE foldrByM #-}
-
-foldlSTM :: (Foldable f, Eq a) => (Int -> STM a) -> (a -> b -> STM a) -> STM a -> f b -> STM a
-foldlSTM = foldlBySTM (returning (==))
-{-# INLINE foldlSTM #-}
-
-foldlBySTM :: Foldable f => (a -> a -> STM Bool) -> (Int -> STM a) -> (a -> b -> STM a) -> STM a -> f b -> STM a
-foldlBySTM cmp g f mz = liftM extractAcc . Foldable.foldl go (liftM (Acc 0) mz)
-  where
-    go mia b = do
-      Acc n a <- mia
-      a' <- specBySTM cmp (g n) (`f` b) a
-      return (Acc (n + 1) a')
-{-# INLINE foldlBySTM #-}
-
-foldrSTM :: (Foldable f, Eq b) => (Int -> STM b) -> (a -> b -> STM b) -> STM b -> f a -> STM b
-foldrSTM = foldrBySTM (returning (==))
-{-# INLINE foldrSTM #-}
-
-foldrBySTM :: Foldable f => (b -> b -> STM Bool) -> (Int -> STM b) -> (a -> b -> STM b) -> STM b -> f a -> STM b
-foldrBySTM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz)
-  where
-    go a mib = do
-      Acc n b <- mib
-      b' <- specBySTM cmp (g n) (f a) b
-      return (Acc (n + 1) b')
-{-# INLINE foldrBySTM #-}
-
--- | Given a valid estimator @g@, @'foldl' g f z xs@ yields the same answer as @'foldl'' f z xs@.
---
--- @g n@ should supply an estimate of the value returned from folding over the first @n@ elements of the container.
---
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
--- provide increased opportunities for parallelism.
-
-foldl  :: (Foldable f, Eq b) => (Int -> b) -> (b -> a -> b) -> b -> f a -> b
-foldl = foldlBy (==) 
-{-# INLINE foldl #-}
-
-foldlBy  :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> f a -> b
-foldlBy cmp g f z = extractAcc . Foldable.foldl mf (Acc 0 z)
-  where
-    mf (Acc n a) b = Acc (n + 1) (specBy cmp (g n) (`f` b) a)
-{-# INLINE foldlBy #-}
-
-foldr1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a
-foldr1 = foldr1By (==) 
-{-# INLINE foldr1 #-}
-
-foldr1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a
-foldr1By cmp g f xs = fromMaybeAcc (errorEmptyStructure "foldr1")
-                                   (Foldable.foldr mf NothingAcc xs)
-  where
-    mf a (JustAcc n b) = JustAcc (n + 1) (specBy cmp (g n) (f a) b)
-    mf a NothingAcc = JustAcc 1 a
-{-# INLINE foldr1By #-}
-
-foldl1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a
-foldl1 = foldl1By (==)
-{-# INLINE foldl1 #-}
-
-foldl1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a
-foldl1By cmp g f xs = fromMaybeAcc (errorEmptyStructure "foldl1")
-                               (Foldable.foldl mf NothingAcc xs)
-  where
-    mf (JustAcc n a) b = JustAcc (n + 1) (specBy cmp (g n) (`f` b) a)
-    mf NothingAcc b    = JustAcc 1 b
-{-# INLINE foldl1By #-}
-
--- | Map each element of a structure to an action, evaluate these actions
--- from left to right and ignore the results.
-traverse_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f c) -> (a -> f b) -> t a -> f ()
-traverse_ = traverseBy_ (==)
-{-# INLINE traverse_ #-}
-
-traverseBy_ :: (Foldable t, Applicative f) => (f () -> f () -> Bool) -> (Int -> f c) -> (a -> f b) -> t a -> f ()
-traverseBy_ cmp g f = foldrBy cmp ((() <$) . g) ((*>) . f) (pure ())
-{-# INLINE traverseBy_ #-}
-
--- | 'for_' is 'traverse_' with its arguments flipped.
-for_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f c) -> t a -> (a -> f b) -> f ()
-for_ g = flip (traverse_ g)
-{-# INLINE for_ #-}
-
-forBy_ :: (Foldable t, Applicative f) => (f () -> f () -> Bool) -> (Int -> f c) -> t a -> (a -> f b) -> f ()
-forBy_ cmp g = flip (traverseBy_ cmp g)
-{-# INLINE forBy_ #-}
-
--- | Map each element of the structure to a monadic action, evaluating these actions
--- from left to right and ignoring the results.
-mapM_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m c) -> (a -> m b) -> t a -> m ()
-mapM_ = mapByM_ (==)
-{-# INLINE mapM_ #-}
-
--- | Map each element of the structure to a monadic action, evaluating these actions
--- from left to right and ignoring the results, while transactional side-effects from 
--- mis-speculated actions are rolled back.
-mapSTM_ :: Foldable t => STM Bool -> (Int -> STM c) -> (a -> STM b) -> t a -> STM ()
-mapSTM_ chk g f = foldrBySTM (\_ _ -> chk) (\n -> () <$ g n) (\a _ -> () <$ f a) (return ())
-{-# INLINE mapSTM_ #-}
-
-mapByM_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m c) -> (a -> m b) -> t a -> m ()
-mapByM_ cmp g f = foldrBy cmp (\n -> g n >> return ()) ((>>) . f) (return ())
-{-# INLINE mapByM_ #-}
-
--- | 'for_' is 'mapM_' with its arguments flipped.
-forM_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m c) -> t a -> (a -> m b) -> m ()
-forM_ g = flip (mapM_ g)
-{-# INLINE forM_ #-}
-
--- | 'for_' is 'mapM_' with its arguments flipped.
-forSTM_ :: Foldable t => STM Bool -> (Int -> STM c) -> t a -> (a -> STM b) -> STM ()
-forSTM_ chk g = flip (mapSTM_ chk g)
-{-# INLINE forSTM_ #-}
-
-forByM_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m c) -> t a -> (a -> m b) -> m ()
-forByM_ cmp g = flip (mapByM_ cmp g)
-{-# INLINE forByM_ #-}
-
-sequenceA_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f b) -> t (f a) -> f ()
-sequenceA_ = sequenceByA_ (==)
-{-# INLINE sequenceA_ #-}
-
-sequenceByA_ :: (Foldable t, Applicative f, Eq (f ())) => (f () -> f () -> Bool) -> (Int -> f b) -> t (f a) -> f ()
-sequenceByA_ cmp g = foldrBy cmp ((()<$) . g) (*>) (pure ())
-{-# INLINE sequenceByA_ #-}
-
-sequence_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m b) -> t (m a) -> m ()
-sequence_ = sequenceBy_ (==) 
-{-# INLINE sequence_ #-}
-
-sequenceSTM_:: Foldable t => STM Bool -> (Int -> STM a) -> t (STM b) -> STM ()
-sequenceSTM_ chk g = foldrBySTM (\_ _ -> chk) (\n -> () <$ g n) (\a _ -> () <$ a) (return ())
-{-# INLINE sequenceSTM_ #-}
-
-sequenceBy_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m b) -> t (m a) -> m ()
-sequenceBy_ cmp g = foldrBy cmp (\n -> g n >> return ()) (>>) (return ())
-{-# INLINE sequenceBy_ #-}
-
-asum :: (Foldable t, Alternative f, Eq (f a)) => (Int -> f a) -> t (f a) -> f a
-asum = asumBy (==)
-{-# INLINE asum #-}
-
-asumBy :: (Foldable t, Alternative f) => (f a -> f a -> Bool) -> (Int -> f a) -> t (f a) -> f a
-asumBy cmp g = foldrBy cmp g (<|>) empty
-{-# INLINE asumBy #-}
-
-msum  :: (Foldable t, MonadPlus m, Eq (m a)) => (Int -> m a) -> t (m a) -> m a
-msum = msumBy (==) 
-{-# INLINE msum #-}
-
-msumBy  :: (Foldable t, MonadPlus m) => (m a -> m a -> Bool) -> (Int -> m a) -> t (m a) -> m a
-msumBy cmp g = foldrBy cmp g mplus mzero 
-{-# INLINE msumBy #-}
-
-toList :: (Foldable t, Eq a) => (Int -> [a]) -> t a -> [a]
-toList = toListBy (==)
-{-# INLINE toList #-}
-
-toListBy :: Foldable t => ([a] -> [a] -> Bool) -> (Int -> [a]) -> t a -> [a]
-toListBy cmp g = foldrBy cmp g (:) []
-{-# INLINE toListBy #-}
-
-concat :: (Foldable t, Eq a) => (Int -> [a]) -> t [a] -> [a]
-concat = fold
-{-# INLINE concat #-}
-
-concatBy :: Foldable t => ([a] -> [a] -> Bool) -> (Int -> [a]) -> t [a] -> [a]
-concatBy = foldBy
-{-# INLINE concatBy #-}
-
-concatMap :: (Foldable t, Eq b) => (Int -> [b]) -> (a -> [b]) -> t a -> [b]
-concatMap = foldMap
-{-# INLINE concatMap #-}
-
-concatMapBy :: (Foldable t) => ([b] -> [b] -> Bool) -> (Int -> [b]) -> (a -> [b]) -> t a -> [b]
-concatMapBy = foldMapBy
-{-# INLINE concatMapBy #-}
-
-and :: Foldable t => (Int -> Bool) -> t Bool -> Bool
-and g = getAll . foldMap (All . g) All
-{-# INLINE and #-}
-
-or :: Foldable t => (Int -> Bool) -> t Bool -> Bool
-or g = getAny . foldMap (Any . g) Any
-{-# INLINE or #-}
-
-all :: Foldable t => (Int -> Bool) -> (a -> Bool) -> t a -> Bool
-all g p = getAll . foldMap (All . g) (All . p)
-{-# INLINE all #-}
-
-any :: Foldable t => (Int -> Bool) -> (a -> Bool) -> t a -> Bool
-any g p = getAny . foldMap (Any . g) (Any . p)
-{-# INLINE any #-}
-
-sum :: (Foldable t, Eq a, Num a) => (Int -> a) -> t a -> a
-sum = sumBy (==)
-{-# INLINE sum #-}
-
-sumBy :: (Foldable t, Num a) => (a -> a -> Bool) -> (Int -> a) -> t a -> a
-sumBy cmp g = getSum . foldMapBy (on cmp getSum) (Sum . g) Sum
-{-# INLINE sumBy #-}
-
-product :: (Foldable t, Eq a, Num a) => (Int -> a) -> t a -> a
-product = productBy (==)
-{-# INLINE product #-}
-
-productBy :: (Foldable t, Num a) => (a -> a -> Bool) -> (Int -> a) -> t a -> a
-productBy cmp g = getProduct . foldMapBy (on cmp getProduct) (Product . g) Product
-{-# INLINE productBy #-}
-
-maximum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a
-maximum g = foldr1 g max
-{-# INLINE maximum #-}
-
--- TODO: allow for patching?
-maximumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
-maximumBy cmp g = foldr1By cmp' g max'
-  where 
-    max' x y = case cmp x y of 
-        GT -> x 
-        _  -> y
-    cmp' x y = cmp x y == EQ
-{-# INLINE maximumBy #-}
-        
-minimum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a
-minimum g = foldr1 g min
-{-# INLINE minimum #-}
-
-minimumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
-minimumBy cmp g = foldr1By cmp' g min'
-  where 
-    min' x y = case cmp x y of 
-        GT -> x 
-        _  -> y
-    cmp' x y = cmp x y == EQ
-{-# INLINE minimumBy #-}
-        
-elem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool
-elem g = any g . (==)
-{-# INLINE elem #-}
-
-elemBy :: Foldable t => (a -> a -> Bool) -> (Int -> Bool) -> a -> t a -> Bool
-elemBy cmp g = any g . cmp
-{-# INLINE elemBy #-}
-
-notElem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool
-notElem g a = not . elem g a
-{-# INLINE notElem #-}
-
-notElemBy :: Foldable t => (a -> a -> Bool) -> (Int -> Bool) -> a -> t a -> Bool
-notElemBy cmp g a = not . elemBy cmp g a
-{-# INLINE notElemBy #-}
-
-find :: (Foldable t, Eq a) => (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a
-find = findBy (==) 
-
-findBy :: Foldable t => (Maybe a -> Maybe a -> Bool) -> (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a 
-findBy cmp g p = getFirst . foldMapBy (on cmp getFirst) (First . g) (\x -> if p x then First (Just x) else First (Nothing))
-
diff --git a/Control/Concurrent/Speculation/Internal.hs b/Control/Concurrent/Speculation/Internal.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation/Internal.hs
+++ /dev/null
@@ -1,64 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Concurrent.Speculation.Internal
--- Copyright   :  (C) 2010-2011 Edward Kmett
--- License     :  BSD-style (see the file LICENSE)
---
--- Maintainer  :  Edward Kmett <ekmett@gmail.com>
--- Stability   :  provisional
--- Portability :  portable
---
-----------------------------------------------------------------------------
-module Control.Concurrent.Speculation.Internal
-    ( Acc(..)
-    , extractAcc
-    , MaybeAcc(..)
-    , fromMaybeAcc
-    , errorEmptyStructure
-    , returning
-    ) where
-
-import Data.Foldable
-import Data.Traversable
-import Control.Applicative
-
--- comonad!
-data Acc a = Acc {-# UNPACK #-} !Int a
-
-instance Functor Acc where
-    fmap f (Acc n a) = Acc n (f a)
-
-instance Foldable Acc where
-    foldMap = foldMapDefault
-
-instance Traversable Acc where
-    traverse f (Acc n a) = Acc n <$> f a
-
-extractAcc :: Acc a -> a
-extractAcc (Acc _ a) = a
-{-# INLINE extractAcc #-}
-
-data MaybeAcc a = JustAcc {-# UNPACK #-} !Int a | NothingAcc
-
-instance Functor MaybeAcc where
-    fmap f (JustAcc n a) = JustAcc n (f a)
-    fmap _ NothingAcc = NothingAcc
-
-instance Foldable MaybeAcc where
-    foldMap = foldMapDefault
-
-instance Traversable MaybeAcc where
-    traverse f (JustAcc n a) = JustAcc n <$> f a
-    traverse _ NothingAcc    = pure NothingAcc
-
-fromMaybeAcc :: a -> MaybeAcc a -> a
-fromMaybeAcc _ (JustAcc _ a) = a
-fromMaybeAcc a _ = a
-{-# INLINE fromMaybeAcc #-}
-
-errorEmptyStructure :: String -> a
-errorEmptyStructure f = error $ f ++ ": error empty structure"
-
-returning :: Monad m => (a -> b -> c) -> a -> b -> m c
-returning f a b = return (f a b)
-{-# INLINE returning #-}
diff --git a/Control/Concurrent/Speculation/List.hs b/Control/Concurrent/Speculation/List.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation/List.hs
+++ /dev/null
@@ -1,127 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Concurrent.Speculation.List
--- Copyright   :  (C) 2010-2011 Edward Kmett,
--- License     :  BSD-style (see the file LICENSE)
---
--- Maintainer  :  Edward Kmett <ekmett@gmail.com>
--- Stability   :  provisional
--- Portability :  portable
---
-----------------------------------------------------------------------------
-module Control.Concurrent.Speculation.List
-    (
-    -- * Speculative scans
-      scan, scanBy
-    , scanMap, scanMapBy
-    , scanr, scanrBy
-    , scanl, scanlBy
-    , scanr1, scanr1By
-    , scanl1, scanl1By
-    {-
-    -- ** Speculative monadic scans
-    , scanrM, scanrByM
-    , scanlM, scanlByM
-    -- * Speculative transactional monadic scans
-    , scanrSTM, scanrBySTM
-    , scanlSTM, scanlBySTM
-    -}
-    ) where
-
-
-import Prelude hiding
-    (foldl, foldl1, foldr, foldr1
-    , any, all, and, or, mapM_, sequence_
-    , elem, notElem, sum, product
-    , minimum, maximum, concat, concatMap
-    , scanr, scanl, scanr1, scanl1
-    )
-
-import Data.Monoid
-import qualified Data.List as List
-import Control.Concurrent.Speculation
-import Control.Concurrent.Speculation.Internal
-
--- | Given a valid estimator @g@, @'scan' g xs@ converts @xs@ into a list of the prefix sums.
---
--- @g n@ should supply an estimate of the value of the monoidal summation over the first @n@ elements of the container.
---
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the prefix sum, then this can
--- provide increased opportunities for parallelism.
-
-scan :: (Monoid m, Eq m) => (Int -> m) -> [m] -> [m]
-scan = scanBy (==)
-{-# INLINE scan #-}
-
--- | 'scan' using 'specBy'
-scanBy :: Monoid m => (m -> m -> Bool) -> (Int -> m) -> [m] -> [m]
-scanBy cmp g = scanrBy cmp g mappend mempty
-{-# INLINE scanBy #-}
-
--- | Given a valid estimator @g@, @'scanMap' g f xs@ converts @xs@ into a list of the prefix sums.
---
--- @g n@ should supply an estimate of the value of the monoidal summation over the first @n@ elements of the container.
---
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the scan, then this can
--- provide increased opportunities for parallelism.
---
--- > scan = scanMap id
--- > scanMap = scanMapBy (==)
-
-scanMap :: (Monoid m, Eq m) => (Int -> m) -> (a -> m) -> [a] -> [m]
-scanMap = scanMapBy (==)
-{-# INLINE scanMap #-}
-
-scanMapBy :: Monoid m => (m -> m -> Bool) -> (Int -> m) -> (a -> m) -> [a] -> [m]
-scanMapBy cmp g f = scanrBy cmp g (mappend . f) mempty
-{-# INLINE scanMapBy #-}
-
--- | Given a valid estimator @g@, @'scanr' g f z xs@ yields the same answer as @'scanr'' f z xs@.
---
--- @g n@ should supply an estimate of the value returned from scanning over the last @n@ elements of the container.
---
--- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the scan, then this can
--- provide increased opportunities for parallelism.
-
-scanr :: Eq b => (Int -> b) -> (a -> b -> b) -> b -> [a] -> [b]
-scanr = scanrBy (==)
-{-# INLINE scanr #-}
-
-scanrBy :: (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> [a] -> [b]
-scanrBy cmp g f z = map extractAcc . List.scanr mf (Acc 0 z)
-  where
-    mf a (Acc n b) = let n' = n + 1 in Acc n' (specBy cmp (g n') (f a) b)
-{-# INLINE scanrBy #-}
-
-
-scanl  :: Eq b => (Int -> b) -> (b -> a -> b) -> b -> [a] -> [b]
-scanl = scanlBy (==)
-{-# INLINE scanl #-}
-
-scanlBy  :: (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> [a] -> [b]
-scanlBy cmp g f z = map extractAcc . List.scanl mf (Acc 0 z)
-  where
-    mf (Acc n a) b = let n' = n + 1 in Acc n' (specBy cmp (g n') (`f` b) a)
-{-# INLINE scanlBy #-}
-
-scanr1 :: Eq a => (Int -> a) -> (a -> a -> a) -> [a] -> [a]
-scanr1 = scanr1By (==)
-{-# INLINE scanr1 #-}
-
-scanr1By :: (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> [a] -> [a]
-scanr1By cmp g f xs = map (fromMaybeAcc undefined) $ List.scanr mf NothingAcc xs
-  where
-    mf a (JustAcc n b) = let n' = n + 1 in JustAcc n' (specBy cmp (g n') (f a) b)
-    mf a NothingAcc = JustAcc 1 a
-{-# INLINE scanr1By #-}
-
-scanl1 :: Eq a => (Int -> a) -> (a -> a -> a) -> [a] -> [a]
-scanl1 = scanl1By (==)
-{-# INLINE scanl1 #-}
-
-scanl1By :: (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> [a] -> [a]
-scanl1By cmp g f xs = map (fromMaybeAcc undefined) $ List.scanl mf NothingAcc xs
-  where
-    mf (JustAcc n a) b = let n' = n + 1 in JustAcc n' (specBy cmp (g n') (`f` b) a)
-    mf NothingAcc b    = JustAcc 1 b
-{-# INLINE scanl1By #-}
diff --git a/Control/Concurrent/Speculation/Traversable.hs b/Control/Concurrent/Speculation/Traversable.hs
deleted file mode 100644
--- a/Control/Concurrent/Speculation/Traversable.hs
+++ /dev/null
@@ -1,209 +0,0 @@
-{-# LANGUAGE MagicHash, Rank2Types, UnboxedTuples, BangPatterns #-}
-{-# LANGUAGE CPP #-}
-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
-{-# LANGUAGE Trustworthy #-}
-#endif
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Concurrent.Speculation.Traversable
--- Copyright   :  (C) 2010-2011 Edward Kmett,
--- License     :  BSD-style (see the file LICENSE)
---
--- Maintainer  :  Edward Kmett <ekmett@gmail.com>
--- Stability   :  provisional
--- Portability :  non-portable (UnboxedTuples, Rank2Types)
---
-----------------------------------------------------------------------------
-module Control.Concurrent.Speculation.Traversable
-    (
-    -- * Traversable
-    -- ** Applicative Traversals
-      traverse, traverseBy
-    , for, forBy
-    , sequenceA, sequenceByA
-    -- ** Monadic traversals
-    , mapM, mapByM
-    , sequence, sequenceBy
-    , forM, forByM
-    -- ** STM-based traversals with transactional rollback
-    , mapSTM, mapBySTM
-    , forSTM, forBySTM
-    -- * Accumulating parameters
-    , mapAccumL, mapAccumLBy
-    , mapAccumR, mapAccumRBy
-    ) where
-
-import Prelude hiding (mapM, sequence)
-import GHC.Prim
-import GHC.Types
-import Data.Traversable (Traversable)
-import qualified Data.Traversable as Traversable
-import Control.Applicative
-import Control.Concurrent.STM
-import Control.Concurrent.Speculation
-import Control.Concurrent.Speculation.Internal
-
-mapAccumL :: (Traversable t, Eq a) => (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
-mapAccumL = mapAccumLBy (==)
-{-# INLINE mapAccumL #-}
-
-mapAccumLBy :: Traversable t => (a -> a -> Bool) -> (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
-mapAccumLBy cmp g f z xs = runIntAccumL (Traversable.traverse go xs) 0 z
-  where
-    go b = IntAccumL (\n a ->
-            let ~(a', c) = specBy cmp (g (I# n)) (`f` b) a
-            in (# n +# 1#, a', c #))
-{-# INLINE mapAccumLBy #-}
-
-mapAccumR :: (Traversable t, Eq a) => (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
-mapAccumR = mapAccumRBy (==)
-{-# INLINE mapAccumR #-}
-
-mapAccumRBy :: Traversable t => (a -> a -> Bool) -> (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
-mapAccumRBy cmp g f z xs = runIntAccumR (Traversable.traverse go xs) 0 z
-  where
-    go b = IntAccumR (\n a ->
-            let ~(a', c) = specBy cmp (g (I# n)) (`f` b) a
-            in (# n +# 1#, a', c #))
-{-# INLINE mapAccumRBy #-}
-
-traverse  :: (Traversable t, Applicative f, Eq a) => (Int -> a) -> (a -> f b) -> t a -> f (t b)
-traverse = traverseBy (==)
-{-# INLINE traverse #-}
-
-traverseBy :: (Traversable t, Applicative f) => (a -> a -> Bool) -> (Int -> a) -> (a -> f b) -> t a -> f (t b)
-traverseBy cmp g f xs = runAccT (Traversable.traverse go xs) 0
-  where
-    -- go :: a -> AccT f a
-    go a = AccT $ \i -> acc (i +# 1#) $ specBy cmp (g (I# i)) f a
-{-# INLINE traverseBy #-}
-
-mapM :: (Traversable t, Monad m, Eq a) => (Int -> a) -> (a -> m b) -> t a -> m (t b)
-mapM = mapByM (==)
-{-# INLINE mapM #-}
-
-mapByM :: (Traversable t, Monad m) => (a -> a -> Bool) -> (Int -> a) -> (a -> m b) -> t a -> m (t b)
-mapByM cmp g f = unwrapMonad . traverseBy cmp g (WrapMonad . f)
-{-# INLINE mapByM #-}
-
-mapSTM :: (Traversable t, Eq a) => (Int -> STM a) -> (a -> STM b) -> t a -> STM (t b)
-mapSTM = mapBySTM (returning (==))
-{-# INLINE mapSTM #-}
-
-mapBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> (a -> STM b) -> t a -> STM (t b)
-mapBySTM cmp g f xs = unwrapMonad (runAccT (Traversable.traverse go xs) 0)
-  where
-    go a = AccT $ \i -> acc (i +# 1#) $ WrapMonad $ specBySTM cmp (g (I# i)) f a
-{-# INLINE mapBySTM #-}
-
-
-sequenceA :: (Traversable t, Applicative f, Eq (f a)) => (Int -> f a) -> t (f a) -> f (t a)
-sequenceA g = traverse g id
-{-# INLINE sequenceA #-}
-
-sequenceByA :: (Traversable t, Applicative f) => (f a -> f a -> Bool) -> (Int -> f a) -> t (f a) -> f (t a)
-sequenceByA cmp g = traverseBy cmp g id
-{-# INLINE sequenceByA #-}
-
-sequence   :: (Traversable t, Monad m, Eq (m a)) => (Int -> m a) -> t (m a) -> m (t a)
-sequence g = mapM g id
-{-# INLINE sequence #-}
-
-sequenceBy :: (Traversable t, Monad m) => (m a -> m a -> Bool) -> (Int -> m a) -> t (m a) -> m (t a)
-sequenceBy cmp g = mapByM cmp g id
-{-# INLINE sequenceBy #-}
-
-{-
-sequenceSTM   :: (Traversable t, Eq a) => (Int -> STM a) -> t (STM a) -> STM (t a)
-sequenceSTM g = mapSTM g id
-{-# INLINE sequenceSTM #-}
-
-sequenceBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> t (STM a) -> STM (t a)
-sequenceBySTM cmp g = mapBySTM cmp g id
-{-# INLINE sequenceBySTM #-}
--}
-
-for :: (Traversable t, Applicative f, Eq a) => (Int -> a) -> t a -> (a -> f b) -> f (t b)
-for g = flip (traverse g)
-{-# INLINE for #-}
-
-forBy :: (Traversable t, Applicative f) => (a -> a -> Bool) -> (Int -> a) -> t a -> (a -> f b) -> f (t b)
-forBy cmp g = flip (traverseBy cmp g)
-{-# INLINE forBy #-}
-
-forM :: (Traversable t, Monad m, Eq a) => (Int -> a) -> t a -> (a -> m b) -> m (t b)
-forM g = flip (mapM g)
-{-# INLINE forM #-}
-
-forByM :: (Traversable t, Monad m) => (a -> a -> Bool) -> (Int -> a) -> t a -> (a -> m b) -> m (t b)
-forByM cmp g = flip (mapByM cmp g)
-{-# INLINE forByM #-}
-
-forSTM :: (Traversable t, Eq a) => (Int -> STM a) -> t a -> (a -> STM b) -> STM (t b)
-forSTM g = flip (mapSTM g)
-{-# INLINE forSTM #-}
-
-forBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> t a -> (a -> STM b) -> STM (t b)
-forBySTM cmp g = flip (mapBySTM cmp g)
-{-# INLINE forBySTM #-}
-
--- Utilities
-
-acc :: Int# -> a -> Acc a
-acc i a = Acc (I# i) a
-{-# INLINE acc #-}
-
-data IntAccumL s a = IntAccumL (Int# -> s -> (# Int#, s, a #))
-
-runIntAccumL :: IntAccumL s a -> Int -> s -> (s, a)
-runIntAccumL (IntAccumL m) (I# i) s = case m i s of
-    (# _, s1, a #) -> (s1, a)
-{-# INLINE runIntAccumL #-}
-
-instance Functor (IntAccumL s) where
-    fmap f (IntAccumL m) = IntAccumL  (\i s -> case m i s of
-        (# i1, s1, a #) -> (# i1, s1, f a #))
-
-instance Applicative (IntAccumL s) where
-    pure a = IntAccumL (\i s -> (# i, s, a #))
-    IntAccumL mf <*> IntAccumL ma = IntAccumL (\i s ->
-        case mf i s of
-            (# i1, s1, f #) ->
-                case ma i1 s1 of
-                    (# i2, s2, a #) -> (# i2, s2, f a #))
-
-data IntAccumR s a = IntAccumR (Int# -> s -> (# Int#, s, a #))
-
-runIntAccumR :: IntAccumR s a -> Int -> s -> (s, a)
-runIntAccumR (IntAccumR m) (I# i) s = case m i s of
-    (# _, s1, a #) -> (s1, a)
-{-# INLINE runIntAccumR #-}
-
-instance Functor (IntAccumR s) where
-    fmap f (IntAccumR m) = IntAccumR  (\i s -> case m i s of
-        (# i1, s1, a #) -> (# i1, s1, f a #))
-
-instance Applicative (IntAccumR s) where
-    pure a = IntAccumR (\i s -> (# i, s, a #))
-    IntAccumR mf <*> IntAccumR ma = IntAccumR (\i s ->
-        case ma i s of
-            (# i1, s1, a #) ->
-                case mf i1 s1 of
-                    (# i2, s2, f #) -> (# i2, s2, f a #))
-
--- applicative composition with a strict integer state applicative
-newtype AccT m a = AccT (Int# -> Acc (m a))
-
-runAccT :: Applicative m => AccT m a -> Int -> m a
-runAccT (AccT m) (I# i) = extractAcc (m i)
-{-# INLINE runAccT #-}
-
-instance Functor f => Functor (AccT f) where
-    fmap f (AccT m) = AccT (\i# -> case m i# of Acc i a -> Acc i (fmap f a))
-
-instance Applicative f => Applicative (AccT f) where
-    pure a = AccT (\i -> Acc (I# i) (pure a))
-    AccT mf <*> AccT ma = AccT (\i0# ->
-        let !(Acc !(I# i1#) f) = mf i0#
-            !(Acc i2 a) = ma i1#
-        in  Acc i2 (f <*> a))
diff --git a/HLint.hs b/HLint.hs
new file mode 100644
--- /dev/null
+++ b/HLint.hs
@@ -0,0 +1,1 @@
+ignore "Use void"
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2010-2013, Edward Kmett
+Copyright (c) 2010-2015, Edward Kmett
 
 All rights reserved.
 
diff --git a/speculation.cabal b/speculation.cabal
--- a/speculation.cabal
+++ b/speculation.cabal
@@ -1,5 +1,5 @@
 name:           speculation
-version:        1.5.0.1
+version:        1.5.0.2
 license:        BSD3
 license-file:   LICENSE
 author:         Edward A. Kmett
@@ -8,10 +8,10 @@
 homepage:       http://github.com/ekmett/speculation
 bug-reports:    http://github.com/ekmett/speculation/issues
 category:       Concurrency
-copyright:      (c) 2010-2013 Edward A. Kmett
-build-type:     Custom
+copyright:      (c) 2010-2015 Edward A. Kmett
+build-type:     Simple
 cabal-version:  >=1.6
-tested-with:    GHC==6.12.1, GHC==7.3.20111017, GHC==7.4.1, GHC==7.6.3, GHC==7.7
+tested-with:    GHC==6.12.1, GHC==7.3.20111017, GHC==7.4.2, GHC==7.6.3, GHC==7.7, GHC==7.8.4, GHC==7.10.0.20150307
 synopsis:       A framework for safe, programmable, speculative parallelism
 description:
  A framework for safe, programmable, speculative parallelism, loosely based on:
@@ -65,7 +65,7 @@
  .
  'specSTM' provides a similar time table for STM actions, but also rolls back side-effects. The one unfortunate operational distinction is that it is forced to compute 'a' in the background thread and therefore degrades slightly less gracefully under load, although we mitigate this effect by only enqueuing if the number of sparks for the current capability is lower than the total number of capabilities, to try to avoid wasting time when all computational resources are in use.
 
-extra-source-files: README.markdown CHANGELOG.markdown ISSUES.markdown .travis.yml
+extra-source-files: README.markdown CHANGELOG.markdown ISSUES.markdown .travis.yml HLint.hs
 
 source-repository head
   type:     git
@@ -78,6 +78,7 @@
 
 library
   ghc-options: -Wall
+  hs-source-dirs: src
   if flag(optimize)
     ghc-options: -funbox-strict-fields -O2 -fspec-constr -fdicts-cheap
 
@@ -85,7 +86,7 @@
 
   build-depends:
     ghc-prim,
-    transformers >= 0.2.2.0 && < 0.4,
+    transformers >= 0.2.2.0 && < 0.5,
     stm          >= 2.1 && < 2.5
 
   exposed-modules:
diff --git a/src/Control/Concurrent/Speculation.hs b/src/Control/Concurrent/Speculation.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation.hs
@@ -0,0 +1,160 @@
+{-# LANGUAGE CPP #-}
+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
+{-# LANGUAGE Trustworthy #-}
+#endif
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation
+-- Copyright   :  (C) 2008-2015 Edward Kmett,
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  portable
+--
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation
+    (
+    -- * Speculative application
+      spec
+    , specBy
+    , specOn
+    -- * Speculative application with transactional rollback
+    , specSTM
+    , specOnSTM
+    , specBySTM
+    ) where
+
+import Control.Concurrent.STM
+import Control.Concurrent.Speculation.Internal (returning)
+import Control.Monad (liftM2, unless)
+import Data.Function (on)
+import GHC.Conc
+
+-- * Basic speculation
+
+-- | @'spec' g f a@ evaluates @f g@ while forcing @a@, if @g == a@ then @f g@ is returned, otherwise @f a@ is evaluated and returned. Furthermore, if the argument has already been evaluated or are not running on the threaded runtime, we skip the @f g@ computation entirely. If a good guess at the value of @a@ is available, this is one way to induce parallelism in an otherwise sequential task. However, if the guess isn\'t available more cheaply than the actual answer, then this saves no work and if the guess is wrong, you risk evaluating the function twice. Under high load or in a runtime with access to a single capability, since 'f g' is computed via the spark queue, the speculation will be skipped and you will obtain the same answer as 'f $! a'.
+--
+--The best-case timeline looks like:
+--
+-- > foreground: [----- a -----]
+-- > foreground:               [-]    (check g == a)
+-- > spark:         [----- f g -----]
+-- > overall:    [--- spec g f a ---]
+--
+-- The worst-case timeline looks like:
+--
+-- > foreground: [----- a -----]
+-- > foreground:               [-]               (check g == a)
+-- > foreground:                 [---- f a ----]
+-- > spark:         [----- f g -----]
+-- > overall:    [-------- spec g f a ---------]
+--
+-- Note that, if @f g@ takes longer than a to compute, in the HEAD release of GHC, @f g@ will be collected and killed during garbage collection.
+--
+-- > foreground: [----- a -----]
+-- > foreground:               [-]               (check g == a)
+-- > foreground:                 [---- f a ----]
+-- > spark:         [---- f g ----######         (#'s mark when this spark is collectable)
+-- > overall:    [--------- spec g f a --------]
+-- 
+-- Under high load:
+--
+-- > foreground: [----- a -----]
+-- > foreground:               [-]               (check g == a)
+-- > foreground:                 [---- f a ----]
+-- > overall:    [-------- spec g f a ---------]
+--
+-- Compare these to the timeline of @f $! a@:
+--
+-- > foreground: [----- a -----]
+-- > foreground:               [---- f a ----]
+-- > orverall:   [---------- f $! a ---------]
+
+spec :: Eq a => a -> (a -> b) -> a -> b
+spec = specBy (==)
+{-# INLINE spec #-}
+
+-- | 'spec' with a user defined comparison function
+specBy :: (a -> a -> Bool) -> a -> (a -> b) -> a -> b
+specBy cmp guess f a
+  | numCapabilities == 1 = f $! a
+  | otherwise = speculation `par`
+    if cmp guess a
+    then speculation
+    else f a
+  where speculation = f guess
+{-# INLINE specBy #-}
+
+-- | 'spec' comparing by projection onto another type
+specOn :: Eq c => (a -> c) -> a -> (a -> b) -> a -> b
+specOn = specBy . on (==)
+{-# INLINE specOn #-}
+
+-- * STM-based speculation
+
+-- | @'specSTM' g f a@ evaluates @fg = do g' <- g; f g'@, while forcing @a@, then if @g' == a@ then @fg@ is returned. Otherwise the side-effects of @fg@ are rolled back and @f a@ is evaluated. @g@ is allowed to be a monadic action, so that we can kickstart the computation of @a@ earlier. Under high load, or when we are not using the parallel runtime, the speculation is avoided, to enable this to more closely approximate the runtime profile of spec.
+--
+-- If the argument @a@ is already evaluated, we don\'t bother to perform @f g@ at all.
+--
+-- If a good guess at the value of @a@ is available, this is one way to induce parallelism in an otherwise sequential task.
+--
+-- However, if the guess isn\'t available more cheaply than the actual answer then this saves no work, and if the guess is
+-- wrong, you risk evaluating the function twice.
+--
+-- The best-case timeline looks like:
+--
+-- > foreground: [--- g >>= f ---]
+-- > spark:          [------- a -------]
+-- > foreground:                       [-] (compare g' == a)
+-- > overall:    [---- specSTM g f a ----]
+--
+-- The worst-case timeline looks like:
+--
+-- > foreground: [---- g >>= f ----]
+-- > spark:         [------- a -------]
+-- > foreground:                      [-] (check if g' == a)
+-- > foreground:                        [--] (rollback)
+-- > foreground:                           [------ f a ------]
+-- > overall:    [------------ specSTM g f a ----------------]
+--
+-- Under high load, 'specSTM' degrades less gracefully than 'spec':
+--
+-- > foreground: [---- g >>= f ----]
+-- > spark:                        [------- a -------]
+-- > foreground:                                     [-] (check if g' == a)
+-- > foreground:                                       [--] (rollback)
+-- > foreground:                                          [------ f a ------]
+-- > overall:    [--------------------specSTM g f a ------------------------]
+--
+-- Compare these to the timeline of @f $! a@:
+--
+-- > foreground: [------- a -------]
+-- > foreground:                   [------ f a ------]
+--
+
+specSTM :: Eq a => STM a -> (a -> STM b) -> a -> STM b
+specSTM = specBySTM (returning (==))
+{-# INLINE specSTM #-}
+
+-- | 'specSTM' using a user defined comparison function
+specBySTM :: (a -> a -> STM Bool) -> STM a -> (a -> STM b) -> a -> STM b
+specBySTM cmp mguess f a = do
+  sparks <- unsafeIOToSTM numSparks
+  if sparks < numCapabilities
+    then a `par` do
+      guess <- mguess
+      result <- f guess
+      -- rendezvous with a
+      matching <- cmp guess a
+      unless matching retry
+      return result
+     `orElse`
+      f a
+    else f $! a
+{-# INLINE specBySTM #-}
+
+-- | @'specBySTM' . 'on' (==)@
+specOnSTM :: Eq c => (a -> STM c) -> STM a -> (a -> STM b) -> a -> STM b
+specOnSTM = specBySTM . on (liftM2 (==))
+{-# INLINE specOnSTM #-}
diff --git a/src/Control/Concurrent/Speculation/Class.hs b/src/Control/Concurrent/Speculation/Class.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation/Class.hs
@@ -0,0 +1,40 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation.Class
+-- Copyright   :  (C) 2011-2015 Edward Kmett, Jake McArthur
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  portable
+--
+-- Versions of the combinators from the 'speculation' package
+-- with the signature rearranged to enable them to be used
+-- directly as actions in the 'Cont' and 'ContT' monads
+-- or any other 'Codensity'-shaped monad.
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation.Class where
+
+import Control.Monad.Trans.Cont
+import Control.Concurrent.Speculation
+import Data.Function (on)
+
+class MonadSpec m where
+  -- | @spec@ with a user supplied comparison function
+  specByM :: (a -> a -> Bool) -> a -> a -> m a
+
+-- | When a is unevaluated, @'spec' g a@ evaluates the current continuation 
+-- with @g@ while testing if @g@ '==' @a@, if they differ, it re-evalutes the
+-- continuation with @a@. If @a@ was already evaluated, the continuation is
+-- just directly applied to @a@ instead.
+specM :: (MonadSpec m, Eq a) => a -> a -> m a
+specM = specByM (==)
+
+-- | @spec'@ with a user supplied comparison function
+specOnM :: (MonadSpec m, Eq c) => (a -> c) -> a -> a -> m a
+specOnM = specByM . on (==)
+
+-- * Basic speculation
+
+instance MonadSpec (ContT r m) where
+  specByM f g a = ContT $ \k -> specBy f g k a
diff --git a/src/Control/Concurrent/Speculation/Foldable.hs b/src/Control/Concurrent/Speculation/Foldable.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation/Foldable.hs
@@ -0,0 +1,433 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE BangPatterns #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation.Foldable
+-- Copyright   :  (C) 2010-2015 Edward Kmett
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  portable
+--
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation.Foldable
+    (
+    -- * Speculative folds
+      fold, foldBy
+    , foldMap, foldMapBy
+    , foldr, foldrBy
+    , foldl, foldlBy
+    , foldr1, foldr1By
+    , foldl1, foldl1By
+    -- ** Speculative monadic folds
+    , foldrM, foldrByM
+    , foldlM, foldlByM
+    -- * Speculative transactional monadic folds
+    , foldrSTM, foldrBySTM
+    , foldlSTM, foldlBySTM
+    -- * Folding actions
+    -- ** Applicative actions
+    , traverse_, traverseBy_
+    , for_, forBy_
+    , sequenceA_, sequenceByA_
+    , asum, asumBy
+    -- ** Monadic actions
+    , mapM_, mapByM_
+    , forM_, forByM_
+    , sequence_, sequenceBy_
+    , msum, msumBy
+    -- ** Speculative transactional monadic actions
+    , mapSTM_, forSTM_, sequenceSTM_
+    -- * Specialized folds
+    , toList, toListBy
+    , concat, concatBy
+    , concatMap, concatMapBy
+    , all, any, and, or
+    , sum, sumBy
+    , product, productBy
+    , maximum, maximumBy
+    , minimum, minimumBy
+    -- * Searches
+    , elem, elemBy
+    , notElem, notElemBy
+    , find, findBy
+    ) where
+
+import Prelude hiding
+    ( foldl, foldl1, foldr, foldr1
+    , any, all, and, or, mapM_, sequence_
+    , elem, notElem, sum, product
+    , minimum, maximum, concat, concatMap
+#if __GLASGOW_HASKELL__ >= 710
+    , foldMap
+#endif
+    )
+
+import Data.Monoid
+import Data.Ix ()
+import Data.Function (on)
+
+#if __GLASGOW_HASKELL__ < 710
+import Data.Foldable (Foldable)
+#endif
+import qualified Data.Foldable as Foldable
+import Control.Concurrent.STM
+import Control.Concurrent.Speculation
+import Control.Concurrent.Speculation.Internal
+import Control.Applicative
+import Control.Monad hiding (mapM_, msum, forM_, sequence_)
+
+-- | Given a valid estimator @g@, @'fold' g f xs@ yields the same answer as @'fold' f xs@.
+--
+-- @g n@ should supply an estimate of the value of the monoidal summation over the last @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
+-- provide increased opportunities for parallelism.
+
+fold :: (Foldable f, Monoid m, Eq m) => (Int -> m) -> f m -> m
+fold = foldBy (==)
+{-# INLINE fold #-}
+
+-- | 'fold' using 'specBy'
+foldBy :: (Foldable f, Monoid m) => (m -> m -> Bool) -> (Int -> m) -> f m -> m
+foldBy cmp g = foldrBy cmp g mappend mempty
+{-# INLINE foldBy #-}
+
+-- | Given a valid estimator @g@, @'foldMap' g f xs@ yields the same answer as @'foldMap' f xs@.
+--
+-- @g n@ should supply an estimate of the value of the monoidal summation over the last @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
+-- provide increased opportunities for parallelism.
+
+foldMap :: (Foldable f, Monoid m, Eq m) => (Int -> m) -> (a -> m) -> f a -> m
+foldMap = foldMapBy (==)
+{-# INLINE foldMap #-}
+
+-- | 'foldMap' using 'specBy'
+foldMapBy :: (Foldable f, Monoid m) => (m -> m -> Bool) -> (Int -> m) -> (a -> m) -> f a -> m
+foldMapBy cmp g f = foldrBy cmp g (mappend . f) mempty
+{-# INLINE foldMapBy #-}
+
+foldr :: (Foldable f, Eq b) => (Int -> b) -> (a -> b -> b) -> b -> f a -> b
+foldr = foldrBy (==)
+{-# INLINE foldr #-}
+
+-- | Given a valid estimator @g@, @'foldr' g f z xs@ yields the same answer as @'foldr'' f z xs@.
+--
+-- @g n@ should supply an estimate of the value returned from folding over the last @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
+-- provide increased opportunities for parallelism.
+foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> f a -> b
+foldrBy cmp g f z = extractAcc . Foldable.foldr mf (Acc 0 z)
+  where
+    mf a (Acc n b) = Acc (n + 1) (specBy cmp (g n) (f a) b)
+{-# INLINE foldrBy #-}
+
+
+{-
+-- Variations:
+-- These variations are not used because the values ot the left shouldn't affect the intermediate state of a right fold.
+--
+-- this version receiveds both the number of values remaining and the number so far
+
+foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> Int -> b) -> (a -> b -> b) -> b -> f a -> b
+foldrBy cmp g f z xs = Foldable.foldr mf (Acc 0 (const z)) xs 0
+  where
+    mf a (Acc r b) !l = let l' = l + 1 in Acc (r + 1) (specBy cmp (g l') (f a) (b l'))
+{-# INLINE foldrBy #-}
+
+-- this estimator receives the number of values to the left of the summation.
+foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> f a -> b
+foldrBy cmp g f z xs = Foldable.foldr mf (const z) xs 0
+  where
+    mf a b !i = let i' = i + 1 in specBy cmp (g i') (f a) (b i')
+{-# INLINE foldrBy #-}
+-}
+
+foldlM :: (Foldable f, Monad m, Eq (m b)) => (Int -> m b) -> (b -> a -> m b) -> m b -> f a -> m b
+foldlM = foldlByM (==)
+{-# INLINE foldlM #-}
+
+foldlByM ::  (Foldable f, Monad m) => (m b -> m b -> Bool) -> (Int -> m b) -> (b -> a -> m b) -> m b -> f a -> m b
+foldlByM  cmp g f mz = liftM extractAcc . Foldable.foldl go (liftM (Acc 0) mz)
+  where
+    go mia b = do
+      Acc n a <- mia
+      a' <- specBy cmp (g n) (>>= (`f` b)) (return a)
+      return (Acc (n + 1) a')
+{-# INLINE foldlByM #-}
+
+foldrM :: (Foldable f, Monad m, Eq (m b)) => (Int -> m b) -> (a -> b -> m b) -> m b -> f a -> m b
+foldrM = foldrByM (==)
+{-# INLINE foldrM #-}
+
+foldrByM :: (Foldable f, Monad m) => (m b -> m b -> Bool) -> (Int -> m b) -> (a -> b -> m b) -> m b -> f a -> m b
+foldrByM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz)
+  where
+    go a mib = do
+      Acc n b <- mib
+      b' <- specBy cmp (g n) (>>= f a) (return b)
+      return (Acc (n + 1) b')
+{-# INLINE foldrByM #-}
+
+foldlSTM :: (Foldable f, Eq a) => (Int -> STM a) -> (a -> b -> STM a) -> STM a -> f b -> STM a
+foldlSTM = foldlBySTM (returning (==))
+{-# INLINE foldlSTM #-}
+
+foldlBySTM :: Foldable f => (a -> a -> STM Bool) -> (Int -> STM a) -> (a -> b -> STM a) -> STM a -> f b -> STM a
+foldlBySTM cmp g f mz = liftM extractAcc . Foldable.foldl go (liftM (Acc 0) mz)
+  where
+    go mia b = do
+      Acc n a <- mia
+      a' <- specBySTM cmp (g n) (`f` b) a
+      return (Acc (n + 1) a')
+{-# INLINE foldlBySTM #-}
+
+foldrSTM :: (Foldable f, Eq b) => (Int -> STM b) -> (a -> b -> STM b) -> STM b -> f a -> STM b
+foldrSTM = foldrBySTM (returning (==))
+{-# INLINE foldrSTM #-}
+
+foldrBySTM :: Foldable f => (b -> b -> STM Bool) -> (Int -> STM b) -> (a -> b -> STM b) -> STM b -> f a -> STM b
+foldrBySTM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz)
+  where
+    go a mib = do
+      Acc n b <- mib
+      b' <- specBySTM cmp (g n) (f a) b
+      return (Acc (n + 1) b')
+{-# INLINE foldrBySTM #-}
+
+-- | Given a valid estimator @g@, @'foldl' g f z xs@ yields the same answer as @'foldl'' f z xs@.
+--
+-- @g n@ should supply an estimate of the value returned from folding over the first @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the fold, then this can
+-- provide increased opportunities for parallelism.
+
+foldl  :: (Foldable f, Eq b) => (Int -> b) -> (b -> a -> b) -> b -> f a -> b
+foldl = foldlBy (==)
+{-# INLINE foldl #-}
+
+foldlBy  :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> f a -> b
+foldlBy cmp g f z = extractAcc . Foldable.foldl mf (Acc 0 z)
+  where
+    mf (Acc n a) b = Acc (n + 1) (specBy cmp (g n) (`f` b) a)
+{-# INLINE foldlBy #-}
+
+foldr1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a
+foldr1 = foldr1By (==)
+{-# INLINE foldr1 #-}
+
+foldr1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a
+foldr1By cmp g f xs = fromMaybeAcc (errorEmptyStructure "foldr1")
+                                   (Foldable.foldr mf NothingAcc xs)
+  where
+    mf a (JustAcc n b) = JustAcc (n + 1) (specBy cmp (g n) (f a) b)
+    mf a NothingAcc = JustAcc 1 a
+{-# INLINE foldr1By #-}
+
+foldl1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a
+foldl1 = foldl1By (==)
+{-# INLINE foldl1 #-}
+
+foldl1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a
+foldl1By cmp g f xs = fromMaybeAcc (errorEmptyStructure "foldl1")
+                               (Foldable.foldl mf NothingAcc xs)
+  where
+    mf (JustAcc n a) b = JustAcc (n + 1) (specBy cmp (g n) (`f` b) a)
+    mf NothingAcc b    = JustAcc 1 b
+{-# INLINE foldl1By #-}
+
+-- | Map each element of a structure to an action, evaluate these actions
+-- from left to right and ignore the results.
+traverse_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f c) -> (a -> f b) -> t a -> f ()
+traverse_ = traverseBy_ (==)
+{-# INLINE traverse_ #-}
+
+traverseBy_ :: (Foldable t, Applicative f) => (f () -> f () -> Bool) -> (Int -> f c) -> (a -> f b) -> t a -> f ()
+traverseBy_ cmp g f = foldrBy cmp ((() <$) . g) ((*>) . f) (pure ())
+{-# INLINE traverseBy_ #-}
+
+-- | 'for_' is 'traverse_' with its arguments flipped.
+for_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f c) -> t a -> (a -> f b) -> f ()
+for_ g = flip (traverse_ g)
+{-# INLINE for_ #-}
+
+forBy_ :: (Foldable t, Applicative f) => (f () -> f () -> Bool) -> (Int -> f c) -> t a -> (a -> f b) -> f ()
+forBy_ cmp g = flip (traverseBy_ cmp g)
+{-# INLINE forBy_ #-}
+
+-- | Map each element of the structure to a monadic action, evaluating these actions
+-- from left to right and ignoring the results.
+mapM_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m c) -> (a -> m b) -> t a -> m ()
+mapM_ = mapByM_ (==)
+{-# INLINE mapM_ #-}
+
+-- | Map each element of the structure to a monadic action, evaluating these actions
+-- from left to right and ignoring the results, while transactional side-effects from
+-- mis-speculated actions are rolled back.
+mapSTM_ :: Foldable t => STM Bool -> (Int -> STM c) -> (a -> STM b) -> t a -> STM ()
+mapSTM_ chk g f = foldrBySTM (\_ _ -> chk) (\n -> () <$ g n) (\a _ -> () <$ f a) (return ())
+{-# INLINE mapSTM_ #-}
+
+mapByM_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m c) -> (a -> m b) -> t a -> m ()
+mapByM_ cmp g f = foldrBy cmp (\n -> g n >> return ()) ((>>) . f) (return ())
+{-# INLINE mapByM_ #-}
+
+-- | 'for_' is 'mapM_' with its arguments flipped.
+forM_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m c) -> t a -> (a -> m b) -> m ()
+forM_ g = flip (mapM_ g)
+{-# INLINE forM_ #-}
+
+-- | 'for_' is 'mapM_' with its arguments flipped.
+forSTM_ :: Foldable t => STM Bool -> (Int -> STM c) -> t a -> (a -> STM b) -> STM ()
+forSTM_ chk g = flip (mapSTM_ chk g)
+{-# INLINE forSTM_ #-}
+
+forByM_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m c) -> t a -> (a -> m b) -> m ()
+forByM_ cmp g = flip (mapByM_ cmp g)
+{-# INLINE forByM_ #-}
+
+sequenceA_ :: (Foldable t, Applicative f, Eq (f ())) => (Int -> f b) -> t (f a) -> f ()
+sequenceA_ = sequenceByA_ (==)
+{-# INLINE sequenceA_ #-}
+
+sequenceByA_ :: (Foldable t, Applicative f) => (f () -> f () -> Bool) -> (Int -> f b) -> t (f a) -> f ()
+sequenceByA_ cmp g = foldrBy cmp ((()<$) . g) (*>) (pure ())
+{-# INLINE sequenceByA_ #-}
+
+sequence_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m b) -> t (m a) -> m ()
+sequence_ = sequenceBy_ (==)
+{-# INLINE sequence_ #-}
+
+sequenceSTM_:: Foldable t => STM Bool -> (Int -> STM a) -> t (STM b) -> STM ()
+sequenceSTM_ chk g = foldrBySTM (\_ _ -> chk) (\n -> () <$ g n) (\a _ -> () <$ a) (return ())
+{-# INLINE sequenceSTM_ #-}
+
+sequenceBy_ :: (Foldable t, Monad m) => (m () -> m () -> Bool) -> (Int -> m b) -> t (m a) -> m ()
+sequenceBy_ cmp g = foldrBy cmp (\n -> g n >> return ()) (>>) (return ())
+{-# INLINE sequenceBy_ #-}
+
+asum :: (Foldable t, Alternative f, Eq (f a)) => (Int -> f a) -> t (f a) -> f a
+asum = asumBy (==)
+{-# INLINE asum #-}
+
+asumBy :: (Foldable t, Alternative f) => (f a -> f a -> Bool) -> (Int -> f a) -> t (f a) -> f a
+asumBy cmp g = foldrBy cmp g (<|>) empty
+{-# INLINE asumBy #-}
+
+msum  :: (Foldable t, MonadPlus m, Eq (m a)) => (Int -> m a) -> t (m a) -> m a
+msum = msumBy (==)
+{-# INLINE msum #-}
+
+msumBy  :: (Foldable t, MonadPlus m) => (m a -> m a -> Bool) -> (Int -> m a) -> t (m a) -> m a
+msumBy cmp g = foldrBy cmp g mplus mzero
+{-# INLINE msumBy #-}
+
+toList :: (Foldable t, Eq a) => (Int -> [a]) -> t a -> [a]
+toList = toListBy (==)
+{-# INLINE toList #-}
+
+toListBy :: Foldable t => ([a] -> [a] -> Bool) -> (Int -> [a]) -> t a -> [a]
+toListBy cmp g = foldrBy cmp g (:) []
+{-# INLINE toListBy #-}
+
+concat :: (Foldable t, Eq a) => (Int -> [a]) -> t [a] -> [a]
+concat = fold
+{-# INLINE concat #-}
+
+concatBy :: Foldable t => ([a] -> [a] -> Bool) -> (Int -> [a]) -> t [a] -> [a]
+concatBy = foldBy
+{-# INLINE concatBy #-}
+
+concatMap :: (Foldable t, Eq b) => (Int -> [b]) -> (a -> [b]) -> t a -> [b]
+concatMap = foldMap
+{-# INLINE concatMap #-}
+
+concatMapBy :: (Foldable t) => ([b] -> [b] -> Bool) -> (Int -> [b]) -> (a -> [b]) -> t a -> [b]
+concatMapBy = foldMapBy
+{-# INLINE concatMapBy #-}
+
+and :: Foldable t => (Int -> Bool) -> t Bool -> Bool
+and g = getAll . foldMap (All . g) All
+{-# INLINE and #-}
+
+or :: Foldable t => (Int -> Bool) -> t Bool -> Bool
+or g = getAny . foldMap (Any . g) Any
+{-# INLINE or #-}
+
+all :: Foldable t => (Int -> Bool) -> (a -> Bool) -> t a -> Bool
+all g p = getAll . foldMap (All . g) (All . p)
+{-# INLINE all #-}
+
+any :: Foldable t => (Int -> Bool) -> (a -> Bool) -> t a -> Bool
+any g p = getAny . foldMap (Any . g) (Any . p)
+{-# INLINE any #-}
+
+sum :: (Foldable t, Eq a, Num a) => (Int -> a) -> t a -> a
+sum = sumBy (==)
+{-# INLINE sum #-}
+
+sumBy :: (Foldable t, Num a) => (a -> a -> Bool) -> (Int -> a) -> t a -> a
+sumBy cmp g = getSum . foldMapBy (on cmp getSum) (Sum . g) Sum
+{-# INLINE sumBy #-}
+
+product :: (Foldable t, Eq a, Num a) => (Int -> a) -> t a -> a
+product = productBy (==)
+{-# INLINE product #-}
+
+productBy :: (Foldable t, Num a) => (a -> a -> Bool) -> (Int -> a) -> t a -> a
+productBy cmp g = getProduct . foldMapBy (on cmp getProduct) (Product . g) Product
+{-# INLINE productBy #-}
+
+maximum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a
+maximum g = foldr1 g max
+{-# INLINE maximum #-}
+
+-- TODO: allow for patching?
+maximumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
+maximumBy cmp g = foldr1By cmp' g max'
+  where
+    max' x y = case cmp x y of
+        GT -> x
+        _  -> y
+    cmp' x y = cmp x y == EQ
+{-# INLINE maximumBy #-}
+
+minimum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a
+minimum g = foldr1 g min
+{-# INLINE minimum #-}
+
+minimumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
+minimumBy cmp g = foldr1By cmp' g min'
+  where
+    min' x y = case cmp x y of
+        GT -> x
+        _  -> y
+    cmp' x y = cmp x y == EQ
+{-# INLINE minimumBy #-}
+
+elem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool
+elem g = any g . (==)
+{-# INLINE elem #-}
+
+elemBy :: Foldable t => (a -> a -> Bool) -> (Int -> Bool) -> a -> t a -> Bool
+elemBy cmp g = any g . cmp
+{-# INLINE elemBy #-}
+
+notElem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool
+notElem g a = not . elem g a
+{-# INLINE notElem #-}
+
+notElemBy :: Foldable t => (a -> a -> Bool) -> (Int -> Bool) -> a -> t a -> Bool
+notElemBy cmp g a = not . elemBy cmp g a
+{-# INLINE notElemBy #-}
+
+find :: (Foldable t, Eq a) => (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a
+find = findBy (==)
+
+findBy :: Foldable t => (Maybe a -> Maybe a -> Bool) -> (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a
+findBy cmp g p = getFirst . foldMapBy (on cmp getFirst) (First . g) (\x -> First (if p x then Just x else Nothing))
+
diff --git a/src/Control/Concurrent/Speculation/Internal.hs b/src/Control/Concurrent/Speculation/Internal.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation/Internal.hs
@@ -0,0 +1,67 @@
+{-# LANGUAGE CPP #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation.Internal
+-- Copyright   :  (C) 2010-2015 Edward Kmett
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  portable
+--
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation.Internal
+    ( Acc(..)
+    , extractAcc
+    , MaybeAcc(..)
+    , fromMaybeAcc
+    , errorEmptyStructure
+    , returning
+    ) where
+
+#if __GLASGOW_HASKELL__ < 710
+import Control.Applicative
+import Data.Foldable
+#endif
+import Data.Traversable
+
+-- comonad!
+data Acc a = Acc {-# UNPACK #-} !Int a
+
+instance Functor Acc where
+    fmap f (Acc n a) = Acc n (f a)
+
+instance Foldable Acc where
+    foldMap = foldMapDefault
+
+instance Traversable Acc where
+    traverse f (Acc n a) = Acc n <$> f a
+
+extractAcc :: Acc a -> a
+extractAcc (Acc _ a) = a
+{-# INLINE extractAcc #-}
+
+data MaybeAcc a = JustAcc {-# UNPACK #-} !Int a | NothingAcc
+
+instance Functor MaybeAcc where
+    fmap f (JustAcc n a) = JustAcc n (f a)
+    fmap _ NothingAcc = NothingAcc
+
+instance Foldable MaybeAcc where
+    foldMap = foldMapDefault
+
+instance Traversable MaybeAcc where
+    traverse f (JustAcc n a) = JustAcc n <$> f a
+    traverse _ NothingAcc    = pure NothingAcc
+
+fromMaybeAcc :: a -> MaybeAcc a -> a
+fromMaybeAcc _ (JustAcc _ a) = a
+fromMaybeAcc a _ = a
+{-# INLINE fromMaybeAcc #-}
+
+errorEmptyStructure :: String -> a
+errorEmptyStructure f = error $ f ++ ": error empty structure"
+
+returning :: Monad m => (a -> b -> c) -> a -> b -> m c
+returning f a b = return (f a b)
+{-# INLINE returning #-}
diff --git a/src/Control/Concurrent/Speculation/List.hs b/src/Control/Concurrent/Speculation/List.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation/List.hs
@@ -0,0 +1,130 @@
+{-# LANGUAGE CPP #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation.List
+-- Copyright   :  (C) 2010-2015 Edward Kmett,
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  portable
+--
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation.List
+    (
+    -- * Speculative scans
+      scan, scanBy
+    , scanMap, scanMapBy
+    , scanr, scanrBy
+    , scanl, scanlBy
+    , scanr1, scanr1By
+    , scanl1, scanl1By
+    {-
+    -- ** Speculative monadic scans
+    , scanrM, scanrByM
+    , scanlM, scanlByM
+    -- * Speculative transactional monadic scans
+    , scanrSTM, scanrBySTM
+    , scanlSTM, scanlBySTM
+    -}
+    ) where
+
+
+import Prelude hiding
+    (foldl, foldl1, foldr, foldr1
+    , any, all, and, or, mapM_, sequence_
+    , elem, notElem, sum, product
+    , minimum, maximum, concat, concatMap
+    , scanr, scanl, scanr1, scanl1
+    )
+
+#if __GLASGOW_HASKELL__ < 710
+import Data.Monoid
+#endif
+import qualified Data.List as List
+import Control.Concurrent.Speculation
+import Control.Concurrent.Speculation.Internal
+
+-- | Given a valid estimator @g@, @'scan' g xs@ converts @xs@ into a list of the prefix sums.
+--
+-- @g n@ should supply an estimate of the value of the monoidal summation over the first @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the prefix sum, then this can
+-- provide increased opportunities for parallelism.
+
+scan :: (Monoid m, Eq m) => (Int -> m) -> [m] -> [m]
+scan = scanBy (==)
+{-# INLINE scan #-}
+
+-- | 'scan' using 'specBy'
+scanBy :: Monoid m => (m -> m -> Bool) -> (Int -> m) -> [m] -> [m]
+scanBy cmp g = scanrBy cmp g mappend mempty
+{-# INLINE scanBy #-}
+
+-- | Given a valid estimator @g@, @'scanMap' g f xs@ converts @xs@ into a list of the prefix sums.
+--
+-- @g n@ should supply an estimate of the value of the monoidal summation over the first @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the scan, then this can
+-- provide increased opportunities for parallelism.
+--
+-- > scan = scanMap id
+-- > scanMap = scanMapBy (==)
+
+scanMap :: (Monoid m, Eq m) => (Int -> m) -> (a -> m) -> [a] -> [m]
+scanMap = scanMapBy (==)
+{-# INLINE scanMap #-}
+
+scanMapBy :: Monoid m => (m -> m -> Bool) -> (Int -> m) -> (a -> m) -> [a] -> [m]
+scanMapBy cmp g f = scanrBy cmp g (mappend . f) mempty
+{-# INLINE scanMapBy #-}
+
+-- | Given a valid estimator @g@, @'scanr' g f z xs@ yields the same answer as @'scanr'' f z xs@.
+--
+-- @g n@ should supply an estimate of the value returned from scanning over the last @n@ elements of the container.
+--
+-- If @g n@ is accurate a reasonable percentage of the time and faster to compute than the scan, then this can
+-- provide increased opportunities for parallelism.
+
+scanr :: Eq b => (Int -> b) -> (a -> b -> b) -> b -> [a] -> [b]
+scanr = scanrBy (==)
+{-# INLINE scanr #-}
+
+scanrBy :: (b -> b -> Bool) -> (Int -> b) -> (a -> b -> b) -> b -> [a] -> [b]
+scanrBy cmp g f z = map extractAcc . List.scanr mf (Acc 0 z)
+  where
+    mf a (Acc n b) = let n' = n + 1 in Acc n' (specBy cmp (g n') (f a) b)
+{-# INLINE scanrBy #-}
+
+
+scanl  :: Eq b => (Int -> b) -> (b -> a -> b) -> b -> [a] -> [b]
+scanl = scanlBy (==)
+{-# INLINE scanl #-}
+
+scanlBy  :: (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> [a] -> [b]
+scanlBy cmp g f z = map extractAcc . List.scanl mf (Acc 0 z)
+  where
+    mf (Acc n a) b = let n' = n + 1 in Acc n' (specBy cmp (g n') (`f` b) a)
+{-# INLINE scanlBy #-}
+
+scanr1 :: Eq a => (Int -> a) -> (a -> a -> a) -> [a] -> [a]
+scanr1 = scanr1By (==)
+{-# INLINE scanr1 #-}
+
+scanr1By :: (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> [a] -> [a]
+scanr1By cmp g f xs = map (fromMaybeAcc undefined) $ List.scanr mf NothingAcc xs
+  where
+    mf a (JustAcc n b) = let n' = n + 1 in JustAcc n' (specBy cmp (g n') (f a) b)
+    mf a NothingAcc = JustAcc 1 a
+{-# INLINE scanr1By #-}
+
+scanl1 :: Eq a => (Int -> a) -> (a -> a -> a) -> [a] -> [a]
+scanl1 = scanl1By (==)
+{-# INLINE scanl1 #-}
+
+scanl1By :: (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> [a] -> [a]
+scanl1By cmp g f xs = map (fromMaybeAcc undefined) $ List.scanl mf NothingAcc xs
+  where
+    mf (JustAcc n a) b = let n' = n + 1 in JustAcc n' (specBy cmp (g n') (`f` b) a)
+    mf NothingAcc b    = JustAcc 1 b
+{-# INLINE scanl1By #-}
diff --git a/src/Control/Concurrent/Speculation/Traversable.hs b/src/Control/Concurrent/Speculation/Traversable.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Concurrent/Speculation/Traversable.hs
@@ -0,0 +1,218 @@
+{-# LANGUAGE MagicHash, Rank2Types, UnboxedTuples, BangPatterns #-}
+{-# LANGUAGE CPP #-}
+#if __GLASGOW_HASKELL__ >= 702
+{-# LANGUAGE Trustworthy #-}
+#endif
+-----------------------------------------------------------------------------
+-- |
+-- Module      :  Control.Concurrent.Speculation.Traversable
+-- Copyright   :  (C) 2010-2015 Edward Kmett,
+-- License     :  BSD-style (see the file LICENSE)
+--
+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>
+-- Stability   :  provisional
+-- Portability :  non-portable (UnboxedTuples, Rank2Types)
+--
+----------------------------------------------------------------------------
+module Control.Concurrent.Speculation.Traversable
+    (
+    -- * Traversable
+    -- ** Applicative Traversals
+      traverse, traverseBy
+    , for, forBy
+    , sequenceA, sequenceByA
+    -- ** Monadic traversals
+    , mapM, mapByM
+    , sequence, sequenceBy
+    , forM, forByM
+    -- ** STM-based traversals with transactional rollback
+    , mapSTM, mapBySTM
+    , forSTM, forBySTM
+    -- * Accumulating parameters
+    , mapAccumL, mapAccumLBy
+    , mapAccumR, mapAccumRBy
+    ) where
+
+import Prelude hiding
+  ( mapM
+  , sequence
+#if __GLASGOW_HASKELL__ >= 710
+  , traverse
+  , sequenceA
+#endif
+  )
+import GHC.Prim
+import GHC.Types
+#if __GLASGOW_HASKELL__ < 710
+import Data.Traversable (Traversable)
+#endif
+import qualified Data.Traversable as Traversable
+import Control.Applicative
+import Control.Concurrent.STM
+import Control.Concurrent.Speculation
+import Control.Concurrent.Speculation.Internal
+
+mapAccumL :: (Traversable t, Eq a) => (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
+mapAccumL = mapAccumLBy (==)
+{-# INLINE mapAccumL #-}
+
+mapAccumLBy :: Traversable t => (a -> a -> Bool) -> (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
+mapAccumLBy cmp g f z xs = runIntAccumL (Traversable.traverse go xs) 0 z
+  where
+    go b = IntAccumL (\n a ->
+            let ~(a', c) = specBy cmp (g (I# n)) (`f` b) a
+            in (# n +# 1#, a', c #))
+{-# INLINE mapAccumLBy #-}
+
+mapAccumR :: (Traversable t, Eq a) => (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
+mapAccumR = mapAccumRBy (==)
+{-# INLINE mapAccumR #-}
+
+mapAccumRBy :: Traversable t => (a -> a -> Bool) -> (Int -> a) -> (a -> b -> (a, c)) -> a -> t b -> (a, t c)
+mapAccumRBy cmp g f z xs = runIntAccumR (Traversable.traverse go xs) 0 z
+  where
+    go b = IntAccumR (\n a ->
+            let ~(a', c) = specBy cmp (g (I# n)) (`f` b) a
+            in (# n +# 1#, a', c #))
+{-# INLINE mapAccumRBy #-}
+
+traverse  :: (Traversable t, Applicative f, Eq a) => (Int -> a) -> (a -> f b) -> t a -> f (t b)
+traverse = traverseBy (==)
+{-# INLINE traverse #-}
+
+traverseBy :: (Traversable t, Applicative f) => (a -> a -> Bool) -> (Int -> a) -> (a -> f b) -> t a -> f (t b)
+traverseBy cmp g f xs = runAccT (Traversable.traverse go xs) 0
+  where
+    -- go :: a -> AccT f a
+    go a = AccT $ \i -> acc (i +# 1#) $ specBy cmp (g (I# i)) f a
+{-# INLINE traverseBy #-}
+
+mapM :: (Traversable t, Monad m, Eq a) => (Int -> a) -> (a -> m b) -> t a -> m (t b)
+mapM = mapByM (==)
+{-# INLINE mapM #-}
+
+mapByM :: (Traversable t, Monad m) => (a -> a -> Bool) -> (Int -> a) -> (a -> m b) -> t a -> m (t b)
+mapByM cmp g f = unwrapMonad . traverseBy cmp g (WrapMonad . f)
+{-# INLINE mapByM #-}
+
+mapSTM :: (Traversable t, Eq a) => (Int -> STM a) -> (a -> STM b) -> t a -> STM (t b)
+mapSTM = mapBySTM (returning (==))
+{-# INLINE mapSTM #-}
+
+mapBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> (a -> STM b) -> t a -> STM (t b)
+mapBySTM cmp g f xs = unwrapMonad (runAccT (Traversable.traverse go xs) 0)
+  where
+    go a = AccT $ \i -> acc (i +# 1#) $ WrapMonad $ specBySTM cmp (g (I# i)) f a
+{-# INLINE mapBySTM #-}
+
+
+sequenceA :: (Traversable t, Applicative f, Eq (f a)) => (Int -> f a) -> t (f a) -> f (t a)
+sequenceA g = traverse g id
+{-# INLINE sequenceA #-}
+
+sequenceByA :: (Traversable t, Applicative f) => (f a -> f a -> Bool) -> (Int -> f a) -> t (f a) -> f (t a)
+sequenceByA cmp g = traverseBy cmp g id
+{-# INLINE sequenceByA #-}
+
+sequence   :: (Traversable t, Monad m, Eq (m a)) => (Int -> m a) -> t (m a) -> m (t a)
+sequence g = mapM g id
+{-# INLINE sequence #-}
+
+sequenceBy :: (Traversable t, Monad m) => (m a -> m a -> Bool) -> (Int -> m a) -> t (m a) -> m (t a)
+sequenceBy cmp g = mapByM cmp g id
+{-# INLINE sequenceBy #-}
+
+{-
+sequenceSTM   :: (Traversable t, Eq a) => (Int -> STM a) -> t (STM a) -> STM (t a)
+sequenceSTM g = mapSTM g id
+{-# INLINE sequenceSTM #-}
+
+sequenceBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> t (STM a) -> STM (t a)
+sequenceBySTM cmp g = mapBySTM cmp g id
+{-# INLINE sequenceBySTM #-}
+-}
+
+for :: (Traversable t, Applicative f, Eq a) => (Int -> a) -> t a -> (a -> f b) -> f (t b)
+for g = flip (traverse g)
+{-# INLINE for #-}
+
+forBy :: (Traversable t, Applicative f) => (a -> a -> Bool) -> (Int -> a) -> t a -> (a -> f b) -> f (t b)
+forBy cmp g = flip (traverseBy cmp g)
+{-# INLINE forBy #-}
+
+forM :: (Traversable t, Monad m, Eq a) => (Int -> a) -> t a -> (a -> m b) -> m (t b)
+forM g = flip (mapM g)
+{-# INLINE forM #-}
+
+forByM :: (Traversable t, Monad m) => (a -> a -> Bool) -> (Int -> a) -> t a -> (a -> m b) -> m (t b)
+forByM cmp g = flip (mapByM cmp g)
+{-# INLINE forByM #-}
+
+forSTM :: (Traversable t, Eq a) => (Int -> STM a) -> t a -> (a -> STM b) -> STM (t b)
+forSTM g = flip (mapSTM g)
+{-# INLINE forSTM #-}
+
+forBySTM :: Traversable t => (a -> a -> STM Bool) -> (Int -> STM a) -> t a -> (a -> STM b) -> STM (t b)
+forBySTM cmp g = flip (mapBySTM cmp g)
+{-# INLINE forBySTM #-}
+
+-- Utilities
+
+acc :: Int# -> a -> Acc a
+acc i a = Acc (I# i) a
+{-# INLINE acc #-}
+
+data IntAccumL s a = IntAccumL (Int# -> s -> (# Int#, s, a #))
+
+runIntAccumL :: IntAccumL s a -> Int -> s -> (s, a)
+runIntAccumL (IntAccumL m) (I# i) s = case m i s of
+    (# _, s1, a #) -> (s1, a)
+{-# INLINE runIntAccumL #-}
+
+instance Functor (IntAccumL s) where
+    fmap f (IntAccumL m) = IntAccumL  (\i s -> case m i s of
+        (# i1, s1, a #) -> (# i1, s1, f a #))
+
+instance Applicative (IntAccumL s) where
+    pure a = IntAccumL (\i s -> (# i, s, a #))
+    IntAccumL mf <*> IntAccumL ma = IntAccumL (\i s ->
+        case mf i s of
+            (# i1, s1, f #) ->
+                case ma i1 s1 of
+                    (# i2, s2, a #) -> (# i2, s2, f a #))
+
+data IntAccumR s a = IntAccumR (Int# -> s -> (# Int#, s, a #))
+
+runIntAccumR :: IntAccumR s a -> Int -> s -> (s, a)
+runIntAccumR (IntAccumR m) (I# i) s = case m i s of
+    (# _, s1, a #) -> (s1, a)
+{-# INLINE runIntAccumR #-}
+
+instance Functor (IntAccumR s) where
+    fmap f (IntAccumR m) = IntAccumR  (\i s -> case m i s of
+        (# i1, s1, a #) -> (# i1, s1, f a #))
+
+instance Applicative (IntAccumR s) where
+    pure a = IntAccumR (\i s -> (# i, s, a #))
+    IntAccumR mf <*> IntAccumR ma = IntAccumR (\i s ->
+        case ma i s of
+            (# i1, s1, a #) ->
+                case mf i1 s1 of
+                    (# i2, s2, f #) -> (# i2, s2, f a #))
+
+-- applicative composition with a strict integer state applicative
+newtype AccT m a = AccT (Int# -> Acc (m a))
+
+runAccT :: AccT m a -> Int -> m a
+runAccT (AccT m) (I# i) = extractAcc (m i)
+{-# INLINE runAccT #-}
+
+instance Functor f => Functor (AccT f) where
+    fmap f (AccT m) = AccT (\i# -> case m i# of Acc i a -> Acc i (fmap f a))
+
+instance Applicative f => Applicative (AccT f) where
+    pure a = AccT (\i -> Acc (I# i) (pure a))
+    AccT mf <*> AccT ma = AccT (\i0# ->
+        let !(Acc (I# i1#) f) = mf i0#
+            (Acc i2 a) = ma i1#
+        in  Acc i2 (f <*> a))
