I was trying to make a truth table for a list of strings.
Say, I have a list ["a","b"]
and as an output, I want
[[("a",True),("b",True)],
[("a",True),("b",False)],
[("a",False),("b",True)],
[("a",False),("b",False)]]
Each of those instances in the truth table are a custom data type defined as
data TableRow = [(String,Bool)]
Is there any easier way of doing this? Until now I have been doing this
genRow :: [String] -> [TableRow]
genRow [] = []
genRow (x:xs) = ((makeRow x True) : genRow xs) ++
((makeRow x False) : genRow xs)
Quite obviously, this does not quite give me what I expect. Note that makeRow
just takes in a String
and a Bool
and returns a TableRow
.
Is there any cleaner way of doing this? Thanks