Last active
September 6, 2022 15:57
-
-
Save evgenii-malov/9093b092b8782e169eb436ebb69d8cfb to your computer and use it in GitHub Desktop.
Work with mutable arrays in haskell examples
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
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
video https://youtu.be/uj2N5fBZnCA