mirror of
https://github.com/ekmett/speculation.git
synced 2024-11-23 10:59:33 +03:00
minor documentation tweaks, packaging for distribution
This commit is contained in:
parent
5d14400660
commit
b7694b073f
@ -15,16 +15,16 @@ newtype Speculation = Speculation Int deriving (Show,Eq,Typeable)
|
||||
instance Exception Speculation
|
||||
|
||||
-- | @'specSTM' g f a@ evaluates @f g@ while forcing @a@, if @g == a@ then @f g@ is returned. Otherwise the side-effects
|
||||
-- of the current STM transaction are /rolled back/ and @f a@ is evaluated.
|
||||
-- of the current STM transaction are rolled back and @f a@ is evaluated.
|
||||
--
|
||||
-- If the argument @a@ is already evaluated, we don't bother to perform @f g@ at all.
|
||||
-- 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.
|
||||
--
|
||||
-- > spec a f a = f $! a
|
||||
-- > specSTM a f a = f $! a
|
||||
--
|
||||
-- The best-case timeline looks like:
|
||||
--
|
||||
@ -34,11 +34,11 @@ instance Exception Speculation
|
||||
--
|
||||
-- The worst-case timeline looks like:
|
||||
--
|
||||
-- >[------ f g ------]
|
||||
-- > [------ f g ------]
|
||||
-- > [------- a -------]
|
||||
-- [ rollback ]
|
||||
-- > [------ f a ------]
|
||||
-- > [---------- spec g f a ----------------------------]
|
||||
-- > [-- rollback --]
|
||||
-- > [------ f a ------]
|
||||
-- > [------------------ spec g f a ------------------------]
|
||||
--
|
||||
-- Compare these to the timeline of @f $! a@:
|
||||
--
|
||||
|
@ -116,7 +116,7 @@ specFoldl = specFoldlN 0
|
||||
{-# INLINE specFoldl #-}
|
||||
|
||||
class Foldable f => Speculative f where
|
||||
-- | 'specFoldr1' is to 'foldr1' as 'specFoldr' is to 'foldr'
|
||||
-- | 'specFoldr1' is to 'foldr1'' as 'specFoldr' is to 'foldr''
|
||||
specFoldr1 :: Eq a => (Int -> a) -> (a -> a -> a) -> f a -> a
|
||||
|
||||
-- | Given a valid estimator @g@, @'specFoldrN' n g f z xs@ yields the same answer as @'foldr' f z xs@.
|
||||
@ -124,7 +124,7 @@ class Foldable f => Speculative f where
|
||||
-- @g m@ should supply an estimate of the value returned from folding over the last @m - n@ elements of the container.
|
||||
specFoldrN :: Eq b => Int -> (Int -> b) -> (a -> b -> b) -> b -> f a -> b
|
||||
|
||||
-- | 'specFoldl1' is to 'foldl1' as 'specFoldl' is to 'foldl'
|
||||
-- | 'specFoldl1' is to 'foldl1'' as 'specFoldl' is to 'foldl''
|
||||
specFoldl1 :: Eq a => (Int -> a) -> (a -> a -> a) -> f a -> a
|
||||
|
||||
-- | Given a valid estimator @g@, @'specFoldlN' n g f z xs@ yields the same answer as @'foldl' f z xs@.
|
||||
|
@ -43,17 +43,17 @@ description:
|
||||
.
|
||||
'specSTM' provides a similar time table for STM actions, but also rolls back side-effects.
|
||||
.
|
||||
Changes in 0.1.0:
|
||||
/Changes in 0.1.0:/
|
||||
.
|
||||
Added 'Control.Concurrent.STM.Speculation' and 'specSTM'
|
||||
* Added @Control.Concurrent.STM.Speculation@ with 'specSTM', and 'specSTM''
|
||||
.
|
||||
Changes in 0.0.2:
|
||||
/Changes in 0.0.2:/
|
||||
.
|
||||
* 'specFoldr1' bug fix
|
||||
.
|
||||
* Added 'spec'' combinator
|
||||
.
|
||||
Changes in 0.0.1:
|
||||
/Changes in 0.0.1:/
|
||||
.
|
||||
* Added 'WithoutSpeculation' and 'WrappedFoldable'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user