main :: IO () main = print $ combi 4 ['a'..'d'] -- | Non-repeat combination select @n@ from @xs@. combi n xs = combi' 0 n xs -- | Non-repeat combinations recursing at @i@ (splitAt). combi' :: Int -> Int -> [a] -> [[a]] combi' i n xs = case splitAt i xs of ([], []) -> [] ([], hs) -> combi' (i + 1) n hs (h:hs, ts) -> ( if n == 1 then [[h]] else fmap (h :) (combi' 0 (n - 1) (hs <> ts)) ) -- keep h <> combi' 0 n (hs <> ts) -- drop h