-readWord8Array :: MutableByteArray RealWorld Int -> Int -> IO Word8
-readWord16Array :: MutableByteArray RealWorld Int -> Int -> IO Word16
-readWord32Array :: MutableByteArray RealWorld Int -> Int -> IO Word32
-readWord64Array :: MutableByteArray RealWorld Int -> Int -> IO Word64
-
-readWord8Array (MutableByteArray ixs arr#) n@(I# n#) =
- case sizeofMutableByteArray# arr# of
- bytes#
- | n# ># (bytes# -# 1#) -> ioError (userError ("readWord8Array: index out of bounds "++show n))
- | otherwise -> IO $ \ s# ->
- case readCharArray# arr# n# s# of
- (# s2# , r# #) -> (# s2# , intToWord8 (I# (ord# r#)) #)
-
-readWord16Array (MutableByteArray ixs arr#) n@(I# n#) =
- case sizeofMutableByteArray# arr# of
- bytes#
- | n# ># (bytes# `quotInt#` 2# -# 1#) -> ioError (userError ("readWord16Array: index out of bounds "++show n))
- | otherwise -> IO $ \ s# ->
- case readWordArray# arr# (n# `quotInt#` 2#) s# of
- (# s2# , w# #) ->
- case n# `remInt#` 2# of
- 0# -> (# s2# , wordToWord16 (W# w#) #) -- the double byte hides in the lower half of the wrd.
- 1# -> (# s2# , wordToWord16 (W# (shiftRL# w# 16#)) #) -- take the upper 16 bits.
-
-readWord32Array (MutableByteArray ixs arr#) n@(I# n#) =
- case sizeofMutableByteArray# arr# of
- bytes#
- | n# ># (bytes# `quotInt#` 4# -# 1#) -> ioError (userError ("readWord32Array: index out of bounds "++show n))
- | otherwise -> IO $ \ s# ->
- case readWordArray# arr# n# s# of
- (# s2# , w# #) -> (# s2# , wordToWord32 (W# w#) #)
-
+readWord8Array :: (Ix ix) => MutableByteArray s ix -> ix -> ST s Word8
+readWord16Array :: (Ix ix) => MutableByteArray s ix -> ix -> ST s Word16
+readWord32Array :: (Ix ix) => MutableByteArray s ix -> ix -> ST s Word32
+
+readWord8Array (MutableByteArray ixs arr#) n = ST $ \ s# ->
+ case (index ixs n) of { I# n# ->
+ case readCharArray# arr# n# s# of { (# s2# , r# #) ->
+ (# s2# , intToWord8 (I# (ord# r#)) #) }}
+
+
+readWord16Array (MutableByteArray ixs arr#) n = ST $ \ s# ->
+ case (index ixs n) of { I# n# ->
+ case readWordArray# arr# (n# `quotInt#` 2#) s# of { (# s2# , w# #) ->
+ case n# `remInt#` 2# of
+ 0# -> (# s2# , wordToWord16 (W# w#) #)
+ -- the double byte hides in the lower half of the wrd.
+ 1# -> (# s2# , wordToWord16 (W# (shiftRL# w# 16#)) #)
+ -- take the upper 16 bits.
+ }}
+
+readWord32Array (MutableByteArray ixs arr#) n = ST $ \ s# ->
+ case (index ixs n) of { I# n# ->
+ case readWordArray# arr# n# s# of { (# s2# , w# #) ->
+ (# s2# , wordToWord32 (W# w#) #) }}
+
+
+ -- FIXME, Num shouldn't be required, but it makes my life easier.
+readWord64Array :: (Num ix, Ix ix) => MutableByteArray s ix -> ix -> ST s Word64