[add array monad to library
John Meacham <john@repetae.net>**20060212072012] hunk ./lib/Jhc/Array.hs 4
+-- The internal array type
hunk ./lib/Jhc/Array.hs 7
+-- the built-in array quasi-monad
+data AT a
hunk ./lib/Jhc/Array.hs 11
--- | the number representing the size of the array must be less than or equal to the number of
--- elements in the list or bad stuff happens.
-foreign import primitive "unsafeNewArray__" :: Int -> [a] -> (Array__ a)
hunk ./lib/Jhc/Array.hs 12
+-- none of these routines have run-time checks
+foreign import primitive "newAT__" :: Int -> AT a -> Array__ a
+foreign import primitive "writeAT__" :: Int -> a -> AT a
+foreign import primitive "seqAT__" :: AT a -> AT a -> AT a
+foreign import primitive "doneAT__" :: Int -> a -> AT a
hunk ./lib/Jhc/Array.hs 18
+
+
+-- lookup a value in an array
hunk ./lib/Jhc/Array.hs 22
-foreign import primitive "unsafeCopyArray__" :: Int -> [Either (Int,Int,Array__ a) a] -> Array__ a
hunk ./lib/Jhc/Array.hs 24
+newArray :: [a] -> Array__ a
+newArray xs = newAT__ (length as) $ foldr assign doneAT (zip [0..] xs) where
+    assign (i,v) rs = writeAT__ i v `seqAT__` rs
+