RosettaCodeData/Task/Permutations/Haskell/permutations-3.hs

6 lines
218 B
Haskell
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
permutations :: [a] -> [[a]]
permutations [] = [[]]
permutations xs = [ y:zs | (y,ys) <- select xs, zs <- permutations ys]
where select [] = []
select (x:xs) = (x,xs) : [ (y,x:ys) | (y,ys) <- select xs ]