[Haskell-cafe] Big Arrays

Henry Laxen nadine.and.henry at pobox.com
Sun Oct 3 11:54:49 EDT 2010


Dear Group,

I am trying to create a (relatively) big array, 
but it seems I cannot make anything larger 
than 2^30 or so.  Here is the code:

import Data.Word
import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Control.Exception
import Prelude hiding (catch)


t1 :: Word64 -> UArray Word64 Bool
t1 size = runSTUArray 
  (do a <- newArray (0,size) True
                         :: ST s (STUArray s Word64 Bool)
      writeArray a 0 False
      return a)

catchArrayException x = do
  let err = show (x :: SomeException)
  putStrLn $ "Exception [" ++ err ++ "]"
  return ()                           

main = do
  let a1 = t1 (2^30)
      a2 = t1 (2^31)
      a3 = t1 (2^32)
  catch (print $ (a1!0,a1!1)) catchArrayException
  catch (print $ (a2!0,a2!1)) catchArrayException
  catch (print $ (a3!0,a3!1)) catchArrayException
  

This results in:
*Main GOA> main
(False,True)
(Exception [Negative range size]
(False,Exception [Error in array index; 1 not in range [0..1)]

It looks like array ranges can only be Ints, and not Int64 or Word64 types.  
Any pointers would be appreciated.
Best wishes,
Henry Laxen





More information about the Haskell-Cafe mailing list