on master help sign in
Add cautions about Unbox type class usage
4969d04Harendra Kumar
core/src/Streamly/Internal/Data/Unboxed.hs+6−3
@@ -226,8 +226,9 @@ unpin arr@(MutableByteArray marr#) =
226-- deserializes the boxed type from the mutable byte array. The write operation
226-- deserializes the boxed type from the mutable byte array. The write operation
227-- 'pokeByteIndex' serializes the boxed type to the mutable byte array.
227-- 'pokeByteIndex' serializes the boxed type to the mutable byte array.
228--
228--
229−-- Instances can be derived via 'Generic'. Here is an example, for deriving an
229+-- Instances can be derived via 'Generic'. Note that the data type must be
230−-- instance of this type class.
230+-- non-recursive. Here is an example, for deriving an instance of this type
231+-- class.
231--
232--
232-- >>> import GHC.Generics (Generic)
233-- >>> import GHC.Generics (Generic)
233-- >>> :{
234-- >>> :{
@@ -237,6 +238,8 @@ unpin arr@(MutableByteArray marr#) =
237-- } deriving Generic
238-- } deriving Generic
238-- :}
239-- :}
239--
240--
241+-- WARNING! Generic deriving hangs for recursive data types.
242+--
240-- >>> import Streamly.Data.Array (Unbox(..))
243-- >>> import Streamly.Data.Array (Unbox(..))
241-- >>> instance Unbox Object
244-- >>> instance Unbox Object
242--
245--
@@ -255,7 +258,7 @@ unpin arr@(MutableByteArray marr#) =
255-- :}
258-- :}
256--
259--
257class Unbox a where
260class Unbox a where
258− -- | Get the size.
261+ -- | Get the size. Size cannot be zero.
259 sizeOf :: Proxy a -> Int
262 sizeOf :: Proxy a -> Int
260
263
261 default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int
264 default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int