[Haskell-cafe] How does one delare a 2D STUArray in Haskell?

minh thu noteed at gmail.com
Fri Sep 25 02:56:25 EDT 2009


2009/9/25 Casey Hawthorne <caseyh at istar.ca>:
> How does one delare a 2D STUArray in Haskell?

Hi,

STUArray, like other arrays is parametrized by the type of the index,
the "i" in "STUArray s i e" [1]. That "i" is should be an instance of
Ix which is a class of the types that can be used as indices. If you
want to use 2D indices, that's fine as pairs (of types that are
themselves in Ix) are instances of Ix.

In your code, (Int,Int) (2d) and Word32 (1d) are the indice types. So

STUArray s (Word32,Word32) Bool

would be the 2d version of an array indiced by Word32 (that is, an
array indiced by pairs of Word32).

Cheers,
Thu

[1] http://hackage.haskell.org/packages/archive/array/0.2.0.0/doc/html/Data-Array-ST.html#t%3ASTUArray


More information about the Haskell-Cafe mailing list