Skip to content

Instantly share code, notes, and snippets.

@gergoerdi
Last active November 12, 2015 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergoerdi/161b7bc87bbbb27cd78b to your computer and use it in GitHub Desktop.
Save gergoerdi/161b7bc87bbbb27cd78b to your computer and use it in GitHub Desktop.
import Data.Vect
import Data.Fin
%default total
fins : Vect n (Fin n)
fins {n = Z} = []
fins {n = S n} = FZ :: map FS fins
permutations : {n : Nat} -> Vect (fact n) (Vect n a -> Vect n a)
permutations {n = Z} = [id]
permutations {a = a} {n = S n} =
rewrite multCommutative (S n) (fact n) in
concat $ map inserts (permutations {n = n})
where
inserts : (Vect k a -> Vect k a) -> Vect (S k) (Vect (S k) a -> Vect (S k) a)
inserts pi = map (\i => \(x :: xs) => insertAt i x (pi xs)) fins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment