diff --git a/Benchmark.hs b/Benchmark.hs
deleted file mode 100644
--- a/Benchmark.hs
+++ /dev/null
@@ -1,14 +0,0 @@
-module Main where
-
-import Criterion.Main
-
-fib :: Int -> Int
-fib 0 = 0
-fib 1 = 1
-fib n = fib (n - 1) + fib (n - 2)
-
-main :: IO ()
-main = defaultMain 
-    [ bench "fib 1" $ nf fib 1
-    , bench "fib 2" $ nf fib 2
-    ]
diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown
--- a/CHANGELOG.markdown
+++ b/CHANGELOG.markdown
@@ -1,22 +1,39 @@
+/1.3/
+
+ * Removed old benchmark/test framework.
+ * Make numSparks support mandatory.
+ * Moved to Control.Concurrent from Data
+ * Added MonadSpec, so we can make instances for Codensity, etc. in other packages
+ * Removed the ContT r STM combinators
+ * Cleaned out old issues
+ * Made compatible with the removal of the Eq/Show superclasses of Num in GHC 7.3+
+
 /1.2.0.2/
+
  * Fixed name collision with the new Distribution.Simple.testHook in Setup.lhs
 
 /1.2.0.1/
+
  * Weakened dependencies
 
 /1.2.0.0/:
- * Reorganized the module hierarchy into Data.Speculation.*
 
+ * Reorganized the module hierarchy into Data.Speculation
+
 /1.1.0.0/:
+
  * Added support for numSparks
 
 /1.0.0.0/:
+
  * Released
 
 /0.9.0/:
+
  * Removed interim boxing in the unsafeIsEvaluated and unsafeGetTagBits check
 
 /0.8.1/:
+
  * Added Data.List.Foldable
  * Added Data.Traversable.Foldable
  * Fixed an off-by-one error in the arguments to the speculative fold estimators
@@ -26,5 +43,5 @@
  * changed tests and benchmarks to not build by default to work around corruption in the hackage db
 
 /0.8.0.1/:
- 
+
  * test suite now forces build
