mirror of
https://github.com/ekmett/speculation.git
synced 2024-07-14 16:50:23 +03:00
streamlined MonadSpec
This commit is contained in:
parent
7b5ececdfc
commit
bf038b00e6
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
.hpc
|
.hpc
|
||||||
|
*.swo
|
||||||
|
*.swp
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/1.4/
|
||||||
|
|
||||||
|
* Simplified MonadSpec
|
||||||
|
|
||||||
/1.3/
|
/1.3/
|
||||||
|
|
||||||
* Removed old benchmark/test framework.
|
* Removed old benchmark/test framework.
|
||||||
|
@ -17,36 +17,37 @@ module Control.Concurrent.Speculation.Class where
|
|||||||
|
|
||||||
import Control.Monad.Trans.Cont
|
import Control.Monad.Trans.Cont
|
||||||
import Control.Concurrent.Speculation
|
import Control.Concurrent.Speculation
|
||||||
|
import Data.Function (on)
|
||||||
|
|
||||||
class MonadSpec m where
|
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
|
-- | @spec@ with a user supplied comparison function
|
||||||
specByM :: (a -> a -> Bool) -> a -> a -> m a
|
specByM :: (a -> a -> Bool) -> a -> a -> m a
|
||||||
|
|
||||||
-- | @spec'@ with a user supplied comparison function
|
-- | @spec'@ with a user supplied comparison function
|
||||||
specByM' :: (a -> a -> Bool) -> a -> a -> m a
|
specByM' :: (a -> a -> Bool) -> a -> a -> m a
|
||||||
|
|
||||||
-- | @spec'@ with a user supplied comparison function
|
-- | When a is unevaluated, @'spec' g a@ evaluates the current continuation
|
||||||
specOnM :: Eq c => (a -> c) -> a -> a -> m a
|
-- with @g@ while testing if @g@ '==' @a@, if they differ, it re-evalutes the
|
||||||
|
-- continuation with @a@. If @a@ was already evaluated, the continuation is
|
||||||
|
-- just directly applied to @a@ instead.
|
||||||
|
specM :: (MonadSpec m, Eq a) => a -> a -> m a
|
||||||
|
specM = specByM (==)
|
||||||
|
|
||||||
-- | @spec'@ with a user supplied comparison function
|
-- | As per 'spec', without the check for whether or not the second argument
|
||||||
specOnM' :: Eq c => (a -> c) -> a -> a -> m a
|
-- is already evaluated.
|
||||||
|
specM' :: (MonadSpec m, Eq a) => a -> a -> m a
|
||||||
|
specM' = specByM' (==)
|
||||||
|
|
||||||
|
-- | @spec'@ with a user supplied comparison function
|
||||||
|
specOnM :: (MonadSpec m, Eq c) => (a -> c) -> a -> a -> m a
|
||||||
|
specOnM = specByM . on (==)
|
||||||
|
|
||||||
|
-- | @spec'@ with a user supplied comparison function
|
||||||
|
specOnM' :: (MonadSpec m, Eq c) => (a -> c) -> a -> a -> m a
|
||||||
|
specOnM' = specByM . on (==)
|
||||||
|
|
||||||
-- * Basic speculation
|
-- * Basic speculation
|
||||||
|
|
||||||
instance Monad m => MonadSpec (ContT r m) where
|
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
|
||||||
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 @@
|
|||||||
name: speculation
|
name: speculation
|
||||||
version: 1.3
|
version: 1.4
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Edward A. Kmett
|
author: Edward A. Kmett
|
||||||
|
Loading…
Reference in New Issue
Block a user