This is Algorithm A from Functional Programs for Generating Permutations (Topor, 1982). We have implemented Algorithm A in F# as follows. let rec put (a: ‘t) (p: List<‘t>) (q: List<‘t>) : List<‘t> = if p = q then a :: q else p.Head :: (put a p.Tail q) // a: an element // p: aRead more