{-
Âîñïîëüçîâàâøèñü ôóíêöèÿìè map è concatMap, îïðåäåëèòå ôóíêöèþ perms, êîòîðàÿ âîçâðàùàåò âñå ïåðåñòàíîâêè, êîòîðûå ìîæíî ïîëó÷èòü èç äàííîãî ñïèñêà, â ëþáîì ïîðÿäêå.

GHCi> perms [1,2,3]
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

Ñ÷èòàéòå, ÷òî âñå ýëåìåíòû â ñïèñêå óíèêàëüíû, è ÷òî äëÿ ïóñòîãî ñïèñêà èìååòñÿ îäíà ïåðåñòàíîâêà.
-}

module Demo where

perms :: [a] -> [[a]]
perms []     = [[]]
perms (x:xs) = [y | p <- perms xs, y <- interleave p]
  where
    interleave []     = [[x]]
    interleave (y:ys) = (x:y:ys) : map (y:) (interleave ys)

-- http://stackoverflow.com/a/24564307/2289640