

#Hugs 98 iomonad.c update#
Operations which create, update and query these arrays all belong to the TypeĬonstructors for mutable arrays are IOArray and IOUArray (in ) and MutableĪrrays are very similar to IORefs, only they contain multiple values. "mutable array" and is defined in the module )Īnd contains operations to update array elements in-place. The second interface is defined by the type class MArray (which stands for Together with other new array types, you need to importĭ module instead of Data.Array. Also note that to use Array type constructor We will later describe the differencesīetween them and the cases when these other types are preferable to use instead The big difference is that it is now a typeclass and there are 4Īrray type constructors, each of which implements this interface: Array, Import Data.Array buildPair :: ( Int, Int ) buildPair = let arr = listArray ( 1, 10 ) ( repeat 37 ) :: Array Int Int arr' = arr // in ( arr ! 1, arr' ! 1 ) main = print buildPair Here's a simple example of its use that prints (37,64): The first interface provided by the new array library, is definedīy the typeclass IArray (which stands for "immutable array" and definedĪnd defines the same operations that were defined for Array in However, they are actually very simple - each provides just one of two interfaces, and one of these you already know. It is no wonder that theĪrray libraries are a source of so much confusion for new Haskellers. Suffice it to say that these libraries support 9 types of arrayĬonstructors: Array, UArray, IOArray, IOUArray, STArray, STUArray,ĭiffArray, DiffUArray and StorableArray. Nowadays the main Haskell compilers, GHC and Hugs, ship withĪnd these libraries contain a new implementation of arrays which isīackward compatible with the Haskell'98 one, but which has far more features. This before proceeding to the rest of this page. Values, which are evaluated on demand, and can even contain bottom "Boxed" means that array elements are just ordinary Haskell (lazy)
#Hugs 98 iomonad.c code#
Makes it possible to use Arrays in pure functional code along with lists. There are "modification" operations,īut they just return new arrays and don't modify the original one. "Immutable" means that these arrays, like any other pureįunctional data structure, have contents fixed at construction time. Haskell'98 supports just one array constructor type, namely Array, which gives you immutableīoxed arrays.
