module Control.FlatSeq
where
import Data.Word
infixr 0 $!!
($!!) :: WNFData a => (a -> b) -> a -> b
f $!! x = rwnf x `seq` f x
flatseq :: WNFData a => a -> b -> b
flatseq a b = rwnf a `seq` b
rlnf :: (a -> ()) -> [a] -> ()
rlnf _ [] = ()
rlnf r (x:xs) = r x `seq` rlnf r xs
class WNFData a where
rwnf :: a -> ()
rwnf a = a `seq` ()
rwnf2 :: a -> ()
rwnf2 = rwnf
instance WNFData Int
instance WNFData Integer
instance WNFData Float
instance WNFData Double
instance WNFData Char
instance WNFData Bool
instance WNFData ()
instance WNFData Word
instance WNFData Word8
instance WNFData Word16
instance WNFData Word32
instance WNFData Word64
instance WNFData a => WNFData [a] where
rwnf [] = ()
rwnf (x:xs) = x `seq` rwnf xs
instance (WNFData a, WNFData b) => WNFData (a,b) where
rwnf (x,y) = rwnf x `seq` rwnf y
instance (WNFData a, WNFData b, WNFData c) => WNFData (a,b,c) where
rwnf (x,y,z) = rwnf x `seq` rwnf y `seq` rwnf z
instance (WNFData a, WNFData b, WNFData c, WNFData d) => WNFData (a,b,c,d) where
rwnf (x1,x2,x3,x4) = rwnf x1 `seq`
rwnf x2 `seq`
rwnf x3 `seq`
rwnf x4