copyright bump, whitespace cleanup

This commit is contained in:
Edward Kmett 2015-03-08 06:32:52 -04:00
parent f193a812a5
commit 92e3e50701
8 changed files with 45 additions and 34 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2010-2013, Edward Kmett Copyright (c) 2010-2015, Edward Kmett
All rights reserved. All rights reserved.

View File

@ -8,7 +8,7 @@ stability: experimental
homepage: http://github.com/ekmett/speculation homepage: http://github.com/ekmett/speculation
bug-reports: http://github.com/ekmett/speculation/issues bug-reports: http://github.com/ekmett/speculation/issues
category: Concurrency category: Concurrency
copyright: (c) 2010-2013 Edward A. Kmett copyright: (c) 2010-2015 Edward A. Kmett
build-type: Simple build-type: Simple
cabal-version: >=1.6 cabal-version: >=1.6
tested-with: GHC==6.12.1, GHC==7.3.20111017, GHC==7.4.2, GHC==7.6.3, GHC==7.7, GHC==7.8.4, GHC==7.10.0.20150307 tested-with: GHC==6.12.1, GHC==7.3.20111017, GHC==7.4.2, GHC==7.6.3, GHC==7.7, GHC==7.8.4, GHC==7.10.0.20150307

View File

@ -5,7 +5,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Control.Concurrent.Speculation -- Module : Control.Concurrent.Speculation
-- Copyright : (C) 2008-2011 Edward Kmett, -- Copyright : (C) 2008-2015 Edward Kmett,
-- License : BSD-style (see the file LICENSE) -- License : BSD-style (see the file LICENSE)
-- --
-- Maintainer : Edward Kmett <ekmett@gmail.com> -- Maintainer : Edward Kmett <ekmett@gmail.com>

View File

@ -1,7 +1,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Control.Concurrent.Speculation.Class -- Module : Control.Concurrent.Speculation.Class
-- Copyright : (C) 2011 Edward Kmett, Jake McArthur -- Copyright : (C) 2011-2015 Edward Kmett, Jake McArthur
-- License : BSD-style (see the file LICENSE) -- License : BSD-style (see the file LICENSE)
-- --
-- Maintainer : Edward Kmett <ekmett@gmail.com> -- Maintainer : Edward Kmett <ekmett@gmail.com>

View File

