Home > other >  How To Set 1 Value in Massiv Array?
How To Set 1 Value in Massiv Array?

Time:03-22

I am new to Haskell and Massiv so please forgive if question is dumb.

I have a mutable array of primitives:

x = (makeVectorR P Seq (Sz 10) (\_ -> 0))

I want to set 1 value in my array. It would be nice to do something like this:

(x ! 3) = 42

Is this something that Massiv supports?

CodePudding user response:

Here's how you can create a mutable primitive array and set a single value in it:

{-# LANGUAGE TypeApplications #-}

import qualified Data.Massiv.Array.Mutable as M
import Data.Massiv.Array (P, Sz (Sz1))

main :: IO ()
main = do
  x <- M.newMArray @P (Sz1 10) 0
  M.write_ x 3 42
  • Related