Created
November 11, 2015 14:58
-
-
Save gergoerdi/8dda25d8347c26e1d475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Vect | |
%default total | |
permutations : Vect n a -> Vect (fact n) (Vect n a) | |
permutations [] = [[]] | |
permutations {n = S n} (x :: xs) = rewrite multCommutative (S n) (fact n) in | |
concat $ map (inserts x) (permutations xs) | |
where | |
inserts : a -> Vect k a -> Vect (S k) (Vect (S k) a) | |
inserts x [] = [[x]] | |
inserts x (y :: ys) = (x :: y :: ys) :: (map (y ::) (inserts x ys)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment