module Test.LeanCheck.Core
(
holds
, fails
, exists
, counterExample
, counterExamples
, witness
, witnesses
, Testable(..)
, results
, Listable(..)
, cons0
, cons1
, cons2
, cons3
, cons4
, cons5
, delay
, reset
, suchThat
, (\/), (\\//)
, (><)
, productWith
, mapT
, filterT
, concatT
, concatMapT
, toTiers
, (==>)
, (+|)
, listIntegral
, listFractional
, listFloating
)
where
import Data.Maybe (listToMaybe)
class Listable a where
tiers :: [[a]]
list :: [a]
tiers = [a] -> [[a]]
forall a. [a] -> [[a]]
toTiers [a]
forall a. Listable a => [a]
list
list = [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[a]]
forall a. Listable a => [[a]]
tiers
{-# MINIMAL list | tiers #-}
toTiers :: [a] -> [[a]]
toTiers :: forall a. [a] -> [[a]]
toTiers = (a -> [a]) -> [a] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[])
instance Listable () where
list :: [()]
list = [()]
listIntegral :: (Ord a, Num a) => [a]
listIntegral :: forall a. (Ord a, Num a) => [a]
listIntegral = a
0 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
positives [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
+| [a]
negatives
where
positives :: [a]
positives = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a -> a -> a
forall a. Num a => a -> a -> a
+a
1) a
1
negatives :: [a]
negatives = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<a
0) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> a) -> a -> [a]
forall a. (a -> a) -> a -> [a]
iterate (a -> a -> a
forall a. Num a => a -> a -> a
subtract a
1) (-a
1)
instance Listable Int where
list :: [Int]
list = [Int]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable Integer where
list :: [Integer]
list = [Integer]
forall a. (Ord a, Num a) => [a]
listIntegral
instance Listable Char where
list :: [Char]
list = [Char
'a'..Char
'z']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
' ',Char
'\n']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'A'..Char
'Z']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'0'..Char
'9']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'!'..Char
'/']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'\t']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
':'..Char
'@']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'['..Char
'`']
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
+| [Char
'{'..Char
'~']
instance Listable Bool where
tiers :: [[Bool]]
tiers = Bool -> [[Bool]]
forall a. a -> [[a]]
cons0 Bool
False [[Bool]] -> [[Bool]] -> [[Bool]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ Bool -> [[Bool]]
forall a. a -> [[a]]
cons0 Bool
True
instance Listable a => Listable (Maybe a) where
tiers :: [[Maybe a]]
tiers = Maybe a -> [[Maybe a]]
forall a. a -> [[a]]
cons0 Maybe a
forall a. Maybe a
Nothing [[Maybe a]] -> [[Maybe a]] -> [[Maybe a]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> Maybe a) -> [[Maybe a]]
forall a b. Listable a => (a -> b) -> [[b]]
cons1 a -> Maybe a
forall a. a -> Maybe a
Just
instance (Listable a, Listable b) => Listable (Either a b) where
tiers :: [[Either a b]]
tiers = [[Either a b]] -> [[Either a b]]
forall a. [[a]] -> [[a]]
reset ((a -> Either a b) -> [[Either a b]]
forall a b. Listable a => (a -> b) -> [[b]]
cons1 a -> Either a b
forall a b. a -> Either a b
Left)
[[Either a b]] -> [[Either a b]] -> [[Either a b]]
forall a. [[a]] -> [[a]] -> [[a]]
\\// [[Either a b]] -> [[Either a b]]
forall a. [[a]] -> [[a]]
reset ((b -> Either a b) -> [[Either a b]]
forall a b. Listable a => (a -> b) -> [[b]]
cons1 b -> Either a b
forall a b. b -> Either a b
Right)
instance (Listable a, Listable b) => Listable (a,b) where
tiers :: [[(a, b)]]
tiers = [[a]]
forall a. Listable a => [[a]]
tiers [[a]] -> [[b]] -> [[(a, b)]]
forall a b. [[a]] -> [[b]] -> [[(a, b)]]
>< [[b]]
forall a. Listable a => [[a]]
tiers
instance (Listable a, Listable b, Listable c) => Listable (a,b,c) where
tiers :: [[(a, b, c)]]
tiers = (a -> (b, c) -> (a, b, c)) -> [[a]] -> [[(b, c)]] -> [[(a, b, c)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z) -> (a
x,b
y,c
z)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c)]]
forall a. Listable a => [[a]]
tiers
instance (Listable a, Listable b, Listable c, Listable d) =>
Listable (a,b,c,d) where
tiers :: [[(a, b, c, d)]]
tiers = (a -> (b, c, d) -> (a, b, c, d))
-> [[a]] -> [[(b, c, d)]] -> [[(a, b, c, d)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w) -> (a
x,b
y,c
z,d
w)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d)]]
forall a. Listable a => [[a]]
tiers
instance (Listable a, Listable b, Listable c, Listable d, Listable e) =>
Listable (a,b,c,d,e) where
tiers :: [[(a, b, c, d, e)]]
tiers = (a -> (b, c, d, e) -> (a, b, c, d, e))
-> [[a]] -> [[(b, c, d, e)]] -> [[(a, b, c, d, e)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (\a
x (b
y,c
z,d
w,e
v) -> (a
x,b
y,c
z,d
w,e
v)) [[a]]
forall a. Listable a => [[a]]
tiers [[(b, c, d, e)]]
forall a. Listable a => [[a]]
tiers
instance (Listable a) => Listable [a] where
tiers :: [[[a]]]
tiers = [a] -> [[[a]]]
forall a. a -> [[a]]
cons0 []
[[[a]]] -> [[[a]]] -> [[[a]]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> [a] -> [a]) -> [[[a]]]
forall a b c. (Listable a, Listable b) => (a -> b -> c) -> [[c]]
cons2 (:)
listFractional :: (Ord a, Fractional a) => [a]
listFractional :: forall a. (Ord a, Fractional a) => [a]
listFractional = a
0 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
positives [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
+| [a]
negatives
where
stern :: [a]
stern = (Integer -> a) -> [Integer] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> (Integer -> Integer) -> Integer -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Integer
fusc) [Integer
1..]
positives :: [a]
positives = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> [a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> a
forall a. Fractional a => a -> a -> a
(/) [a]
stern (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
1 [a]
stern)
negatives :: [a]
negatives = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<a
0) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map a -> a
forall a. Num a => a -> a
negate [a]
positives
fusc :: Integer -> Integer
fusc = Integer -> Integer -> Integer -> Integer
forall {t} {t}. (Integral t, Num t) => t -> t -> t -> t
fu Integer
1 Integer
0 where fu :: t -> t -> t -> t
fu t
a t
b t
0 = t
b
fu t
a t
b t
n | t -> Bool
forall a. Integral a => a -> Bool
even t
n = t -> t -> t -> t
fu (t
a t -> t -> t
forall a. Num a => a -> a -> a
+ t
b) t
b (t
n t -> t -> t
forall a. Integral a => a -> a -> a
`div` t
2)
| Bool
otherwise = t -> t -> t -> t
fu t
a (t
a t -> t -> t
forall a. Num a => a -> a -> a
+ t
b) ((t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1) t -> t -> t
forall a. Integral a => a -> a -> a
`div` t
2)
listFloating :: (Ord a, Fractional a) => [a]
listFloating :: forall a. (Ord a, Fractional a) => [a]
listFloating = [a]
heading [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
two, a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0, -a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0] [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
etc
where
([a]
heading,a
two:[a]
etc) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
2) [a]
forall a. (Ord a, Fractional a) => [a]
listFractional
instance Listable Float where
list :: [Float]
list = [Float]
forall a. (Ord a, Fractional a) => [a]
listFloating
instance Listable Double where
list :: [Double]
list = [Double]
forall a. (Ord a, Fractional a) => [a]
listFloating
instance Listable Ordering where
tiers :: [[Ordering]]
tiers = Ordering -> [[Ordering]]
forall a. a -> [[a]]
cons0 Ordering
LT
[[Ordering]] -> [[Ordering]] -> [[Ordering]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ Ordering -> [[Ordering]]
forall a. a -> [[a]]
cons0 Ordering
EQ
[[Ordering]] -> [[Ordering]] -> [[Ordering]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ Ordering -> [[Ordering]]
forall a. a -> [[a]]
cons0 Ordering
GT
mapT :: (a -> b) -> [[a]] -> [[b]]
mapT :: forall a b. (a -> b) -> [[a]] -> [[b]]
mapT = ([a] -> [b]) -> [[a]] -> [[b]]
forall a b. (a -> b) -> [a] -> [b]
map (([a] -> [b]) -> [[a]] -> [[b]])
-> ((a -> b) -> [a] -> [b]) -> (a -> b) -> [[a]] -> [[b]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map
filterT :: (a -> Bool) -> [[a]] -> [[a]]
filterT :: forall a. (a -> Bool) -> [[a]] -> [[a]]
filterT a -> Bool
f = ([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter a -> Bool
f)
concatT :: [[ [[a]] ]] -> [[a]]
concatT :: forall a. [[[[a]]]] -> [[a]]
concatT = ([[a]] -> [[a]] -> [[a]]) -> [[a]] -> [[[a]]] -> [[a]]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
(\+:/) [] ([[[a]]] -> [[a]]) -> ([[[[a]]]] -> [[[a]]]) -> [[[[a]]]] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[[a]]] -> [[a]]) -> [[[[a]]]] -> [[[a]]]
forall a b. (a -> b) -> [a] -> [b]
map (([[a]] -> [[a]] -> [[a]]) -> [[a]] -> [[[a]]] -> [[a]]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
(\/) [])
where
[[a]]
xss \+:/ :: [[a]] -> [[a]] -> [[a]]
\+:/ [[a]]
yss = [[a]]
xss [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ ([][a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
yss)
concatMapT :: (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT :: forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT a -> [[b]]
f = [[[[b]]]] -> [[b]]
forall a. [[[[a]]]] -> [[a]]
concatT ([[[[b]]]] -> [[b]]) -> ([[a]] -> [[[[b]]]]) -> [[a]] -> [[b]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [[b]]) -> [[a]] -> [[[[b]]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT a -> [[b]]
f
cons0 :: a -> [[a]]
cons0 :: forall a. a -> [[a]]
cons0 a
x = [[a
x]]
cons1 :: Listable a => (a -> b) -> [[b]]
cons1 :: forall a b. Listable a => (a -> b) -> [[b]]
cons1 a -> b
f = [[b]] -> [[b]]
forall a. [[a]] -> [[a]]
delay ([[b]] -> [[b]]) -> [[b]] -> [[b]]
forall a b. (a -> b) -> a -> b
$ (a -> b) -> [[a]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT a -> b
f [[a]]
forall a. Listable a => [[a]]
tiers
cons2 :: (Listable a, Listable b) => (a -> b -> c) -> [[c]]
cons2 :: forall a b c. (Listable a, Listable b) => (a -> b -> c) -> [[c]]
cons2 a -> b -> c
f = [[c]] -> [[c]]
forall a. [[a]] -> [[a]]
delay ([[c]] -> [[c]]) -> [[c]] -> [[c]]
forall a b. (a -> b) -> a -> b
$ ((a, b) -> c) -> [[(a, b)]] -> [[c]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c) -> (a, b) -> c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> c
f) [[(a, b)]]
forall a. Listable a => [[a]]
tiers
cons3 :: (Listable a, Listable b, Listable c) => (a -> b -> c -> d) -> [[d]]
cons3 :: forall a b c d.
(Listable a, Listable b, Listable c) =>
(a -> b -> c -> d) -> [[d]]
cons3 a -> b -> c -> d
f = [[d]] -> [[d]]
forall a. [[a]] -> [[a]]
delay ([[d]] -> [[d]]) -> [[d]] -> [[d]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c) -> d) -> [[(a, b, c)]] -> [[d]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d) -> (a, b, c) -> d
forall a b c d. (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f) [[(a, b, c)]]
forall a. Listable a => [[a]]
tiers
cons4 :: (Listable a, Listable b, Listable c, Listable d)
=> (a -> b -> c -> d -> e) -> [[e]]
cons4 :: forall a b c d e.
(Listable a, Listable b, Listable c, Listable d) =>
(a -> b -> c -> d -> e) -> [[e]]
cons4 a -> b -> c -> d -> e
f = [[e]] -> [[e]]
forall a. [[a]] -> [[a]]
delay ([[e]] -> [[e]]) -> [[e]] -> [[e]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d) -> e) -> [[(a, b, c, d)]] -> [[e]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e) -> (a, b, c, d) -> e
forall a b c d e. (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 a -> b -> c -> d -> e
f) [[(a, b, c, d)]]
forall a. Listable a => [[a]]
tiers
cons5 :: (Listable a, Listable b, Listable c, Listable d, Listable e)
=> (a -> b -> c -> d -> e -> f) -> [[f]]
cons5 :: forall a b c d e f.
(Listable a, Listable b, Listable c, Listable d, Listable e) =>
(a -> b -> c -> d -> e -> f) -> [[f]]
cons5 a -> b -> c -> d -> e -> f
f = [[f]] -> [[f]]
forall a. [[a]] -> [[a]]
delay ([[f]] -> [[f]]) -> [[f]] -> [[f]]
forall a b. (a -> b) -> a -> b
$ ((a, b, c, d, e) -> f) -> [[(a, b, c, d, e)]] -> [[f]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f
forall a b c d e f.
(a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f
uncurry5 a -> b -> c -> d -> e -> f
f) [[(a, b, c, d, e)]]
forall a. Listable a => [[a]]
tiers
delay :: [[a]] -> [[a]]
delay :: forall a. [[a]] -> [[a]]
delay = ([][a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:)
reset :: [[a]] -> [[a]]
reset :: forall a. [[a]] -> [[a]]
reset = ([a] -> Bool) -> [[a]] -> [[a]]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null
suchThat :: [[a]] -> (a->Bool) -> [[a]]
suchThat :: forall a. [[a]] -> (a -> Bool) -> [[a]]
suchThat = ((a -> Bool) -> [[a]] -> [[a]]) -> [[a]] -> (a -> Bool) -> [[a]]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> Bool) -> [[a]] -> [[a]]
filterT
(+|) :: [a] -> [a] -> [a]
[] +| :: forall a. [a] -> [a] -> [a]
+| [a]
ys = [a]
ys
(a
x:[a]
xs) +| [a]
ys = a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:([a]
ys [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
+| [a]
xs)
infixr 5 +|
(\/) :: [[a]] -> [[a]] -> [[a]]
[[a]]
xss \/ :: forall a. [[a]] -> [[a]] -> [[a]]
\/ [] = [[a]]
xss
[] \/ [[a]]
yss = [[a]]
yss
([a]
xs:[[a]]
xss) \/ ([a]
ys:[[a]]
yss) = ([a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
ys) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]]
xss [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ [[a]]
yss
infixr 7 \/
(\\//) :: [[a]] -> [[a]] -> [[a]]
[[a]]
xss \\// :: forall a. [[a]] -> [[a]] -> [[a]]
\\// [] = [[a]]
xss
[] \\// [[a]]
yss = [[a]]
yss
([a]
xs:[[a]]
xss) \\// ([a]
ys:[[a]]
yss) = ([a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
+| [a]
ys) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]]
xss [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
\\// [[a]]
yss
infixr 7 \\//
(><) :: [[a]] -> [[b]] -> [[(a,b)]]
>< :: forall a b. [[a]] -> [[b]] -> [[(a, b)]]
(><) = (a -> b -> (a, b)) -> [[a]] -> [[b]] -> [[(a, b)]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (,)
infixr 8 ><
productWith :: (a->b->c) -> [[a]] -> [[b]] -> [[c]]
productWith :: forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith a -> b -> c
_ [[a]]
_ [] = []
productWith a -> b -> c
_ [] [[b]]
_ = []
productWith a -> b -> c
f ([a]
xs:[[a]]
xss) [[b]]
yss = ([b] -> [c]) -> [[b]] -> [[c]]
forall a b. (a -> b) -> [a] -> [b]
map ([a]
xs [a] -> [b] -> [c]
**) [[b]]
yss
[[c]] -> [[c]] -> [[c]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ [[c]] -> [[c]]
forall a. [[a]] -> [[a]]
delay ((a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith a -> b -> c
f [[a]]
xss [[b]]
yss)
where
[a]
xs ** :: [a] -> [b] -> [c]
** [b]
ys = [a
x a -> b -> c
`f` b
y | a
x <- [a]
xs, b
y <- [b]
ys]
class Testable a where
resultiers :: a -> [[([String],Bool)]]
instance Testable Bool where
resultiers :: Bool -> [[([[Char]], Bool)]]
resultiers Bool
p = [[([],Bool
p)]]
instance (Testable b, Show a, Listable a) => Testable (a->b) where
resultiers :: (a -> b) -> [[([[Char]], Bool)]]
resultiers a -> b
p = (a -> [[([[Char]], Bool)]]) -> [[a]] -> [[([[Char]], Bool)]]
forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT a -> [[([[Char]], Bool)]]
resultiersFor [[a]]
forall a. Listable a => [[a]]
tiers
where
resultiersFor :: a -> [[([[Char]], Bool)]]
resultiersFor a
x = ([[Char]] -> [[Char]]) -> ([[Char]], Bool) -> ([[Char]], Bool)
forall {t} {a} {b}. (t -> a) -> (t, b) -> (a, b)
mapFst (Int -> a -> [Char] -> [Char]
forall a. Show a => Int -> a -> [Char] -> [Char]
showsPrec Int
11 a
x [Char]
""[Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
:) (([[Char]], Bool) -> ([[Char]], Bool))
-> [[([[Char]], Bool)]] -> [[([[Char]], Bool)]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` b -> [[([[Char]], Bool)]]
forall a. Testable a => a -> [[([[Char]], Bool)]]
resultiers (a -> b
p a
x)
mapFst :: (t -> a) -> (t, b) -> (a, b)
mapFst t -> a
f (t
x,b
y) = (t -> a
f t
x, b
y)
results :: Testable a => a -> [([String],Bool)]
results :: forall a. Testable a => a -> [([[Char]], Bool)]
results = [[([[Char]], Bool)]] -> [([[Char]], Bool)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[([[Char]], Bool)]] -> [([[Char]], Bool)])
-> (a -> [[([[Char]], Bool)]]) -> a -> [([[Char]], Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [[([[Char]], Bool)]]
forall a. Testable a => a -> [[([[Char]], Bool)]]
resultiers
counterExamples :: Testable a => Int -> a -> [[String]]
counterExamples :: forall a. Testable a => Int -> a -> [[[Char]]]
counterExamples Int
n a
p = [[[Char]]
as | ([[Char]]
as,Bool
False) <- Int -> [([[Char]], Bool)] -> [([[Char]], Bool)]
forall a. Int -> [a] -> [a]
take Int
n (a -> [([[Char]], Bool)]
forall a. Testable a => a -> [([[Char]], Bool)]
results a
p)]
counterExample :: Testable a => Int -> a -> Maybe [String]
counterExample :: forall a. Testable a => Int -> a -> Maybe [[Char]]
counterExample Int
n = [[[Char]]] -> Maybe [[Char]]
forall a. [a] -> Maybe a
listToMaybe ([[[Char]]] -> Maybe [[Char]])
-> (a -> [[[Char]]]) -> a -> Maybe [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> [[[Char]]]
forall a. Testable a => Int -> a -> [[[Char]]]
counterExamples Int
n
witnesses :: Testable a => Int -> a -> [[String]]
witnesses :: forall a. Testable a => Int -> a -> [[[Char]]]
witnesses Int
n a
p = [[[Char]]
as | ([[Char]]
as,Bool
True) <- Int -> [([[Char]], Bool)] -> [([[Char]], Bool)]
forall a. Int -> [a] -> [a]
take Int
n (a -> [([[Char]], Bool)]
forall a. Testable a => a -> [([[Char]], Bool)]
results a
p)]
witness :: Testable a => Int -> a -> Maybe [String]
witness :: forall a. Testable a => Int -> a -> Maybe [[Char]]
witness Int
n = [[[Char]]] -> Maybe [[Char]]
forall a. [a] -> Maybe a
listToMaybe ([[[Char]]] -> Maybe [[Char]])
-> (a -> [[[Char]]]) -> a -> Maybe [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> [[[Char]]]
forall a. Testable a => Int -> a -> [[[Char]]]
witnesses Int
n
holds :: Testable a => Int -> a -> Bool
holds :: forall a. Testable a => Int -> a -> Bool
holds Int
n = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (a -> [Bool]) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Bool] -> [Bool]
forall a. Int -> [a] -> [a]
take Int
n ([Bool] -> [Bool]) -> (a -> [Bool]) -> a -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([[Char]], Bool) -> Bool) -> [([[Char]], Bool)] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map ([[Char]], Bool) -> Bool
forall a b. (a, b) -> b
snd ([([[Char]], Bool)] -> [Bool])
-> (a -> [([[Char]], Bool)]) -> a -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [([[Char]], Bool)]
forall a. Testable a => a -> [([[Char]], Bool)]
results
fails :: Testable a => Int -> a -> Bool
fails :: forall a. Testable a => Int -> a -> Bool
fails Int
n = Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> Bool
forall a. Testable a => Int -> a -> Bool
holds Int
n
exists :: Testable a => Int -> a -> Bool
exists :: forall a. Testable a => Int -> a -> Bool
exists Int
n = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> (a -> [Bool]) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Bool] -> [Bool]
forall a. Int -> [a] -> [a]
take Int
n ([Bool] -> [Bool]) -> (a -> [Bool]) -> a -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([[Char]], Bool) -> Bool) -> [([[Char]], Bool)] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map ([[Char]], Bool) -> Bool
forall a b. (a, b) -> b
snd ([([[Char]], Bool)] -> [Bool])
-> (a -> [([[Char]], Bool)]) -> a -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [([[Char]], Bool)]
forall a. Testable a => a -> [([[Char]], Bool)]
results
uncurry3 :: (a->b->c->d) -> (a,b,c) -> d
uncurry3 :: forall a b c d. (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f (a
x,b
y,c
z) = a -> b -> c -> d
f a
x b
y c
z
uncurry4 :: (a->b->c->d->e) -> (a,b,c,d) -> e
uncurry4 :: forall a b c d e. (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 a -> b -> c -> d -> e
f (a
x,b
y,c
z,d
w) = a -> b -> c -> d -> e
f a
x b
y c
z d
w
uncurry5 :: (a->b->c->d->e->f) -> (a,b,c,d,e) -> f
uncurry5 :: forall a b c d e f.
(a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f
uncurry5 a -> b -> c -> d -> e -> f
f (a
x,b
y,c
z,d
w,e
v) = a -> b -> c -> d -> e -> f
f a
x b
y c
z d
w e
v
(==>) :: Bool -> Bool -> Bool
Bool
False ==> :: Bool -> Bool -> Bool
==> Bool
_ = Bool
True
Bool
True ==> Bool
p = Bool
p
infixr 0 ==>