Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created October 19, 2009 21:15
Show Gist options
  • Save abuiles/213716 to your computer and use it in GitHub Desktop.
Save abuiles/213716 to your computer and use it in GitHub Desktop.
perm :: [Int] -> [ [Int]]
perm [] = return []
perm (x:xs) = do ys <- perm xs
zs <- insert x ys
return zs
insert :: a -> [a] -> [[a]]
insert x xs = (return (x:xs))
`mplus` case xs of
[] -> mzero
(y:ys) -> liftM (y:) (insert x ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment