Skip to content

Instantly share code, notes, and snippets.

@shoooe
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoooe/961a596b5d56a24235f3 to your computer and use it in GitHub Desktop.
Save shoooe/961a596b5d56a24235f3 to your computer and use it in GitHub Desktop.
Some exercise with Haskell
-- Original question can be found here:
-- http://www.reddit.com/r/haskell/comments/2lq8dt/produce_infinite_list_with_a_string/
permWithRep :: Int -> [a] -> [[a]]
permWithRep = replicateM
allSets :: String -> [[String]]
allSets str = map (flip permWithRep $ str) [0..]
main :: IO ()
main = do
print $ take 3 . allSets $ "ab"
-- [[""],["a","b"],["aa","ab","ba","bb"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment