Suppose n and d are natural numbers. For some reason, I wish to enumerate all pairs (S, R) where S is a Vec<bool> of length exactly n, and R is a Vec<Vec<Vec<bool>>> of size exactly d consisting of square matrices of size exactly n * n (i.e, binary relations on n elements). Thus, I want something of type Iterator<Item=(Vec<bool>, Vec<Vec<Vec<bool>>>)>.
How do I create such an iterator that iterates through each of these objects on demand, i.e, not precompute them?
For analogy, here is how I would do this in Haskell:
type Subset = [Bool]
type Relation = [[Bool]] -- a square matrix
allSubsets :: Int -> [Subset]
allSubsets n = sequence $ replicate n [True, False]
-- all Relations between a subset of n elements and a subset of m elements
allRelations :: Int -> Int -> [Relation]
allRelations n m = sequence $ replicate n (allSubsets m)
-- all families of d relations on a set of n elements
enumerateTransitions :: Int -> Int -> [[Relation]]
enumerateTransitions n d = sequence $ replicate d (allRelations n n)
-- all possible pairs of (a subset of n elements, along with d relations on them)
enumerate :: Int -> Int -> [(Subset, [Relation])]
enumerate n d = do
finalStates <- allSubsets n
transs <- enumerateTransitions n d
pure (finalStates, transs)