Skip to content

Instantly share code, notes, and snippets.

@evgenii-malov
Last active September 6, 2022 15:57
Show Gist options
  • Save evgenii-malov/9093b092b8782e169eb436ebb69d8cfb to your computer and use it in GitHub Desktop.
Save evgenii-malov/9093b092b8782e169eb436ebb69d8cfb to your computer and use it in GitHub Desktop.
Work with mutable arrays in haskell examples
-- video https://youtu.be/uj2N5fBZnCA
import Data.Array.MArray
import Data.Array.IO.Internals (IOArray(IOArray))
import Control.Monad.ST
import Data.Array.ST
workio = do
a <- newArray (0,3) 'a' :: IO ( IOArray Int Char)
writeArray a 3 'x'
a_ <- getAssocs a
print a_
e <- readArray a 3
print e
workst = do
a <- newArray (0,3) 'a' :: ST s (STArray s Int Char)
writeArray a 3 'x'
getAssocs a
main = workio >> print (runST workst)
--Some links:
--https://www.haskell.org/tutorial/arrays.html
--https://mmhaskell.com/data-structures/array
--https://wiki.haskell.org/Arrays
@evgenii-malov
Copy link
Author

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