@@ -178,7 +178,6 @@ unpin arr@(MutableByteArray marr#) =
178178-- The Unbox type class
179179--------------------------------------------------------------------------------
180180
181−-- XXX Use Proxy type in sizeOf method.
182181-- XXX generate error if the size is < 1
183182
184183-- In theory we could convert a type to and from a byte stream and use that
@@ -257,10 +256,10 @@ unpin arr@(MutableByteArray marr#) =
257256--
258257class Unbox a where
259258 -- | Get the size.
260− sizeOf :: a -> Int
259+ sizeOf :: Proxy a -> Int
261260
262− default sizeOf :: (SizeOfRep (Rep a)) => a -> Int
263− sizeOf _ = genericSizeOf (Proxy :: Proxy a)
261+ default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int
262+ sizeOf = genericSizeOf
264263
265264 -- | Read an element of type "a" from a MutableByteArray given the byte
266265 -- index.
@@ -449,7 +448,7 @@ instance Unbox IoSubSystem where
449448 pokeByteIndex i arr a = pokeByteIndex i arr (fromEnum a)
450449
451450 {-# INLINE sizeOf #-}
452− sizeOf = sizeOf . fromEnum
451+ sizeOf _ = sizeOf (Proxy :: Proxy Int)
453452#endif
454453
455454instance Unbox Bool where
@@ -511,7 +510,7 @@ readUnsafe = Peeker (Builder step)
511510 {-# INLINE step #-}
512511 step :: forall a. Unbox a => BoundedPtr -> IO (BoundedPtr, a)
513512 step (BoundedPtr arr pos end) = do
514− let next = pos + sizeOf (undefined :: a)
513+ let next = pos + sizeOf (Proxy :: Proxy a)
515514 r <- peekByteIndex pos arr
516515 return (BoundedPtr arr next end, r)
517516
@@ -524,7 +523,7 @@ read = Peeker (Builder step)
524523 {-# INLINE step #-}
525524 step :: forall a. Unbox a => BoundedPtr -> IO (BoundedPtr, a)
526525 step (BoundedPtr arr pos end) = do
527− let next = pos + sizeOf (undefined :: a)
526+ let next = pos + sizeOf (Proxy :: Proxy a)
528527 when (next > end) $ error "peekObject reading beyond limit"
529528 r <- peekByteIndex pos arr
530529 return (BoundedPtr arr next end, r)
@@ -557,16 +556,16 @@ runPeeker (Peeker (Builder f)) ptr = fmap snd (f ptr)
557556
558557-- Does not check writing beyond bound.
559558{-# INLINE pokeBoundedPtrUnsafe #-}
560−pokeBoundedPtrUnsafe :: Unbox a => a -> BoundedPtr -> IO BoundedPtr
559+pokeBoundedPtrUnsafe :: forall a. Unbox a => a -> BoundedPtr -> IO BoundedPtr
561560pokeBoundedPtrUnsafe a (BoundedPtr arr pos end) = do
562− let next = pos + sizeOf a
561+ let next = pos + sizeOf (Proxy :: Proxy a)
563562 pokeByteIndex pos arr a
564563 return (BoundedPtr arr next end)
565564
566565{-# INLINE pokeBoundedPtr #-}
567−pokeBoundedPtr :: Unbox a => a -> BoundedPtr -> IO BoundedPtr
566+pokeBoundedPtr :: forall a. Unbox a => a -> BoundedPtr -> IO BoundedPtr
568567pokeBoundedPtr a (BoundedPtr arr pos end) = do
569− let next = pos + sizeOf a
568+ let next = pos + sizeOf (Proxy :: Proxy a)
570569 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
571570 pokeByteIndex pos arr a
572571 return (BoundedPtr arr next end)
@@ -615,7 +614,7 @@ instance SizeOfRep f => SizeOfRep (M1 i c f) where
615614-- Primitive type "a".
616615instance Unbox a => SizeOfRep (K1 i a) where
617616 {-# INLINE sizeOfRep #-}
618− sizeOfRep _ = sizeOf (undefined :: a)
617+ sizeOfRep _ = sizeOf (Proxy :: Proxy a)
619618
620619-- Void: data type without constructors. Values of this type cannot exist,
621620-- therefore the size is undefined. We should never be serializing structures
@@ -671,7 +670,7 @@ instance (MaxArity256 (SumArity (f :+: g)), SizeOfRepSum f, SizeOfRepSum g) =>
671670 {-# INLINE sizeOfRep #-}
672671 sizeOfRep _ =
673672 -- One byte for the constructor id and then the constructor value.
674− sizeOf (undefined :: Word8) +
673+ sizeOf (Proxy :: Proxy Word8) +
675674 max (sizeOfRepSum (undefined :: f x))
676675 (sizeOfRepSum (undefined :: g x))
677676