on master help sign in
Update the Unbox docs about generic deriving
be55a92Harendra Kumar
core/src/Streamly/Internal/Data/Unboxed.hs+11−5
@@ -230,20 +230,26 @@ unpin arr@(MutableByteArray marr#) =
230
230
231-- | A type implementing the 'Unbox' interface supplies operations for reading
231-- | A type implementing the 'Unbox' interface supplies operations for reading
232-- and writing the type from and to a mutable byte array (an unboxed
232-- and writing the type from and to a mutable byte array (an unboxed
233−-- representation) in memory. The read operation 'peekByteIndex' constructs the
233+-- representation of the type) in memory. The read operation 'peekByteIndex'
234−-- boxed type from the mutable byte array. The write operation 'pokeByteIndex'
234+-- deserializes the boxed type from the mutable byte array. The write operation
235−-- writes the boxed type to the mutable byte array.
235+-- 'pokeByteIndex' serializes the boxed type to the mutable byte array.
236--
236--
237−-- Here is an example, to write an instance for this type class.
237+-- Instances can be derived via 'Generic'. Here is an example, for deriving an
238+-- instance of this type class.
238--
239--
240+-- >>> import GHC.Generics (Generic)
239-- >>> :{
241-- >>> :{
240-- data Object = Object
242-- data Object = Object
241-- { _int0 :: Int
243-- { _int0 :: Int
242-- , _int1 :: Int
244-- , _int1 :: Int
243−-- }
245+-- } deriving Generic
244-- :}
246-- :}
245--
247--
246-- >>> import Streamly.Data.Array (Unbox(..))
248-- >>> import Streamly.Data.Array (Unbox(..))
249+-- >>> instance Unbox Object
250+--
251+-- If you want to write the instance manually:
252+--
247-- >>> import Streamly.Internal.Data.Unboxed (castContents)
253-- >>> import Streamly.Internal.Data.Unboxed (castContents)
248-- >>> :{
254-- >>> :{
249-- instance Unbox Object where
255-- instance Unbox Object where