Skip to content

Instantly share code, notes, and snippets.

@fujidig
Created November 5, 2018 23:27
Show Gist options
  • Save fujidig/b6d497a66663742156712d05a7cf5341 to your computer and use it in GitHub Desktop.
Save fujidig/b6d497a66663742156712d05a7cf5341 to your computer and use it in GitHub Desktop.
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector as V
import Control.Monad.Primitive
import Control.Monad
myswap :: PrimMonad m => MV.MVector (PrimState m) a -> Int -> Int -> m ()
myswap v i j = do
a <- MV.read v i
b <- MV.read v j
MV.write v i b
MV.write v j a
main :: IO ()
main = do
array <- V.thaw $ V.fromList [100,200,300]
myswap array 0 1
frozed <- V.freeze array
let list = (V.toList frozed)
print list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment