Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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