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
| [[a]] -> Bool
forall a. [[a]] -> Bool
finite [[a]]
xss = ([b] -> a -> b) -> [[[b]]] -> [[a -> b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT ((a -> b
forall a. HasCallStack => a
undefined (a -> b) -> [(a, b)] -> a -> b
forall a b. Eq a => (a -> b) -> [(a, b)] -> a -> b
`mutate`) ([(a, b)] -> a -> b) -> ([b] -> [(a, b)]) -> [b] -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [b] -> [(a, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[a]]
xss))
([[[b]]] -> [[[b]]]
forall a. [[[a]]] -> [[[a]]]
products ([[[b]]] -> [[[b]]]) -> [[[b]]] -> [[[b]]]
forall a b. (a -> b) -> a -> b
$ Int -> [[b]] -> [[[b]]]
forall a. Int -> a -> [a]
replicate ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([a] -> Int) -> [a] -> Int
forall a b. (a -> b) -> a -> b
$ [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[a]]
xss) [[b]]
yss)
| Bool
otherwise = ((b, [[b]]) -> [[a -> b]]) -> [[(b, [[b]])]] -> [[a -> b]]
forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT (\(b
r,[[b]]
yss) -> ([(a, b)] -> a -> b) -> [[[(a, b)]]] -> [[a -> b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (b -> a -> b
forall a b. a -> b -> a
const b
r (a -> b) -> [(a, b)] -> a -> b
forall a b. Eq a => (a -> b) -> [(a, b)] -> a -> b
`mutate`)
([[a]] -> [[b]] -> [[[(a, b)]]]
forall a b. [[a]] -> [[b]] -> [[[(a, b)]]]
exceptionPairs [[a]]
xss [[b]]
yss))
([[b]] -> [[(b, [[b]])]]
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 = ((a, b) -> (a -> b) -> a -> b) -> (a -> b) -> [(a, b)] -> a -> b
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (a, b) -> (a -> b) -> a -> b
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 t -> t -> Bool
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 = ([a] -> [[[(a, b)]]]) -> [[[a]]] -> [[[(a, b)]]]
forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT [a] -> [[[(a, b)]]]
forall {a}. [a] -> [[[(a, b)]]]
exceptionsFor ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
incompleteSetsOf [[a]]
xss)
where
exceptionsFor :: [a] -> [[[(a, b)]]]
exceptionsFor [a]
xs = [a] -> [b] -> [(a, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip [a]
xs ([b] -> [(a, b)]) -> [[[b]]] -> [[[(a, b)]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[[b]]] -> [[[b]]]
forall a. [[[a]]] -> [[[a]]]
products ([[b]] -> a -> [[b]]
forall a b. a -> b -> a
const [[b]]
yss (a -> [[b]]) -> [a] -> [[[b]]]
forall a b. (a -> b) -> [a] -> [b]
`map` [a]
xs)
incompleteSetsOf :: [[a]] -> [[ [a] ]]
incompleteSetsOf :: forall a. [[a]] -> [[[a]]]
incompleteSetsOf = [[[a]]] -> [[[a]]]
forall a. HasCallStack => [a] -> [a]
init ([[[a]]] -> [[[a]]]) -> ([[a]] -> [[[a]]]) -> [[a]] -> [[[a]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
setsOf