hpaste

recent | annotate | new

module Main where                                                                          
                                                                                           
import Data.Array.IO                                                                       
import Data.Array.Storable                                                                 
import Data.Int                                                                            
import IO                                                                                  
                                                                                           
buildTable1 :: Int -> IO (IOUArray Int Int8)
buildTable1 size = newArray (0,size-1) 0
                                                                                           
buildTable2 :: Int -> IO (StorableArray Int Int8)
buildTable2 size = newArray (0,size-1) 0
                                                                                           
go arr = do str <- getLine                                                                 
            val <- readArray arr (read str)                                                
            print val                                                                      
            writeArray arr (read str) (val+1)                                              
            go arr                                                                         
                                                                                           
--size = 4294967296 -- 4 * 2^30 (too big)
--size = 4294907296 -- Main: internal error...
size = 4290967296 -- works

main = do                                                                                  
  hSetBuffering stdout NoBuffering                                                         
  print $ ("Building table...",size)                                                       
  arr <- buildTable2 size 
  putStrLn ""                                                                              
  putStrLn "Ready."                                                                        
  go arr