{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
module Control.Seq
(
Strategy
, using
, withStrategy
, r0
, rseq
, rdeepseq
, seqList
, seqListN
, seqListNth
, seqFoldable
, seqMap
, seqArray
, seqArrayBounds
, seqTuple2
, seqTuple3
, seqTuple4
, seqTuple5
, seqTuple6
, seqTuple7
, seqTuple8
, seqTuple9
) where
import Control.DeepSeq (NFData, deepseq)
#if MIN_VERSION_base(4,8,0)
import Data.Foldable (toList)
#else
import Data.Foldable (Foldable, toList)
#endif
import Data.Map (Map)
import qualified Data.Map (toList)
#if !((__GLASGOW_HASKELL__ >= 711) && MIN_VERSION_array(0,5,1))
import Data.Ix (Ix)
#endif
import Data.Array (Array)
import qualified Data.Array (bounds, elems)
infixl 0 `using`
type Strategy a = a -> ()
using :: a -> Strategy a -> a
x :: a
x using :: a -> Strategy a -> a
`using` strat :: Strategy a
strat = Strategy a
strat a
x () -> a -> a
forall a b. a -> b -> b
`seq` a
x
withStrategy :: Strategy a -> a -> a
withStrategy :: Strategy a -> a -> a
withStrategy = (a -> Strategy a -> a) -> Strategy a -> a -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Strategy a -> a
forall a. a -> Strategy a -> a
using
r0 :: Strategy a
r0 :: Strategy a
r0 _ = ()
rseq :: Strategy a
rseq :: Strategy a
rseq x :: a
x = a
x a -> () -> ()
forall a b. a -> b -> b
`seq` ()
rdeepseq :: NFData a => Strategy a
rdeepseq :: Strategy a
rdeepseq x :: a
x = a
x a -> () -> ()
forall a b. NFData a => a -> b -> b
`deepseq` ()
seqList :: Strategy a -> Strategy [a]
seqList :: Strategy a -> Strategy [a]
seqList _strat :: Strategy a
_strat [] = ()
seqList strat :: Strategy a
strat (x :: a
x:xs :: [a]
xs) = Strategy a
strat a
x () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy a -> Strategy [a]
forall a. Strategy a -> Strategy [a]
seqList Strategy a
strat [a]
xs
seqListN :: Int -> Strategy a -> Strategy [a]
seqListN :: Int -> Strategy a -> Strategy [a]
seqListN 0 _strat :: Strategy a
_strat _ = ()
seqListN !Int
_ _strat :: Strategy a
_strat [] = ()
seqListN !Int
n strat :: Strategy a
strat (x :: a
x:xs :: [a]
xs) = Strategy a
strat a
x () -> () -> ()
forall a b. a -> b -> b
`seq` Int -> Strategy a -> Strategy [a]
forall a. Int -> Strategy a -> Strategy [a]
seqListN (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) Strategy a
strat [a]
xs
seqListNth :: Int -> Strategy a -> Strategy [a]
seqListNth :: Int -> Strategy a -> Strategy [a]
seqListNth 0 strat :: Strategy a
strat (x :: a
x:_) = Strategy a
strat a
x
seqListNth !Int
_ _strat :: Strategy a
_strat [] = ()
seqListNth !Int
n strat :: Strategy a
strat (_:xs :: [a]
xs) = Int -> Strategy a -> Strategy [a]
forall a. Int -> Strategy a -> Strategy [a]
seqListNth (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) Strategy a
strat [a]
xs
seqFoldable :: Foldable t => Strategy a -> Strategy (t a)
seqFoldable :: Strategy a -> Strategy (t a)
seqFoldable strat :: Strategy a
strat = Strategy a -> Strategy [a]
forall a. Strategy a -> Strategy [a]
seqList Strategy a
strat Strategy [a] -> (t a -> [a]) -> Strategy (t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
{-# SPECIALISE seqFoldable :: Strategy a -> Strategy [a] #-}
#if (__GLASGOW_HASKELL__ >= 711) && MIN_VERSION_array(0,5,1)
seqArray :: Strategy a -> Strategy (Array i a)
#else
seqArray :: Ix i => Strategy a -> Strategy (Array i a)
#endif
seqArray :: Strategy a -> Strategy (Array i a)
seqArray strat :: Strategy a
strat = Strategy a -> Strategy [a]
forall a. Strategy a -> Strategy [a]
seqList Strategy a
strat Strategy [a] -> (Array i a -> [a]) -> Strategy (Array i a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array i a -> [a]
forall i e. Array i e -> [e]
Data.Array.elems
#if (__GLASGOW_HASKELL__ >= 711) && MIN_VERSION_array(0,5,1)
seqArrayBounds :: Strategy i -> Strategy (Array i a)
#else
seqArrayBounds :: Ix i => Strategy i -> Strategy (Array i a)
#endif
seqArrayBounds :: Strategy i -> Strategy (Array i a)
seqArrayBounds strat :: Strategy i
strat = Strategy i -> Strategy i -> Strategy (i, i)
forall a b. Strategy a -> Strategy b -> Strategy (a, b)
seqTuple2 Strategy i
strat Strategy i
strat Strategy (i, i) -> (Array i a -> (i, i)) -> Strategy (Array i a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array i a -> (i, i)
forall i e. Array i e -> (i, i)
Data.Array.bounds
seqMap :: Strategy k -> Strategy v -> Strategy (Map k v)
seqMap :: Strategy k -> Strategy v -> Strategy (Map k v)
seqMap stratK :: Strategy k
stratK stratV :: Strategy v
stratV = Strategy (k, v) -> Strategy [(k, v)]
forall a. Strategy a -> Strategy [a]
seqList (Strategy k -> Strategy v -> Strategy (k, v)
forall a b. Strategy a -> Strategy b -> Strategy (a, b)
seqTuple2 Strategy k
stratK Strategy v
stratV) Strategy [(k, v)] -> (Map k v -> [(k, v)]) -> Strategy (Map k v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Data.Map.toList
seqTuple2 :: Strategy a -> Strategy b -> Strategy (a,b)
seqTuple2 :: Strategy a -> Strategy b -> Strategy (a, b)
seqTuple2 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 (x1 :: a
x1,x2 :: b
x2) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2
seqTuple3 :: Strategy a -> Strategy b -> Strategy c -> Strategy (a,b,c)
seqTuple3 :: Strategy a -> Strategy b -> Strategy c -> Strategy (a, b, c)
seqTuple3 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3
seqTuple4 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy (a,b,c,d)
seqTuple4 :: Strategy a
-> Strategy b -> Strategy c -> Strategy d -> Strategy (a, b, c, d)
seqTuple4 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4
seqTuple5 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy (a,b,c,d,e)
seqTuple5 :: Strategy a
-> Strategy b
-> Strategy c
-> Strategy d
-> Strategy e
-> Strategy (a, b, c, d, e)
seqTuple5 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 strat5 :: Strategy e
strat5 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy e
strat5 e
x5
seqTuple6 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy (a,b,c,d,e,f)
seqTuple6 :: Strategy a
-> Strategy b
-> Strategy c
-> Strategy d
-> Strategy e
-> Strategy f
-> Strategy (a, b, c, d, e, f)
seqTuple6 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 strat5 :: Strategy e
strat5 strat6 :: Strategy f
strat6 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5,x6 :: f
x6) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy e
strat5 e
x5 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy f
strat6 f
x6
seqTuple7 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy (a,b,c,d,e,f,g)
seqTuple7 :: Strategy a
-> Strategy b
-> Strategy c
-> Strategy d
-> Strategy e
-> Strategy f
-> Strategy g
-> Strategy (a, b, c, d, e, f, g)
seqTuple7 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 strat5 :: Strategy e
strat5 strat6 :: Strategy f
strat6 strat7 :: Strategy g
strat7 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5,x6 :: f
x6,x7 :: g
x7) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy e
strat5 e
x5 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy f
strat6 f
x6 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy g
strat7 g
x7
seqTuple8 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy (a,b,c,d,e,f,g,h)
seqTuple8 :: Strategy a
-> Strategy b
-> Strategy c
-> Strategy d
-> Strategy e
-> Strategy f
-> Strategy g
-> Strategy h
-> Strategy (a, b, c, d, e, f, g, h)
seqTuple8 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 strat5 :: Strategy e
strat5 strat6 :: Strategy f
strat6 strat7 :: Strategy g
strat7 strat8 :: Strategy h
strat8 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5,x6 :: f
x6,x7 :: g
x7,x8 :: h
x8) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy e
strat5 e
x5 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy f
strat6 f
x6 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy g
strat7 g
x7 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy h
strat8 h
x8
seqTuple9 :: Strategy a -> Strategy b -> Strategy c -> Strategy d -> Strategy e -> Strategy f -> Strategy g -> Strategy h -> Strategy i -> Strategy (a,b,c,d,e,f,g,h,i)
seqTuple9 :: Strategy a
-> Strategy b
-> Strategy c
-> Strategy d
-> Strategy e
-> Strategy f
-> Strategy g
-> Strategy h
-> Strategy i
-> Strategy (a, b, c, d, e, f, g, h, i)
seqTuple9 strat1 :: Strategy a
strat1 strat2 :: Strategy b
strat2 strat3 :: Strategy c
strat3 strat4 :: Strategy d
strat4 strat5 :: Strategy e
strat5 strat6 :: Strategy f
strat6 strat7 :: Strategy g
strat7 strat8 :: Strategy h
strat8 strat9 :: Strategy i
strat9 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5,x6 :: f
x6,x7 :: g
x7,x8 :: h
x8,x9 :: i
x9) =
Strategy a
strat1 a
x1 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy b
strat2 b
x2 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy c
strat3 c
x3 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy d
strat4 d
x4 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy e
strat5 e
x5 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy f
strat6 f
x6 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy g
strat7 g
x7 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy h
strat8 h
x8 () -> () -> ()
forall a b. a -> b -> b
`seq` Strategy i
strat9 i
x9