Perm.hs

import Data.List

permutationz [] = [[]] permutationz (x:xs) = [left ++ [x] ++ right | p <- permutationz xs, (left, right) <- splits p]

splits2 xs = zip (inits xs) (tails xs)

splits [] = [([], [])] splits (x:xs) = [([], x:xs)] ++ [(x:left, right) | (left, right) <- splits xs]

sameSplits :: [Int] -> Bool – quickCheck me sameSplits ns = splits2 ns == splits ns