我想在Haskell
中这样做对于MyString = "ab"
和n = 4
,结果应为>
["aaaa","aaab","aaba","aabb","abaa","abab","abba","abbb","baaa","baab","baba","babb","bbaa","bbab","bbba","bbbb"]
答案 0 :(得分:7)
replicateM 4 "ab"
给出你要求的东西。您可以从Control.Monad
。
答案 1 :(得分:1)
如果你想自己写,你可以做以下事情。
seq i xs | i > 0 = [x:ys | x <- xs, ys <- seq (i-1) xs]
| otherwise = [[]]