Skip to content

Mutable vectors #6

Description

@chris-martin

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]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good for new contributorsPull requests welcome!new exampleThis issue is about writing a new example program.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions