Created
November 5, 2018 23:27
-
-
Save fujidig/b6d497a66663742156712d05a7cf5341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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