Permalink
Browse files

1.3 release candidate

  • Loading branch information...
1 parent 3d0d9ed commit 7b5ececdfc9a2967f186fbe038b38d4aa26ecb6a @ekmett committed Nov 9, 2011
View
@@ -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
@@ -1,5 +1,16 @@
-{-# LANGUAGE CPP, BangPatterns, DeriveDataTypeable, MagicHash #-}
-module Data.Speculation
+{-# 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
@@ -18,7 +29,7 @@ module Data.Speculation
) where
import Control.Concurrent.STM
-import Data.Speculation.Internal (returning)
+import Control.Concurrent.Speculation.Internal (returning)
import Data.TagBits (unsafeIsEvaluated)
import Control.Monad (liftM2, unless)
import Data.Function (on)
@@ -86,7 +97,7 @@ specBy cmp guess f a
specBy' :: (a -> a -> Bool) -> a -> (a -> b) -> a -> b
specBy' cmp guess f a
| numCapabilities == 1 = f $! a
- | otherwise = speculation `par`
+ | otherwise = speculation `par`
if cmp guess a
then speculation
else f a
@@ -162,16 +173,11 @@ specBySTM cmp guess 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
+ if sparks < numCapabilities
then a `par` do
guess <- mguess
result <- f guess
@@ -181,7 +187,7 @@ specBySTM' cmp mguess f a = do
return result
`orElse`
f a
- else f $! a
+ else f $! a
{-# INLINE specBySTM' #-}
-- | @'specBySTM' . 'on' (==)@
@@ -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
@@ -1,5 +1,5 @@
{-# LANGUAGE BangPatterns #-}
-module Data.Speculation.Foldable
+module Control.Concurrent.Speculation.Foldable
(
-- * Speculative folds
fold, foldBy
@@ -55,8 +55,8 @@ 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.Concurrent.Speculation
+import Control.Concurrent.Speculation.Internal
import Control.Applicative
import Control.Monad hiding (mapM_, msum, forM_, sequence_)
@@ -349,15 +349,15 @@ 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 :: (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, Num a) => (Int -> a) -> t a -> a
+product :: (Foldable t, Eq a, Num a) => (Int -> a) -> t a -> a
product = productBy (==)
{-# INLINE product #-}
@@ -1,4 +1,15 @@
-module Data.Speculation.Internal
+-----------------------------------------------------------------------------
+-- |
+-- 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(..)
@@ -1,6 +1,16 @@
-{-# LANGUAGE BangPatterns #-}
-module Data.Speculation.List
- (
+-----------------------------------------------------------------------------
+-- |
+-- 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
@@ -19,7 +29,7 @@ module Data.Speculation.List
) where
-import Prelude hiding
+import Prelude hiding
(foldl, foldl1, foldr, foldr1
, any, all, and, or, mapM_, sequence_
, elem, notElem, sum, product
@@ -29,13 +39,13 @@ import Prelude hiding
import Data.Monoid
import qualified Data.List as List
-import Data.Speculation
-import Data.Speculation.Internal
+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.
@@ -49,9 +59,9 @@ 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.
--
@@ -79,13 +89,13 @@ scanr = scanrBy (==)
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
+ 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 (==)
+scanl = scanlBy (==)
{-# INLINE scanl #-}
scanlBy :: (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> [a] -> [b]
@@ -95,7 +105,7 @@ scanlBy cmp g f z = map extractAcc . List.scanl mf (Acc 0 z)
{-# INLINE scanlBy #-}
scanr1 :: Eq a => (Int -> a) -> (a -> a -> a) -> [a] -> [a]
-scanr1 = scanr1By (==)
+scanr1 = scanr1By (==)
{-# INLINE scanr1 #-}
scanr1By :: (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> [a] -> [a]
@@ -115,67 +125,3 @@ scanl1By cmp g f xs = map (fromMaybeAcc undefined) $ List.scanl mf NothingAcc xs
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.
--}
Oops, something went wrong.

0 comments on commit 7b5ecec

Please sign in to comment.