{-# 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
a
x using :: a -> Strategy a -> a
`using` Strategy a
strat = Strategy a
strat a
x () -> a -> a
`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 a
_ = ()
rseq :: Strategy a
rseq :: Strategy a
rseq a
x = a
x a -> () -> ()
`seq` ()
rdeepseq :: NFData a => Strategy a
rdeepseq :: Strategy a
rdeepseq 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 Strategy a
_strat [] = ()
seqList Strategy a
strat (a
x:[a]
xs) = Strategy a
strat a
x () -> () -> ()
`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 Int
0 Strategy a
_strat [a]
_ = ()
seqListN !Int
_ Strategy a
_strat [] = ()
seqListN !Int
n Strategy a
strat (a
x:[a]
xs) = Strategy a
strat a
x () -> () -> ()
`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
-Int
1) Strategy a
strat [a]
xs
seqListNth :: Int -> Strategy a -> Strategy [a]
seqListNth :: Int -> Strategy a -> Strategy [a]
seqListNth Int
0 Strategy a
strat (a
x:[a]
_) = Strategy a
strat a
x
seqListNth !Int
_ Strategy a
_strat [] = ()
seqListNth !Int
n Strategy a
strat (a
_:[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
-Int
1) Strategy a
strat [a]
xs
seqFoldable :: Foldable t => Strategy a -> Strategy (t a)
seqFoldable :: Strategy a -> Strategy (t a)
seqFoldable 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 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 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 Strategy k
stratK 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 Strategy a
strat1 Strategy b
strat2 (a
x1,b
x2) =
Strategy a
strat1 a
x1 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 (a
x1,b
x2,c
x3) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 (a
x1,b
x2,c
x3,d
x4) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 Strategy e
strat5 (a
x1,b
x2,c
x3,d
x4,e
x5) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`seq` Strategy d
strat4 d
x4 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 Strategy e
strat5 Strategy f
strat6 (a
x1,b
x2,c
x3,d
x4,e
x5,f
x6) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`seq` Strategy d
strat4 d
x4 () -> () -> ()
`seq` Strategy e
strat5 e
x5 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 Strategy e
strat5 Strategy f
strat6 Strategy g
strat7 (a
x1,b
x2,c
x3,d
x4,e
x5,f
x6,g
x7) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`seq` Strategy d
strat4 d
x4 () -> () -> ()
`seq` Strategy e
strat5 e
x5 () -> () -> ()
`seq` Strategy f
strat6 f
x6 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 Strategy e
strat5 Strategy f
strat6 Strategy g
strat7 Strategy h
strat8 (a
x1,b
x2,c
x3,d
x4,e
x5,f
x6,g
x7,h
x8) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`seq` Strategy d
strat4 d
x4 () -> () -> ()
`seq` Strategy e
strat5 e
x5 () -> () -> ()
`seq` Strategy f
strat6 f
x6 () -> () -> ()
`seq` Strategy g
strat7 g
x7 () -> () -> ()
`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 Strategy a
strat1 Strategy b
strat2 Strategy c
strat3 Strategy d
strat4 Strategy e
strat5 Strategy f
strat6 Strategy g
strat7 Strategy h
strat8 Strategy i
strat9 (a
x1,b
x2,c
x3,d
x4,e
x5,f
x6,g
x7,h
x8,i
x9) =
Strategy a
strat1 a
x1 () -> () -> ()
`seq` Strategy b
strat2 b
x2 () -> () -> ()
`seq` Strategy c
strat3 c
x3 () -> () -> ()
`seq` Strategy d
strat4 d
x4 () -> () -> ()
`seq` Strategy e
strat5 e
x5 () -> () -> ()
`seq` Strategy f
strat6 f
x6 () -> () -> ()
`seq` Strategy g
strat7 g
x7 () -> () -> ()
`seq` Strategy h
strat8 h
x8 () -> () -> ()
`seq` Strategy i
strat9 i
x9