{-# LANGUAGE FlexibleInstances #-} module Test.Exhaustively where import Control.Exception import Control.Parallel.Strategies import Data.Foldable exhaustively :: Exhaustable i => i -> IO Bool exhaustively = evaluate . exhaust parExhaustively :: (Bounded i, Enum i, Exhaustable b) => (i -> b) -> IO Bool parExhaustively f = evaluate $ foldl' seq True $ withStrategy (parBuffer 1000 rseq) $ map (exhaust . f) (enumFromTo minBound maxBound) class Exhaustable i where exhaust :: i -> Bool instance Exhaustable Bool where exhaust a = a `seq` a instance (Bounded i, Enum i) => Exhaustable (i -> Bool) where exhaust f = foldl' seq True $ map f (enumFromTo minBound maxBound)