module Test.LeanCheck.Function.ListsOfPairs
( (-->>)
, exceptionPairs
)
where
import Test.LeanCheck
import Test.LeanCheck.Tiers
(-->>) :: Eq a => [[a]] -> [[b]] -> [[a->b]]
[[a]]
xss -->> :: [[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 (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 :: (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 (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (a, b) -> (a -> b) -> a -> b
forall t p. Eq t => (t, p) -> (t -> p) -> t -> p
mut a -> b
f [(a, b)]
ms
where
mut :: (t, p) -> (t -> p) -> t -> p
mut (t
x',p
fx') t -> p
f t
x = if t
x t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== t
x' then p
fx' else t -> p
f t
x
exceptionPairs :: [[a]] -> [[b]] -> [[ [(a,b)] ]]
exceptionPairs :: [[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 b. [b] -> [[[(b, b)]]]
exceptionsFor ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
incompleteSetsOf [[a]]
xss)
where
exceptionsFor :: [b] -> [[[(b, b)]]]
exceptionsFor [b]
xs = [b] -> [b] -> [(b, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip [b]
xs ([b] -> [(b, b)]) -> [[[b]]] -> [[[(b, b)]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[[b]]] -> [[[b]]]
forall a. [[[a]]] -> [[[a]]]
products ([[b]] -> b -> [[b]]
forall a b. a -> b -> a
const [[b]]
yss (b -> [[b]]) -> [b] -> [[[b]]]
forall a b. (a -> b) -> [a] -> [b]
`map` [b]
xs)
incompleteSetsOf :: [[a]] -> [[ [a] ]]
incompleteSetsOf :: [[a]] -> [[[a]]]
incompleteSetsOf = [[[a]]] -> [[[a]]]
forall a. [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