@ -1,7 +1,18 @@
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BangPatterns #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Concurrent.Speculation.Foldable
-- Copyright : (C) 2010-2015 Edward Kmett
-- License : BSD-style (see the file LICENSE)
--
-- Maintainer : Edward Kmett <ekmett@gmail.com>
-- Stability : provisional
-- Portability : portable
--
----------------------------------------------------------------------------
module Control.Concurrent.Speculation.Foldable module Control.Concurrent.Speculation.Foldable
( (
-- * Speculative folds -- * Speculative folds
fold, foldBy fold, foldBy
, foldMap, foldMapBy , foldMap, foldMapBy
@ -43,7 +54,7 @@ module Control.Concurrent.Speculation.Foldable
, find, findBy , find, findBy
) where ) where
import Prelude hiding import Prelude hiding
( foldl, foldl1, foldr, foldr1 ( foldl, foldl1, foldr, foldr1
, any, all, and, or, mapM_, sequence_ , any, all, and, or, mapM_, sequence_
, elem, notElem, sum, product , elem, notElem, sum, product
@ -68,9 +79,9 @@ import Control.Applicative
import Control.Monad hiding (mapM_, msum, forM_, sequence_) 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@. -- | 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. -- @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 -- 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. -- provide increased opportunities for parallelism.
@ -84,9 +95,9 @@ foldBy cmp g = foldrBy cmp g mappend mempty
{-# INLINE foldBy #-} {-# INLINE foldBy #-}
-- | Given a valid estimator @g@, @'foldMap' g f xs@ yields the same answer as @'foldMap' f xs@. -- | 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. -- @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 -- 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. -- provide increased opportunities for parallelism.
@ -124,14 +135,14 @@ foldrBy cmp g f z = extractAcc . Foldable.foldr mf (Acc 0 z)
foldrBy :: Foldable f => (b -> b -> Bool) -> (Int -> Int -> b) -> (a -> b -> b) -> b -> f a -> b 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 foldrBy cmp g f z xs = Foldable.foldr mf (Acc 0 (const z)) xs 0
where where
mf a (Acc r b) !l = let l' = l + 1 in Acc (r + 1) (specBy cmp (g l') (f a) (b l')) mf a (Acc r b) !l = let l' = l + 1 in Acc (r + 1) (specBy cmp (g l') (f a) (b l'))
{-# INLINE foldrBy #-} {-# INLINE foldrBy #-}
-- this estimator receives the number of values to the left of the summation. -- 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 :: 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 foldrBy cmp g f z xs = Foldable.foldr mf (const z) xs 0
where where
mf a b !i = let i' = i + 1 in specBy cmp (g i') (f a) (b i') mf a b !i = let i' = i + 1 in specBy cmp (g i') (f a) (b i')
{-# INLINE foldrBy #-} {-# INLINE foldrBy #-}
-} -}
@ -141,7 +152,7 @@ foldlM = foldlByM (==)
{-# INLINE foldlM #-} {-# 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 :: (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) foldlByM cmp g f mz = liftM extractAcc . Foldable.foldl go (liftM (Acc 0) mz)
where where
go mia b = do go mia b = do
Acc n a <- mia Acc n a <- mia
@ -154,7 +165,7 @@ foldrM = foldrByM (==)
{-# INLINE foldrM #-} {-# 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 :: (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) foldrByM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz)
where where
go a mib = do go a mib = do
Acc n b <- mib Acc n b <- mib
@ -196,7 +207,7 @@ foldrBySTM cmp g f mz = liftM extractAcc . Foldable.foldr go (liftM (Acc 0) mz)
-- provide increased opportunities for parallelism. -- provide increased opportunities for parallelism.
foldl :: (Foldable f, Eq b) => (Int -> b) -> (b -> a -> b) -> b -> f a -> b foldl :: (Foldable f, Eq b) => (Int -> b) -> (b -> a -> b) -> b -> f a -> b
foldl = foldlBy (==) foldl = foldlBy (==)
{-# INLINE foldl #-} {-# INLINE foldl #-}
foldlBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> f a -> b foldlBy :: Foldable f => (b -> b -> Bool) -> (Int -> b) -> (b -> a -> b) -> b -> f a -> b
@ -206,7 +217,7 @@ foldlBy cmp g f z = extractAcc . Foldable.foldl mf (Acc 0 z)
{-# INLINE foldlBy #-} {-# INLINE foldlBy #-}
foldr1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a foldr1 :: (Foldable f, Eq a) => (Int -> a) -> (a -> a -> a) -> f a -> a
foldr1 = foldr1By (==) foldr1 = foldr1By (==)
{-# INLINE foldr1 #-} {-# INLINE foldr1 #-}
foldr1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a foldr1By :: Foldable f => (a -> a -> Bool) -> (Int -> a) -> (a -> a -> a) -> f a -> a
@ -255,7 +266,7 @@ mapM_ = mapByM_ (==)
{-# INLINE mapM_ #-} {-# INLINE mapM_ #-}
-- | Map each element of the structure to a monadic action, evaluating these actions -- | 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 -- from left to right and ignoring the results, while transactional side-effects from
-- mis-speculated actions are rolled back. -- mis-speculated actions are rolled back.
mapSTM_ :: Foldable t => STM Bool -> (Int -> STM c) -> (a -> STM b) -> t a -> STM () 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 ()) mapSTM_ chk g f = foldrBySTM (\_ _ -> chk) (\n -> () <$ g n) (\a _ -> () <$ f a) (return ())
@ -288,7 +299,7 @@ sequenceByA_ cmp g = foldrBy cmp ((()<$) . g) (*>) (pure ())
{-# INLINE sequenceByA_ #-} {-# INLINE sequenceByA_ #-}
sequence_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m b) -> t (m a) -> m () sequence_ :: (Foldable t, Monad m, Eq (m ())) => (Int -> m b) -> t (m a) -> m ()
sequence_ = sequenceBy_ (==) sequence_ = sequenceBy_ (==)
{-# INLINE sequence_ #-} {-# INLINE sequence_ #-}
sequenceSTM_:: Foldable t => STM Bool -> (Int -> STM a) -> t (STM b) -> STM () sequenceSTM_:: Foldable t => STM Bool -> (Int -> STM a) -> t (STM b) -> STM ()
@ -308,11 +319,11 @@ asumBy cmp g = foldrBy cmp g (<|>) empty
{-# INLINE asumBy #-} {-# INLINE asumBy #-}
msum :: (Foldable t, MonadPlus m, Eq (m a)) => (Int -> m a) -> t (m a) -> m a msum :: (Foldable t, MonadPlus m, Eq (m a)) => (Int -> m a) -> t (m a) -> m a
msum = msumBy (==) msum = msumBy (==)
{-# INLINE msum #-} {-# INLINE msum #-}
msumBy :: (Foldable t, MonadPlus m) => (m a -> m a -> Bool) -> (Int -> m a) -> t (m a) -> m a 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 msumBy cmp g = foldrBy cmp g mplus mzero
{-# INLINE msumBy #-} {-# INLINE msumBy #-}
toList :: (Foldable t, Eq a) => (Int -> [a]) -> t a -> [a] toList :: (Foldable t, Eq a) => (Int -> [a]) -> t a -> [a]
@ -378,26 +389,26 @@ maximum g = foldr1 g max
-- TODO: allow for patching? -- TODO: allow for patching?
maximumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a maximumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
maximumBy cmp g = foldr1By cmp' g max' maximumBy cmp g = foldr1By cmp' g max'
where where
max' x y = case cmp x y of max' x y = case cmp x y of
GT -> x GT -> x
_ -> y _ -> y
cmp' x y = cmp x y == EQ cmp' x y = cmp x y == EQ
{-# INLINE maximumBy #-} {-# INLINE maximumBy #-}
minimum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a minimum :: (Foldable t, Ord a) => (Int -> a) -> t a -> a
minimum g = foldr1 g min minimum g = foldr1 g min
{-# INLINE minimum #-} {-# INLINE minimum #-}
minimumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a minimumBy :: Foldable t => (a -> a -> Ordering) -> (Int -> a) -> t a -> a
minimumBy cmp g = foldr1By cmp' g min' minimumBy cmp g = foldr1By cmp' g min'
where where
min' x y = case cmp x y of min' x y = case cmp x y of
GT -> x GT -> x
_ -> y _ -> y
cmp' x y = cmp x y == EQ cmp' x y = cmp x y == EQ
{-# INLINE minimumBy #-} {-# INLINE minimumBy #-}
elem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool elem :: (Foldable t, Eq a) => (Int -> Bool) -> a -> t a -> Bool
elem g = any g . (==) elem g = any g . (==)
{-# INLINE elem #-} {-# INLINE elem #-}
@ -415,8 +426,8 @@ notElemBy cmp g a = not . elemBy cmp g a
{-# INLINE notElemBy #-} {-# INLINE notElemBy #-}
find :: (Foldable t, Eq a) => (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a find :: (Foldable t, Eq a) => (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a
find = findBy (==) find = findBy (==)
findBy :: Foldable t => (Maybe a -> Maybe a -> Bool) -> (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a findBy :: Foldable t => (Maybe a -> Maybe a -> Bool) -> (Int -> Maybe a) -> (a -> Bool) -> t a -> Maybe a
findBy cmp g p = getFirst . foldMapBy (on cmp getFirst) (First . g) (\x -> First (if p x then Just x else Nothing)) findBy cmp g p = getFirst . foldMapBy (on cmp getFirst) (First . g) (\x -> First (if p x then Just x else Nothing))

View File

@ -2,7 +2,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Control.Concurrent.Speculation.Internal -- Module : Control.Concurrent.Speculation.Internal
-- Copyright : (C) 2010-2011 Edward Kmett -- Copyright : (C) 2010-2015 Edward Kmett
-- License : BSD-style (see the file LICENSE) -- License : BSD-style (see the file LICENSE)
-- --
-- Maintainer : Edward Kmett <ekmett@gmail.com> -- Maintainer : Edward Kmett <ekmett@gmail.com>

View File

@ -2,7 +2,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Control.Concurrent.Speculation.List -- Module : Control.Concurrent.Speculation.List
-- Copyright : (C) 2010-2011 Edward Kmett, -- Copyright : (C) 2010-2015 Edward Kmett,
-- License : BSD-style (see the file LICENSE) -- License : BSD-style (see the file LICENSE)
-- --
-- Maintainer : Edward Kmett <ekmett@gmail.com> -- Maintainer : Edward Kmett <ekmett@gmail.com>

View File

@ -6,7 +6,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : Control.Concurrent.Speculation.Traversable -- Module : Control.Concurrent.Speculation.Traversable
-- Copyright : (C) 2010-2011 Edward Kmett, -- Copyright : (C) 2010-2015 Edward Kmett,
-- License : BSD-style (see the file LICENSE) -- License : BSD-style (see the file LICENSE)
-- --
-- Maintainer : Edward Kmett <ekmett@gmail.com> -- Maintainer : Edward Kmett <ekmett@gmail.com>