Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created April 25, 2011 14:17
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 jutememo/940572 to your computer and use it in GitHub Desktop.
Save jutememo/940572 to your computer and use it in GitHub Desktop.
import Control.Monad.State
update :: Int -> a -> State [a] ()
update i x = modify $ \xs -> take i xs ++ x : drop (i+1) xs
swapS i j = do xs <- get
update i (xs!!j)
update j (xs!!i)
swap i j xs = (execState $ swapS i j) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment