module Test.LeanCheck.Tiers
(
listCons
, setCons
, bagCons
, mapCons
, noDupListCons
, maybeCons0
, maybeCons1
, maybeCons2
, product3
, product3With
, productMaybeWith
, listsOf
, bagsOf
, setsOf
, noDupListsOf
, products
, maps
, listsOfLength
, distinctPairs
, distinctPairsWith
, unorderedPairs
, unorderedPairsWith
, unorderedDistinctPairs
, unorderedDistinctPairsWith
, deleteT
, normalizeT
, catMaybesT
, mapMaybeT
, discardT
, discardLaterT
, nubT
, choices
, setChoices
, bagChoices
, printTiers
, showTiers
, finite
)
where
import Test.LeanCheck.Basic
import Data.Maybe (catMaybes)
listCons :: Listable a => ([a] -> b) -> [[b]]
listCons :: ([a] -> b) -> [[b]]
listCons = (([a] -> b) -> [[[a]]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
listsOf [[a]]
forall a. Listable a => [[a]]
tiers)
bagCons :: Listable a => ([a] -> b) -> [[b]]
bagCons :: ([a] -> b) -> [[b]]
bagCons = (([a] -> b) -> [[[a]]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
bagsOf [[a]]
forall a. Listable a => [[a]]
tiers)
setCons :: Listable a => ([a] -> b) -> [[b]]
setCons :: ([a] -> b) -> [[b]]
setCons = (([a] -> b) -> [[[a]]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
setsOf [[a]]
forall a. Listable a => [[a]]
tiers)
mapCons :: (Listable a, Listable b) => ([(a,b)] -> c) -> [[c]]
mapCons :: ([(a, b)] -> c) -> [[c]]
mapCons = (([(a, b)] -> c) -> [[[(a, b)]]] -> [[c]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[a]] -> [[b]] -> [[[(a, b)]]]
forall a b. [[a]] -> [[b]] -> [[[(a, b)]]]
maps [[a]]
forall a. Listable a => [[a]]
tiers [[b]]
forall a. Listable a => [[a]]
tiers)
noDupListCons :: Listable a => ([a] -> b) -> [[b]]
noDupListCons :: ([a] -> b) -> [[b]]
noDupListCons = (([a] -> b) -> [[[a]]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` [[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
noDupListsOf [[a]]
forall a. Listable a => [[a]]
tiers)
maybeCons0 :: Maybe b -> [[b]]
maybeCons0 :: Maybe b -> [[b]]
maybeCons0 Maybe b
Nothing = []
maybeCons0 (Just b
x) = [[b
x]]
maybeCons1 :: Listable a => (a -> Maybe b) -> [[b]]
maybeCons1 :: (a -> Maybe b) -> [[b]]
maybeCons1 a -> Maybe b
f = [[b]] -> [[b]]
forall a. [[a]] -> [[a]]
delay ([[b]] -> [[b]]) -> [[b]] -> [[b]]
forall a b. (a -> b) -> a -> b
$ (a -> Maybe b) -> [[a]] -> [[b]]
forall a b. (a -> Maybe b) -> [[a]] -> [[b]]
mapMaybeT a -> Maybe b
f [[a]]
forall a. Listable a => [[a]]
tiers
maybeCons2 :: (Listable a, Listable b) => (a -> b -> Maybe c) -> [[c]]
maybeCons2 :: (a -> b -> Maybe c) -> [[c]]
maybeCons2 a -> b -> Maybe c
f = [[c]] -> [[c]]
forall a. [[a]] -> [[a]]
delay ([[c]] -> [[c]]) -> [[c]] -> [[c]]
forall a b. (a -> b) -> a -> b
$ ((a, b) -> Maybe c) -> [[(a, b)]] -> [[c]]
forall a b. (a -> Maybe b) -> [[a]] -> [[b]]
mapMaybeT ((a -> b -> Maybe c) -> (a, b) -> Maybe c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> b -> Maybe c
f) [[(a, b)]]
forall a. Listable a => [[a]]
tiers
product3 :: [[a]] -> [[b]]-> [[c]] -> [[(a,b,c)]]
product3 :: [[a]] -> [[b]] -> [[c]] -> [[(a, b, c)]]
product3 = (a -> b -> c -> (a, b, c))
-> [[a]] -> [[b]] -> [[c]] -> [[(a, b, c)]]
forall a b c d.
(a -> b -> c -> d) -> [[a]] -> [[b]] -> [[c]] -> [[d]]
product3With (\a
x b
y c
z -> (a
x,b
y,c
z))
product3With :: (a->b->c->d) -> [[a]] -> [[b]] -> [[c]] -> [[d]]
product3With :: (a -> b -> c -> d) -> [[a]] -> [[b]] -> [[c]] -> [[d]]
product3With a -> b -> c -> d
f [[a]]
xss [[b]]
yss [[c]]
zss = ((c -> d) -> c -> d) -> [[c -> d]] -> [[c]] -> [[d]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (c -> d) -> c -> d
forall a b. (a -> b) -> a -> b
($) ((a -> b -> c -> d) -> [[a]] -> [[b]] -> [[c -> d]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith a -> b -> c -> d
f [[a]]
xss [[b]]
yss) [[c]]
zss
productMaybeWith :: (a->b->Maybe c) -> [[a]] -> [[b]] -> [[c]]
productMaybeWith :: (a -> b -> Maybe c) -> [[a]] -> [[b]] -> [[c]]
productMaybeWith a -> b -> Maybe c
_ [[a]]
_ [] = []
productMaybeWith a -> b -> Maybe c
_ [] [[b]]
_ = []
productMaybeWith a -> b -> Maybe 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 -> Maybe c) -> [[a]] -> [[b]] -> [[c]]
forall a b c. (a -> b -> Maybe c) -> [[a]] -> [[b]] -> [[c]]
productMaybeWith a -> b -> Maybe c
f [[a]]
xss [[b]]
yss)
where
[a]
xs ** :: [a] -> [b] -> [c]
** [b]
ys = [Maybe c] -> [c]
forall a. [Maybe a] -> [a]
catMaybes [ a -> b -> Maybe c
f a
x b
y | a
x <- [a]
xs, b
y <- [b]
ys ]
distinctPairs :: [[a]] -> [[(a,a)]]
distinctPairs :: [[a]] -> [[(a, a)]]
distinctPairs = (a -> a -> (a, a)) -> [[a]] -> [[(a, a)]]
forall a b. (a -> a -> b) -> [[a]] -> [[b]]
distinctPairsWith (,)
distinctPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
distinctPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
distinctPairsWith a -> 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 -> [[a]] -> [[b]]) -> [[a]] -> [[[[b]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith (\a
e -> (a -> b) -> [[a]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a -> a -> b
f a
e))
unorderedPairs :: [[a]] -> [[(a,a)]]
unorderedPairs :: [[a]] -> [[(a, a)]]
unorderedPairs = (a -> a -> (a, a)) -> [[a]] -> [[(a, a)]]
forall a b. (a -> a -> b) -> [[a]] -> [[b]]
unorderedPairsWith (,)
unorderedPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
unorderedPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
unorderedPairsWith a -> 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 -> [[a]] -> [[b]]) -> [[a]] -> [[[[b]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith (\a
e -> (a -> b) -> [[a]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a -> a -> b
f a
e))
unorderedDistinctPairs :: [[a]] -> [[(a,a)]]
unorderedDistinctPairs :: [[a]] -> [[(a, a)]]
unorderedDistinctPairs = (a -> a -> (a, a)) -> [[a]] -> [[(a, a)]]
forall a b. (a -> a -> b) -> [[a]] -> [[b]]
unorderedDistinctPairsWith (,)
unorderedDistinctPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
unorderedDistinctPairsWith :: (a -> a -> b) -> [[a]] -> [[b]]
unorderedDistinctPairsWith a -> 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 -> [[a]] -> [[b]]) -> [[a]] -> [[[[b]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith (\a
e -> (a -> b) -> [[a]] -> [[b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a -> a -> b
f a
e))
listsOf :: [[a]] -> [[[a]]]
listsOf :: [[a]] -> [[[a]]]
listsOf [[a]]
xss = [a] -> [[[a]]]
forall a. a -> [[a]]
cons0 []
[[[a]]] -> [[[a]]] -> [[[a]]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ [[[a]]] -> [[[a]]]
forall a. [[a]] -> [[a]]
delay ((a -> [a] -> [a]) -> [[a]] -> [[[a]]] -> [[[a]]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (:) [[a]]
xss ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
listsOf [[a]]
xss))
products :: [ [[a]] ] -> [[ [a] ]]
products :: [[[a]]] -> [[[a]]]
products = ([[a]] -> [[[a]]] -> [[[a]]]) -> [[[a]]] -> [[[a]]] -> [[[a]]]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((a -> [a] -> [a]) -> [[a]] -> [[[a]]] -> [[[a]]]
forall a b c. (a -> b -> c) -> [[a]] -> [[b]] -> [[c]]
productWith (:)) [[[]]]
deleteT :: Eq a => a -> [[a]] -> [[a]]
deleteT :: a -> [[a]] -> [[a]]
deleteT a
_ [] = []
deleteT a
y ([]:[[a]]
xss) = [] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: a -> [[a]] -> [[a]]
forall a. Eq a => a -> [[a]] -> [[a]]
deleteT a
y [[a]]
xss
deleteT a
y [[a
x]] | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = []
deleteT a
y ((a
x:[a]
xs):[[a]]
xss) | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = [a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss
| Bool
otherwise = [[a
x]] [[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ a -> [[a]] -> [[a]]
forall a. Eq a => a -> [[a]] -> [[a]]
deleteT a
y ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)
normalizeT :: [[a]] -> [[a]]
normalizeT :: [[a]] -> [[a]]
normalizeT [] = []
normalizeT [[]] = []
normalizeT [[],[]] = []
normalizeT [[],[],[]] = []
normalizeT [[],[],[],[]] = []
normalizeT [[],[],[],[], []] = []
normalizeT [[],[],[],[], [],[]] = []
normalizeT [[],[],[],[], [],[],[]] = []
normalizeT [[],[],[],[], [],[],[],[]] = []
normalizeT [[],[],[],[], [],[],[],[], []] = []
normalizeT [[],[],[],[], [],[],[],[], [],[]] = []
normalizeT [[],[],[],[], [],[],[],[], [],[],[]] = []
normalizeT [[],[],[],[], [],[],[],[], [],[],[],[]] = []
normalizeT ([a]
xs:[[a]]
xss) = [a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]] -> [[a]]
forall a. [[a]] -> [[a]]
normalizeT [[a]]
xss
catMaybesT :: [[Maybe a]] -> [[a]]
catMaybesT :: [[Maybe a]] -> [[a]]
catMaybesT = ([Maybe a] -> [a]) -> [[Maybe a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map [Maybe a] -> [a]
forall a. [Maybe a] -> [a]
catMaybes
mapMaybeT :: (a -> Maybe b) -> [[a]] -> [[b]]
mapMaybeT :: (a -> Maybe b) -> [[a]] -> [[b]]
mapMaybeT a -> Maybe b
f = [[Maybe b]] -> [[b]]
forall a. [[Maybe a]] -> [[a]]
catMaybesT ([[Maybe b]] -> [[b]]) -> ([[a]] -> [[Maybe b]]) -> [[a]] -> [[b]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> [[a]] -> [[Maybe b]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT a -> Maybe b
f
discardT :: (a -> Bool) -> [[a]] -> [[a]]
discardT :: (a -> Bool) -> [[a]] -> [[a]]
discardT a -> Bool
p = (a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> Bool) -> [[a]] -> [[a]]
filterT (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p)
discardLaterT :: (a -> a -> Bool) -> [[a]] -> [[a]]
discardLaterT :: (a -> a -> Bool) -> [[a]] -> [[a]]
discardLaterT a -> a -> Bool
d [] = []
discardLaterT a -> a -> Bool
d ([]:[[a]]
xss) = [] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: (a -> a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> a -> Bool) -> [[a]] -> [[a]]
discardLaterT a -> a -> Bool
d [[a]]
xss
discardLaterT a -> a -> Bool
d ((a
x:[a]
xs):[[a]]
xss) = [[a
x]]
[[a]] -> [[a]] -> [[a]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> a -> Bool) -> [[a]] -> [[a]]
discardLaterT a -> a -> Bool
d ((a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> Bool) -> [[a]] -> [[a]]
discardT (a -> a -> Bool
`d` a
x) ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss))
nubT :: Ord a => [[a]] -> [[a]]
nubT :: [[a]] -> [[a]]
nubT = (a -> a -> Bool) -> [[a]] -> [[a]]
forall a. (a -> a -> Bool) -> [[a]] -> [[a]]
discardLaterT a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
noDupListsOf :: [[a]] -> [[[a]]]
noDupListsOf :: [[a]] -> [[[a]]]
noDupListsOf =
([[]][[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]]]
forall a. [[[[a]]]] -> [[a]]
concatT ([[[[[a]]]]] -> [[[a]]])
-> ([[a]] -> [[[[[a]]]]]) -> [[a]] -> [[[a]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [[a]] -> [[[a]]]) -> [[a]] -> [[[[[a]]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith (\a
x [[a]]
xss -> ([a] -> [a]) -> [[[a]]] -> [[[a]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
noDupListsOf [[a]]
xss))
bagsOf :: [[a]] -> [[[a]]]
bagsOf :: [[a]] -> [[[a]]]
bagsOf = ([[]][[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]]]
forall a. [[[[a]]]] -> [[a]]
concatT ([[[[[a]]]]] -> [[[a]]])
-> ([[a]] -> [[[[[a]]]]]) -> [[a]] -> [[[a]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [[a]] -> [[[a]]]) -> [[a]] -> [[[[[a]]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith (\a
x [[a]]
xss -> ([a] -> [a]) -> [[[a]]] -> [[[a]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
bagsOf [[a]]
xss))
setsOf :: [[a]] -> [[[a]]]
setsOf :: [[a]] -> [[[a]]]
setsOf = ([[]][[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]]]
forall a. [[[[a]]]] -> [[a]]
concatT ([[[[[a]]]]] -> [[[a]]])
-> ([[a]] -> [[[[[a]]]]]) -> [[a]] -> [[[a]]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [[a]] -> [[[a]]]) -> [[a]] -> [[[[[a]]]]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith (\a
x [[a]]
xss -> ([a] -> [a]) -> [[[a]]] -> [[[a]]]
forall a b. (a -> b) -> [[a]] -> [[b]]
mapT (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
setsOf [[a]]
xss))
maps :: [[a]] -> [[b]] -> [[[(a,b)]]]
maps :: [[a]] -> [[b]] -> [[[(a, b)]]]
maps [[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)]]]
mapsFor ([[a]] -> [[[a]]]
forall a. [[a]] -> [[[a]]]
setsOf [[a]]
xss)
where
mapsFor :: [b] -> [[[(b, b)]]]
mapsFor [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)
choices :: [[a]] -> [[(a,[[a]])]]
choices :: [[a]] -> [[(a, [[a]])]]
choices = (a -> [[a]] -> (a, [[a]])) -> [[a]] -> [[(a, [[a]])]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith (,)
choicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith a -> [[a]] -> b
f [] = []
choicesWith a -> [[a]] -> b
f [[]] = []
choicesWith a -> [[a]] -> b
f ([]:[[a]]
xss) = [] [b] -> [[b]] -> [[b]]
forall a. a -> [a] -> [a]
: (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith (\a
y [[a]]
yss -> a -> [[a]] -> b
f a
y ([][a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]] -> [[a]]
forall a. [[a]] -> [[a]]
normalizeT [[a]]
yss)) [[a]]
xss
choicesWith a -> [[a]] -> b
f ((a
x:[a]
xs):[[a]]
xss) = [[a -> [[a]] -> b
f a
x ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)]]
[[b]] -> [[b]] -> [[b]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
choicesWith (\a
y ([a]
ys:[[a]]
yss) -> a -> [[a]] -> b
f a
y ((a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
ys)[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
yss)) ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)
bagChoices :: [[a]] -> [[(a,[[a]])]]
bagChoices :: [[a]] -> [[(a, [[a]])]]
bagChoices = (a -> [[a]] -> (a, [[a]])) -> [[a]] -> [[(a, [[a]])]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith (,)
bagChoicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith a -> [[a]] -> b
f [] = []
bagChoicesWith a -> [[a]] -> b
f [[]] = []
bagChoicesWith a -> [[a]] -> b
f ([]:[[a]]
xss) = [] [b] -> [[b]] -> [[b]]
forall a. a -> [a] -> [a]
: (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith (\a
y [[a]]
yss -> a -> [[a]] -> b
f a
y ([][a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
yss)) [[a]]
xss
bagChoicesWith a -> [[a]] -> b
f ((a
x:[a]
xs):[[a]]
xss) = [[a -> [[a]] -> b
f a
x ((a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs)[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)]]
[[b]] -> [[b]] -> [[b]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
bagChoicesWith a -> [[a]] -> b
f ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)
setChoices :: [[a]] -> [[(a,[[a]])]]
setChoices :: [[a]] -> [[(a, [[a]])]]
setChoices = (a -> [[a]] -> (a, [[a]])) -> [[a]] -> [[(a, [[a]])]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith (,)
setChoicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith :: (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith a -> [[a]] -> b
f [] = []
setChoicesWith a -> [[a]] -> b
f [[]] = []
setChoicesWith a -> [[a]] -> b
f ([]:[[a]]
xss) = [] [b] -> [[b]] -> [[b]]
forall a. a -> [a] -> [a]
: (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith (\a
y [[a]]
yss -> a -> [[a]] -> b
f a
y ([][a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]] -> [[a]]
forall a. [[a]] -> [[a]]
normalizeT [[a]]
yss)) [[a]]
xss
setChoicesWith a -> [[a]] -> b
f ((a
x:[a]
xs):[[a]]
xss) = [[a -> [[a]] -> b
f a
x ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)]]
[[b]] -> [[b]] -> [[b]]
forall a. [[a]] -> [[a]] -> [[a]]
\/ (a -> [[a]] -> b) -> [[a]] -> [[b]]
forall a b. (a -> [[a]] -> b) -> [[a]] -> [[b]]
setChoicesWith a -> [[a]] -> b
f ([a]
xs[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
xss)
listsOfLength :: Int -> [[a]] -> [[[a]]]
listsOfLength :: Int -> [[a]] -> [[[a]]]
listsOfLength Int
n [[a]]
xss = [[[a]]] -> [[[a]]]
forall a. [[[a]]] -> [[[a]]]
products (Int -> [[a]] -> [[[a]]]
forall a. Int -> a -> [a]
replicate Int
n [[a]]
xss)
listLines :: [String] -> String
listLines :: [String] -> String
listLines [] = String
"[]"
listLines [String
s] | Char
'\n' Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` String
s = String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]"
listLines [String]
ss = (String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]")
(String -> String) -> ([String] -> String) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines
([String] -> String)
-> ([String] -> [String]) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String -> String) -> [String] -> [String] -> [String]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith String -> String -> String
beside ([String
"[ "] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ String -> [String]
forall a. a -> [a]
repeat String
", ")
([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String]
ss
where
beside :: String -> String -> String
beside :: String -> String -> String
beside String
s = String -> String
forall a. [a] -> [a]
init
(String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines
([String] -> String) -> (String -> [String]) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> String -> String) -> [String] -> [String] -> [String]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith String -> String -> String
forall a. [a] -> [a] -> [a]
(++) ([String
s] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ String -> [String]
forall a. a -> [a]
repeat (Int -> Char -> String
forall a. Int -> a -> [a]
replicate (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) Char
' '))
([String] -> [String])
-> (String -> [String]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
showListLines :: Show a => [a] -> String
showListLines :: [a] -> String
showListLines = [String] -> String
listLines ([String] -> String) -> ([a] -> [String]) -> [a] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> String) -> [a] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map a -> String
forall a. Show a => a -> String
show
dotsLongerThan :: Int -> [String] -> [String]
dotsLongerThan :: Int -> [String] -> [String]
dotsLongerThan Int
n [String]
xs = Int -> [String] -> [String]
forall a. Int -> [a] -> [a]
take Int
n [String]
xs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
"..." | Bool -> Bool
not (Bool -> Bool) -> ([String] -> Bool) -> [String] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([String] -> Bool) -> [String] -> Bool
forall a b. (a -> b) -> a -> b
$ Int -> [String] -> [String]
forall a. Int -> [a] -> [a]
drop Int
n [String]
xs]
showTiers :: Show a => Int -> [[a]] -> String
showTiers :: Int -> [[a]] -> String
showTiers Int
n = [String] -> String
listLines ([String] -> String) -> ([[a]] -> [String]) -> [[a]] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> [String]
dotsLongerThan Int
n ([String] -> [String]) -> ([[a]] -> [String]) -> [[a]] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> String) -> [[a]] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map [a] -> String
forall a. Show a => [a] -> String
showListLines
printTiers :: Show a => Int -> [[a]] -> IO ()
printTiers :: Int -> [[a]] -> IO ()
printTiers Int
n = String -> IO ()
putStrLn (String -> IO ()) -> ([[a]] -> String) -> [[a]] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[a]] -> String
forall a. Show a => Int -> [[a]] -> String
showTiers Int
n
finite :: [[a]] -> Bool
finite :: [[a]] -> Bool
finite = [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([a] -> Bool) -> ([[a]] -> [a]) -> [[a]] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
12 ([a] -> [a]) -> ([[a]] -> [a]) -> [[a]] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[a]] -> [a]) -> ([[a]] -> [[a]]) -> [[a]] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[a]] -> [[a]]
forall a. Int -> [a] -> [a]
take Int
60