----------------------------------------------------------
-- IO wrappers for primitive operation:
--
---------

heapToArray :: a -> IO (UArray Int Word)
heapToArray x 
    = IO (\s -> 
           case serialize# x s of 
             (# s', bArr# #) -> 
                   case sizeofByteArray# bArr#  of 
                      sz# -> let -- we return a word array, need to
                                 -- adjust size. OTOH, the ByteArray
                                 -- size is always multiple of
                                 -- sizeOf(StgWord) by construction.
                                 size  = (I# sz# ) `div` 
                                            sizeOf(undefined::Word) 
                                 upper = size - 1
                             in (# s', UArray 0 upper size bArr#  #) )
heapToArray :: a -> IO (UArray Int Word)
heapToArray x 
    = IO (\s -> 
           case serialize# x s of 
             (# s', bArr# #) -> 
                   case sizeofByteArray# bArr#  of 
                      sz# -> let -- we return a word array, need to
                                 -- adjust size. OTOH, the ByteArray
                                 -- size is always multiple of
                                 -- sizeOf(StgWord) by construction.
                                 size  = (I# sz# ) `div` 
                                            sizeOf(undefined::Word) 
                                 upper = size - 1
                             in (# s', UArray 0 upper size bArr#  #) )
heapToArray x 
    = IO (\s -> 
           case serialize# x s of 
             (# s', bArr# #) -> 
                   case sizeofByteArray# bArr#  of 
                      sz# -> let -- we return a word array, need to
                                 -- adjust size. OTOH, the ByteArray
                                 -- size is always multiple of
                                 -- sizeOf(StgWord) by construction.
                                 size  = (I# sz# ) `div` 
                                            sizeOf(undefined::Word) 
                                 upper = size - 1
                             in (# s', UArray 0 upper size bArr#  #) )