Haskell: cross product of a list with subsequences of another list
I have another question regarding generating lists of stuff from various
sources.
I have a list of variables
["a", "b", "c", "d", "e"]
and the good old tristate bool values
[Nothing, Just False, Just True].
Now I want to have a list with all subsequences of the variables list
crossed with the values list, so I get
[
[],
[("a", Nothing)],
[("a", Just False)],
[("a", Just True)],
[("b", Nothing)],
...,
[("b", Just True), ("d", Nothing), ("e", Just False)]
...,
[("a", Nothing),
("b", Nothing),
("c", Nothing),
("d", Nothing),
("e", Nothing)],
[("a", Just False),
("b", Just False),
("c", Just False),
("d", Just False),
("e", Just False)],
[("a", Just True),
("b", Just True),
("c", Just True),
("d", Just True),
("e", Just True)]
]
If it was permutations only, a call to permutations combined with a
comprehension would suffice, but I have no idea how to get the list for
the subseqences easily. I could do with using the "call to permutations +
comprehension"-approach on the lists with different sizes but that doesn't
sound very elegant.
Is there a straightfoward solution to that?
No comments:
Post a Comment