Unboxed.foldl'
[darcs-mirrors/vector.git] / Data / Vector / Unboxed / Unbox.hs
1 {-# LANGUAGE MagicHash, UnboxedTuples #-}
2
3 module Data.Vector.Unboxed.Unbox (
4 Unbox(..)
5 ) where
6
7 import GHC.Base (
8 Int(..)
9 )
10
11 import GHC.Prim (
12 ByteArray#, MutableByteArray#, State#,
13
14 Int#, indexIntArray#, readIntArray#, writeIntArray#
15 )
16 import Data.Array.Base (
17 wORD_SCALE
18 )
19
20 class Unbox a where
21 size# :: a -> Int# -> Int#
22 at# :: ByteArray# -> Int# -> a
23 read# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
24 write# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s
25
26 instance Unbox Int where
27 size# _ = wORD_SCALE
28 at# arr# i# = I# (indexIntArray# arr# i#)
29 read# arr# i# s# = case readIntArray# arr# i# s# of
30 (# s1#, n# #) -> (# s1#, I# n# #)
31 write# arr# i# (I# n#) s# = writeIntArray# arr# i# n# s#
32