-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
good for new contributorsPull requests welcome!Pull requests welcome!new exampleThis issue is about writing a new example program.This issue is about writing a new example program.
Description
Here's an example I jotted down a while ago. A slightly more practical example might be nice, but I don't think I've ever actually used mutable vectors in Haskell, nothing is immediately coming to mind... ideas welcome.
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
main =
do
a <- MV.replicate 5 0
do a' <- V.freeze a; putStrLn ("empty: " ++ show a')
MV.write a 4 100
do a' <- V.freeze a; putStrLn ("write: " ++ show a')
do x <- MV.read a 4; putStrLn ("read: " ++ show x)
putStrLn ("length: " ++ show (MV.length a))
b <- V.thaw (V.fromList [1..5])
do b' <- V.freeze b; putStrLn ("dcl: " ++ show b')$ runhaskell vectors.hs
empty: [0,0,0,0,0]
write: [0,0,0,0,100]
read: 100
length: 5
dcl: [1,2,3,4,5]
Metadata
Metadata
Assignees
Labels
good for new contributorsPull requests welcome!Pull requests welcome!new exampleThis issue is about writing a new example program.This issue is about writing a new example program.