Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created October 19, 2009 18:39
Show Gist options
  • Save abuiles/213605 to your computer and use it in GitHub Desktop.
Save abuiles/213605 to your computer and use it in GitHub Desktop.
perm :: MonadPlus m => [a] -> m [a]
perm [] = return []
perm (x:xs) = do ys <- perm xs
zs <- insert x ys
return zs
insert :: MonadPlus m => a -> [a] -> m [a]
insert x xs = (return (x:xs))
`mplus` case xs of
[] -> mzero
(y:ys) -> liftM (y:) (insert x ys)
*Main> perm [1..10]
<interactive>:1:0:
Ambiguous type variable `m' in the constraint:
`MonadPlus m' arising from a use of `perm' at <interactive>:1:0-11
Probable fix: add a type signature that fixes these type variable(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment