upari :: [Int] -> [[(Int, Int)]] upari [] = [] upari [a, b] = [[(a, b)]] upari (a:xa) = foldl ff [] [0..length(xa) - 1] where ff :: [[(Int, Int)]] -> Int -> [[(Int, Int)]] ff acc i = acc ++ map (\res -> (a, b):res) (upari(left ++ right)) where (left, b:right) = splitAt i xa main = mapM_ print (upari [1..6])