[Haskell-cafe] How to use STArray?

Udo Stenzel u.stenzel at web.de
Thu Aug 25 13:58:46 EDT 2005


Bayley, Alistair wrote:
> compute :: Int -> Int
> compute n = runST ( do
>     arr <- newArray (-1, 1) n
>     readArray 1 arr
>   )

You messed the argument order to readArray up.  Even with that repaired,
you'll need a type signature somewhere to help ghc resolve the
overloading of newArray and readArray, which is surprisingly tricky due
to the "s" that must not escape.  This works:

compute :: Int -> Int
compute n = runST ( do
    arr <- newArray (-1, 1) n :: ST s (STArray s Int Int)
    readArray arr 1
  )



Udo.
-- 
Mikrosoft spel chekar four sail, wurks grate!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20050825/bfc78c51/attachment.bin


More information about the Haskell-Cafe mailing list