diff --git a/Control/Concurrent/Speculation.hs b/Control/Concurrent/Speculation.hs
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation.hs
@@ -0,0 +1,201 @@
+{-# LANGUAGE CPP #-}
+-----------------------------------------------------------------------------
+-- |
+-- 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
+    , spec'
+    , specBy
+    , specBy'
+    , specOn
+    , specOn'
+    -- * Speculative application with transactional rollback
+    , specSTM
+    , specSTM'
+    , specOnSTM
+    , specOnSTM'
+    , specBySTM
+    , specBySTM'
+    ) where
+
+import Control.Concurrent.STM
+import Control.Concurrent.Speculation.Internal (returning)
+import Data.TagBits (unsafeIsEvaluated)
+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 #-}
+
+-- | Unlike 'spec', this version does not check to see if the argument has already been evaluated. This can save
+-- a small amount of work when you know the argument will always require computation.
+
+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
+    | unsafeIsEvaluated a = f a
+    | otherwise = specBy' cmp guess f a
+{-# INLINE specBy #-}
+
+-- | '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 #-}
+
+-- | '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 #-}
+
+-- | Unlike 'specSTM', 'specSTM'' doesn't check if the argument has already been evaluated.
+
+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 guess f a
+    | unsafeIsEvaluated a = f a
+    | otherwise   = specBySTM' cmp guess f a
+{-# INLINE specBySTM #-}
+
+-- | '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 #-}
+
+-- | @'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
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation/Class.hs
@@ -0,0 +1,52 @@
+-----------------------------------------------------------------------------
+-- |
+-- 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
+
+class MonadSpec m where
+  -- | 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 :: Eq a => a -> a -> m a
+
+  -- | As per 'spec', without the check for whether or not the second argument
+  -- is already evaluated.
+  specM' :: Eq a => a -> a -> m a
+
+  -- | @spec@ with a user supplied comparison function
+  specByM :: (a -> a -> Bool) -> a -> a -> m a
+
+  -- | @spec'@ with a user supplied comparison function
+  specByM' :: (a -> a -> Bool) -> a -> a -> m a
+
+  -- | @spec'@ with a user supplied comparison function
+  specOnM :: Eq c => (a -> c) -> a -> a -> m a
+
+  -- | @spec'@ with a user supplied comparison function
+  specOnM' :: Eq c => (a -> c) -> a -> a -> m a
+
+-- * Basic speculation
+
+instance Monad m => MonadSpec (ContT r m) where
+  specM g a = ContT $ \k -> spec g k a
+  specM' g a = ContT $ \k -> spec' g k a
+  specByM f g a = ContT $ \k -> specBy f g k a
+  specByM' f g a = ContT $ \k -> specBy' f g k a
+  specOnM f g a = ContT $ \k -> specOn f g k a
+  specOnM' f g a = ContT $ \k -> specOn' f g k a
diff --git a/Control/Concurrent/Speculation/Foldable.hs b/Control/Concurrent/Speculation/Foldable.hs
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation/Foldable.hs
@@ -0,0 +1,416 @@
+{-# 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
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation/Internal.hs
@@ -0,0 +1,64 @@
+-----------------------------------------------------------------------------
+-- |
+-- 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
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation/List.hs
@@ -0,0 +1,127 @@
+-----------------------------------------------------------------------------
+-- |
+-- 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
new file mode 100644
--- /dev/null
+++ b/Control/Concurrent/Speculation/Traversable.hs
@@ -0,0 +1,205 @@
+{-# LANGUAGE MagicHash, Rank2Types, UnboxedTuples, BangPatterns #-}
+-----------------------------------------------------------------------------
+-- |
+-- 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/Data/Speculation.hs b/Data/Speculation.hs
deleted file mode 100644
--- a/Data/Speculation.hs
+++ /dev/null
@@ -1,195 +0,0 @@
-{-# LANGUAGE CPP, BangPatterns, DeriveDataTypeable, MagicHash #-}
-module Data.Speculation
-    (
-    -- * Speculative application
-      spec
-    , spec'
-    , specBy
-    , specBy'
-    , specOn
-    , specOn'
-    -- * Speculative application with transactional rollback
-    , specSTM
-    , specSTM'
-    , specOnSTM
-    , specOnSTM'
-    , specBySTM
-    , specBySTM'
-    ) where
-
-import Control.Concurrent.STM
-import Data.Speculation.Internal (returning)
-import Data.TagBits (unsafeIsEvaluated)
-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 #-}
-
--- | Unlike 'spec', this version does not check to see if the argument has already been evaluated. This can save
--- a small amount of work when you know the argument will always require computation.
-
-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
-    | unsafeIsEvaluated a = f a
-    | otherwise = specBy' cmp guess f a
-{-# INLINE specBy #-}
-
--- | '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 #-}
-
--- | '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 #-}
-
--- | Unlike 'specSTM', 'specSTM'' doesn't check if the argument has already been evaluated.
-
-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 guess f a
-    | unsafeIsEvaluated a = f a
-    | otherwise   = specBySTM' cmp guess f a
-{-# INLINE specBySTM #-}
-
-#ifndef HAS_NUM_SPARKS
-numSparks :: IO Int
-numSparks = return 0
-#endif
-
--- | '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 #-}
-
--- | @'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/Data/Speculation/Cont.hs b/Data/Speculation/Cont.hs
deleted file mode 100644
--- a/Data/Speculation/Cont.hs
+++ /dev/null
@@ -1,70 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Data.Speculation.Cont
--- 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.
-----------------------------------------------------------------------------
-module Data.Speculation.Cont where
-
-import Control.Monad.Trans.Cont
-import qualified Data.Speculation as Prim
-import Control.Concurrent.STM
-
--- * Basic speculation
-
--- | 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.
-spec :: Eq a => a -> a -> ContT r m a
-spec g a = ContT $ \k -> Prim.spec g k a 
-
--- | As per 'spec', without the check for whether or not the second argument
--- is already evaluated.
-spec' :: Eq a => a -> a -> ContT r m a
-spec' g a = ContT $ \k -> Prim.spec' g k a
-
--- | @spec@ with a user supplied comparison function
-specBy :: (a -> a -> Bool) -> a -> a -> ContT r m a
-specBy f g a = ContT $ \k -> Prim.specBy f g k a
-
--- | @spec'@ with a user supplied comparison function
-specBy' :: (a -> a -> Bool) -> a -> a -> ContT r m a
-specBy' f g a = ContT $ \k -> Prim.specBy' f g k a
-
--- | @spec'@ with a user supplied comparison function
-specOn :: Eq c => (a -> c) -> a -> a -> ContT r m a
-specOn f g a = ContT $ \k -> Prim.specOn f g k a
-
--- | @spec'@ with a user supplied comparison function
-specOn' :: Eq c => (a -> c) -> a -> a -> ContT r m a
-specOn' f g a = ContT $ \k -> Prim.specOn' f g k a
-
--- * STM-based speculation
-
-specSTM :: Eq a => STM a -> a -> ContT r STM a
-specSTM g a = ContT $ \k -> Prim.specSTM g k a 
-
-specSTM' :: Eq a => STM a -> a -> ContT r STM a
-specSTM' g a = ContT $ \k -> Prim.specSTM' g k a 
-
-specOnSTM :: Eq c => (a -> STM c) -> STM a -> a -> ContT r STM a
-specOnSTM f g a = ContT $ \k -> Prim.specOnSTM f g k a 
-
-specOnSTM' :: Eq c => (a -> STM c) -> STM a -> a -> ContT r STM a
-specOnSTM' f g a = ContT $ \k -> Prim.specOnSTM' f g k a 
-
-specBySTM :: (a -> a -> STM Bool) -> STM a -> a -> ContT r STM a
-specBySTM f g a = ContT $ \k -> Prim.specBySTM f g k a 
-
-specBySTM' :: (a -> a -> STM Bool) -> STM a -> a -> ContT r STM a
-specBySTM' f g a = ContT $ \k -> Prim.specBySTM' f g k a 
-
diff --git a/Data/Speculation/Foldable.hs b/Data/Speculation/Foldable.hs
deleted file mode 100644
--- a/Data/Speculation/Foldable.hs
+++ /dev/null
@@ -1,416 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-module Data.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 Data.Speculation
-import Data.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, 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, 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/Data/Speculation/Internal.hs b/Data/Speculation/Internal.hs
deleted file mode 100644
--- a/Data/Speculation/Internal.hs
+++ /dev/null
@@ -1,53 +0,0 @@
-module Data.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/Data/Speculation/List.hs b/Data/Speculation/List.hs
deleted file mode 100644
--- a/Data/Speculation/List.hs
+++ /dev/null
@@ -1,181 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-module Data.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 Data.Speculation
-import Data.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 #-}
-
-{-
-scanlM :: (Monad m, Eq b) => (Int -> b) -> (b -> a -> m b) -> b -> [a] -> m [b]
-scanlM = scanlByM (==)
-{-# INLINE scanlM #-}
-
-scanlByM ::  Monad m => (b -> b -> Bool) -> (Int -> b) -> (b -> a -> m b) -> b -> [a] -> m [b]
-scanlByM  cmp g f mz = liftM (map extractAcc) . List.scanl go (liftM (map (Acc 0)) mz) 
-  where
-    go mia b = do
-      Acc n a <- mia
-      a' <- specBy' cmp (g n) (`f` b) a
-      return (Acc (n + 1) a')
-{-# INLINE scanlByM #-}
-
-scanrM :: (Monad m, Eq (m b)) => (Int -> m b) -> (a -> b -> m b) -> m b -> [a] -> m [b]
-scanrM = scanrByM (==)
-{-# INLINE scanrM #-}
-
-scanrByM :: Monad m => (m b -> m b -> Bool) -> (Int -> m b) -> (a -> b -> m b) -> m b -> [a] -> m [b]
-scanrByM cmp g f mz = liftM (map extractAcc) . List.scanr go (liftM (map (Acc 0)) mz) 
-  where
-    go a mib = do
-      Acc n b <- mib
-      let !n' = n + 1
-      b' <- specBy' cmp (g n') (>>= f a) (return b)
-      return (Acc n' b')
-{-# INLINE scanrByM #-}
-
-scanlSTM :: Eq a => (Int -> STM a) -> (a -> b -> STM a) -> STM a -> [b] -> STM [a]
-scanlSTM = scanlBySTM (returning (==))
-{-# INLINE scanlSTM #-}
-
-scanlBySTM :: (a -> a -> STM Bool) -> (Int -> STM a) -> (a -> b -> STM a) -> STM a -> [b] -> STM [a]
-scanlBySTM cmp g f mz = liftM (map extractAcc) . List.scanl go (liftM (Acc 0) mz)
-  where
-    go mia b = do
-      Acc n a <- mia
-      let !n' = n + 1
-      a' <- specBySTM' cmp (g n') (`f` b) a
-      return (Acc n' a')
-{-# INLINE scanlBySTM #-}
-
-scanrSTM :: Eq b => (Int -> STM b) -> (a -> b -> STM b) -> STM b -> [a] -> STM [b]
-scanrSTM = scanrBySTM (returning (==))
-{-# INLINE scanrSTM #-}
-
-scanrBySTM :: (b -> b -> STM Bool) -> (Int -> STM b) -> (a -> b -> STM b) -> STM b -> [a] -> STM [b]
-scanrBySTM cmp g f mz = liftM (map extractAcc) . List.scanr go (liftM (Acc 0) mz)
-  where
-    go a mib = do
-      Acc n b <- mib
-      let !n' = n + 1
-      b' <- specBySTM' cmp (g n') (f a) b
-      return (Acc n' b')
-{-# INLINE scanrBySTM #-}
-
--- | Given a valid estimator @g@, @'scanl' g f z xs@ yields the same answer as @'scanl'' f z xs@.
---
--- @g n@ should supply an estimate of the value returned from scaning 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.
--}
diff --git a/Data/Speculation/Morphism.hs b/Data/Speculation/Morphism.hs
deleted file mode 100644
--- a/Data/Speculation/Morphism.hs
+++ /dev/null
@@ -1,31 +0,0 @@
-{-# LANGUAGE BangPatterns, MagicHash #-}
-module Data.Speculation.Morphism
-    ( hylo
-    ) where
-
-import GHC.Prim
-import GHC.Types
-
-import Data.Speculation
-
-{-
-newtype Mu f = In { out :: f (Mu f) } 
-
-ana :: (Functor f, Eq a) => (Int -> a) -> (a -> f a) -> a -> Mu f
-ana g psi = go 0# 
-  where
-    go n = In . fmap (go (n +# 1#)) . spec (g (I# n)) psi
-
-apo :: (Functor f, Eq a) => (Int -> a) -> (a -> f (Either (Mu f) a)) -> a -> Mu f
-apo g psi = go 0#
-    where
-        go n = In . fmap (either id (go (n +# 1#))) . spec (g (I# n)) psi 
--}
-        
--- | @'hylo' g phi psi@ is a hylomorphism using a speculative anamorphism, where
--- @g n@ estimates the seed after n iterations of 'psi'.
-
-hylo :: (Functor f, Eq a) => (Int -> a) -> (f b -> b) -> (a -> f a) -> a -> b
-hylo g phi psi = go 0#
-    where
-        go n = phi . fmap (go (n +# 1#)) . spec (g (I# n)) psi
diff --git a/Data/Speculation/Traversable.hs b/Data/Speculation/Traversable.hs
deleted file mode 100644
--- a/Data/Speculation/Traversable.hs
+++ /dev/null
@@ -1,195 +0,0 @@
-{-# LANGUAGE MagicHash, Rank2Types, UnboxedTuples, BangPatterns #-}
-module Data.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
---    , sequenceSTM, sequenceBySTM
-    -- * 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 Data.Speculation
-import Data.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/ISSUES.markdown b/ISSUES.markdown
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -1,31 +1,3 @@
-sparking the right computation
-------------------------------
-
-Currently the computation of 'spec g f a' does exactly what I want
-the computation of 'f g' happens in the spark queue through 'par'
-while the computation of 'a' happens in the foreground, as well as
-any (lazy) evaluation of 'f a'.
-
-(TODO: flop the other of g and a in the cmp to force them in reverse order, to make g even lazier?)
-
-However specSTM lacks this property. the 'par' has to launch the 
-computation of 'a' because 'f g' is in STM. Can we play games with par  
-to retain ownership of the STM transaction and move it into the par block, 
-and rendezvous with it upon the completion of calculating 'a' ? Per Marlow,
-apparently not. This leads to a fallback plan:
-
-sparking only when it makes sense
----------------------------------
-
-Another option (from talking with Simon Marlow) is to add a new primop:
-
-    numSparks# :: State# s -> (# Int#, State# s #)
-
-which computes dequeElements(cap->spark) and to not speculate when that is too high.
-
-Sadly, the cap and spark machinery is marked private by GHC, so this needs to become
-a ticket.
-
 inconsistent use of the estimator function
 ------------------------------------------
 
diff --git a/README.markdown b/README.markdown
--- a/README.markdown
+++ b/README.markdown
@@ -29,7 +29,7 @@
 
 However, if `g` isn\'t available more cheaply than `a`, then this saves no work, and if `g` is wrong, you risk evaluating the function twice.
     spec a f a = f $! a
-    
+
 The best-case timeline looks like:
     [---- f g ----]
        [----- a -----]
@@ -40,7 +40,7 @@
        [----- a -----]
                      [---- f a ----]
     [------- spec g f a -----------]
-    
+
 Compare these to the timeline of `f $! a`:
     [---- a -----]
                  [---- f a ----]
@@ -53,7 +53,7 @@
 ---------------------------------------------
 
 A speculative version of the combinators from `Data.Foldable` is provided as `Data.Foldable.Speculation`.
-    
+
 Each combinator therein takes an extra argument that is used to speculate on the value of the list.
 
 #### foldr
diff --git a/Test.hs b/Test.hs
deleted file mode 100644
--- a/Test.hs
+++ /dev/null
@@ -1,27 +0,0 @@
-{-# LANGUAGE BangPatterns #-}
-module Main where
-
-import Prelude hiding ((||),(&&)) 
-import Test.Framework (Test)
-import Test.Framework (defaultMain, testGroup)
-import Test.Framework.Providers.HUnit
-import Test.Framework.Providers.QuickCheck (testProperty)
-import Test.QuickCheck hiding ((==>))
--- import Test.HUnit hiding (Test)
-import Data.Speculation
-
-main :: IO () 
-main = defaultMain tests
-
-ignore :: Functor f => f a -> f () 
-ignore = fmap (const ())
-
-tests :: [Test]
-tests = 
-    [ testGroup "cases" $ zipWith (testCase . show) [1 :: Int ..] $
-        [] 
-    , testGroup "properties" $ zipWith (testProperty . show) [1 :: Int ..] $ 
-        [ property $ \ a -> spec a (*2) a == ((*2) a :: Int)  -- unevaluated
-        , property $ \ !a -> spec a (*2) a == ((*2) $! a :: Int) -- evaluated
-        ] 
-    ]
diff --git a/speculation.cabal b/speculation.cabal
--- a/speculation.cabal
+++ b/speculation.cabal
@@ -1,5 +1,5 @@
 name:           speculation
-version:        1.2.0.2
+version:        1.3
 license:        BSD3
 license-file:   LICENSE
 author:         Edward A. Kmett
@@ -10,7 +10,7 @@
 copyright:      (c) 2010 Edward A. Kmett
 build-type:     Custom
 cabal-version:  >=1.6
-tested-with:    GHC==6.12.1
+tested-with:    GHC==6.12.1, GHC==7.3.20111017
 synopsis:       A framework for safe, programmable, speculative parallelism
 description:
  A framework for safe, programmable, speculative parallelism, loosely based on:
@@ -23,7 +23,7 @@
  of the transactional rollback machinery from the paper.
  .
  For example:
- . 
+ .
  @'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, 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, 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:
@@ -64,47 +64,27 @@
  .
  '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
+extra-source-files:
+  README.markdown
+  CHANGELOG.markdown
+  ISSUES.markdown
 
 source-repository head
   type:     git
   location: http://github.com/ekmett/speculation.git
   branch:   master
 
-flag HasNumSparks
-  description: RTS provides GHC.Conc.numSparks
-  default: True
-  manual: False
-
-flag tests
-  description: Build the tests
-  default:     False
-
-flag benchmarks
-  description: Build the benchmarks
-  default:     False
-
 flag optimize
   description: Enable optimizations for the library and benchmarks
   default:     True
 
-flag hpc
-  description: Use HPC for tests
-  default:     True
-
 library
   ghc-options: -Wall
   if flag(optimize)
     ghc-options: -funbox-strict-fields -O2 -fspec-constr -fdicts-cheap
-  if flag(HasNumSparks)
-    cpp-options: -DHAS_NUM_SPARKS
-    build-depends: base >= 4.3 && < 6
-  else
-    build-depends: base >= 4 && < 4.3
 
+  build-depends: base >= 4.3 && < 6
+
   build-depends:
     ghc-prim >= 0.2 && < 0.4,
     tag-bits >= 0.1 && < 0.2,
@@ -112,74 +92,11 @@
     stm >= 2.1 && < 2.3
 
   exposed-modules:
-    Data.Speculation
-    Data.Speculation.Cont
-    Data.Speculation.Morphism
-    Data.Speculation.Foldable
-    Data.Speculation.Traversable
-    Data.Speculation.List
+    Control.Concurrent.Speculation
+    Control.Concurrent.Speculation.Class
+    Control.Concurrent.Speculation.Foldable
+    Control.Concurrent.Speculation.Traversable
+    Control.Concurrent.Speculation.List
   other-modules:
-    Data.Speculation.Internal
-
-executable test-speculation
-  main-is: Test.hs
-  if !flag(tests)
-    buildable: False
-  else
-    if flag(hpc)
-      ghc-options: -fhpc
-      x-hpc: true
-    ghc-options: -Wall
-    if flag(HasNumSparks)
-      cpp-options: -DHAS_NUM_SPARKS
-      build-depends: base >= 4.3 && < 6
-    else
-      build-depends: base >= 4 && < 4.3
-    build-depends:
-      ghc-prim >= 0.2 && < 0.4,
-      tag-bits >= 0.1 && < 0.2,
-      stm >= 2.1 && < 2.3,
-      transformers >= 0.2.2.0 && < 0.3,
-      containers >= 0.3.0 && < 0.5,
-      test-framework >= 0.2.4 && < 0.3,
-      test-framework-quickcheck >= 0.2.4 && < 0.3,
-      test-framework-hunit >= 0.2.4 && < 0.3, 
-      QuickCheck >= 1.2.0.0 && < 1.3,
-      HUnit >= 1.2.2.1 && < 1.3
-    other-modules:
-      Data.Speculation
-      Data.Speculation.Cont
-      Data.Speculation.Morphism
-      Data.Speculation.Foldable
-      Data.Speculation.Traversable
-      Data.Speculation.List
-      Data.Speculation.Internal
+    Control.Concurrent.Speculation.Internal
 
-executable benchmark-speculation
-  main-is: Benchmark.hs
-  if !flag(benchmarks)
-    buildable: False
-  else
-    ghc-options: -Wall -threaded
-    if flag(optimize)
-      ghc-options: -O2 -fspec-constr -funbox-strict-fields -fdicts-cheap
-    if flag(HasNumSparks)
-      cpp-options: -DHAS_NUM_SPARKS
-      build-depends: base >= 4.3 && < 6
-    else
-      build-depends: base >= 4 && < 4.3
-    build-depends:
-      ghc-prim >= 0.2 && < 0.4,
-      transformers >= 0.2.2.0 && < 0.3,
-      tag-bits >= 0.1 && < 0.2,
-      stm >= 2.1 && < 2.3,
-      containers >= 0.3.0 && < 0.5,
-      criterion >= 0.5 && < 0.6
-    other-modules:
-      Data.Speculation
-      Data.Speculation.Cont
-      Data.Speculation.Morphism
-      Data.Speculation.Foldable
-      Data.Speculation.Traversable
-      Data.Speculation.List
-      Data.Speculation.Internal
