5 lines
249 B
Haskell
5 lines
249 B
Haskell
permutations :: [a] -> [[a]]
|
|
permutations = foldr (concatMap . insertEverywhere) [[]]
|
|
where insertEverywhere :: a -> [a] -> [[a]]
|
|
insertEverywhere x [] = [[x]]
|
|
insertEverywhere x l@(y:ys) = (x:l) : map (y:) (insertEverywhere x ys)
|