If I have two strings I use a list comprehension to obtain the desired result:
combineStrings firstStr sndStr = [ [a,b] | a <- firstStr, b <- sndStr]
For three strings, I use this
combineStrings firstStr sndStr trdStr = [ [a,b,c] | a <- firstStr, b <- sndStr, c <- trdStr]
What I'm trying is to obtain the same result for a variable number of strings. For example if I have a function which takes the following form:
combineStrings :: [String] -> [String]
I'm trying to obtain the same results as above for 2, 3 ... n lists... I tried multiple ways, like this one
combineStrings [] = []
combineStrings (hd:tl) = [ a:b | a <- hd, b <- combineStrings tl]
but this fails because of [] on the first clause. Can someone help me to write this, please?
combineStrings :: [[a]] -> [[a]]. Then, the first line from undur_gongor's answer can be writtencombineStrings [] = [[]]. You can also try to writecombineStringsusingfoldr, as it fits the fold pattern.