module Test.LeanCheck.Function.ListsOfPairs
( (-->>)
, exceptionPairs
)
where
import Test.LeanCheck
import Test.LeanCheck.Tiers
(-->>) :: Eq a => [[a]] -> [[b]] -> [[a->b]]
[[a]]
xss -->> :: forall a b. Eq a => [[a]] -> [[b]] -> [[a -> b]]
-->> [[b]]
yss
| forall a. [[a]] -> Bool
finite [[a]]
xss = forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((forall a. HasCallStack => a
undefined forall a b. Eq a => (a -> b) -> [(a, b)] -> a -> b
`mutate`) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [a] -> [b] -> [(a, b)]
zip (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[a]]
xss))
(forall a. [[[a]]] -> [[[a]]]
products forall a b. (a -> b) -> a -> b
$ forall a. Int -> a -> [a]
replicate (forall (t :: * -> *) a. Foldable t => t a -> Int
length forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[a]]
xss) [[b]]
yss)
| Bool
otherwise = forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT (\(b
r,[[b]]
yss) -> forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (forall a b. a -> b -> a
const b
r forall a b. Eq a => (a -> b) -> [(a, b)] -> a -> b
`mutate`)
(forall a b. [[a]] -> [[b]] -> [[[(a, b)]]]
exceptionPairs [[a]]
xss [[b]]
yss))
(forall a. [[a]] -> [[(a, [[a]])]]
choices [[b]]
yss)
mutate :: Eq a => (a -> b) -> [(a,b)] -> (a -> b)
mutate :: forall a b. Eq a => (a -> b) -> [(a, b)] -> a -> b
mutate a -> b
f [(a, b)]
ms = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {t} {b}. Eq t => (t, b) -> (t -> b) -> t -> b
mut a -> b
f [(a, b)]
ms
where
mut :: (t, b) -> (t -> b) -> t -> b
mut (t
x',b
fx') t -> b
f t
x = if t
x forall a. Eq a => a -> a -> Bool
== t
x' then b
fx' else t -> b
f t
x
exceptionPairs :: [[a]] -> [[b]] -> [[ [(a,b)] ]]
exceptionPairs :: forall a b. [[a]] -> [[b]] -> [[[(a, b)]]]
exceptionPairs [[a]]
xss [[b]]
yss = forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT forall {a}. [a] -> [[[(a, b)]]]
exceptionsFor (forall a. [[a]] -> [[[a]]]
incompleteSetsOf [[a]]
xss)
where
exceptionsFor :: [a] -> [[[(a, b)]]]
exceptionsFor [a]
xs = forall a b. [a] -> [b] -> [(a, b)]
zip [a]
xs forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` forall a. [[[a]]] -> [[[a]]]
products (forall a b. a -> b -> a
const [[b]]
yss forall a b. (a -> b) -> [a] -> [b]
`map` [a]
xs)
incompleteSetsOf :: [[a]] -> [[ [a] ]]
incompleteSetsOf :: forall a. [[a]] -> [[[a]]]
incompleteSetsOf = forall a. [a] -> [a]
init forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [[a]] -> [[[a]]]
setsOf