Last active
February 22, 2016 11:06
-
-
Save jadlr/c1026e4bd8e6bbbddd5c to your computer and use it in GitHub Desktop.
Permutations of a certain length of a list in haskell (v2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ListPermutations where | |
listPermutations :: [a] -> Integer -> [[a]] | |
listPermutations _ 0 = [[]] | |
listPermutations [] _ = [] | |
listPermutations (x:xs) n = fmap (x:) (listPermutations xs (n - 1)) ++ listPermutations xs n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lazy, so this returns immediately: