So I have found a function on this forum from about 7 years ago and wanted to figure out exactly the way it works as I'm quite new to Haskell and am struggling to understand it.
truths :: Int -> [[Bool]]
truths 0 = [[]]
truths n = do
x <- [True,False]
map (x :) (truths (n - 1))
This function basically generates permutations of boolean values of given size n. So truths 3 returns [[True,True,True],[True,True,False],[True,False,True],[True,False,False],[False,True,True],[False,True,False],[False,False,True],[False,False,False]]
I have seen do being used in IO context. But I'm struggling to understand why it works the way it does here.