on master help sign in
Update the Unbox docs about generic deriving
commitbe55a92ae8149ce84ca669f36bb0e722bb0dcbe7 authorHarendra Kumar <harendra@composewell.com> dateSat 7 Jan 2023, 10:18 (4 years ago) parent82a4167
1 file changed+11−5
core/src/Streamly/Internal/Data/Unboxed.hs+11−5
core/src/Streamly/Internal/Data/Unboxed.hs+11−5
@@ -230,20 +230,26 @@ unpin arr@(MutableByteArray marr#) =
230230
231231-- | A type implementing the 'Unbox' interface supplies operations for reading
232232-- and writing the type from and to a mutable byte array (an unboxed
233−-- representation) in memory. The read operation 'peekByteIndex' constructs the
234−-- boxed type from the mutable byte array. The write operation 'pokeByteIndex'
235−-- writes the boxed type to the mutable byte array.
233+-- representation of the type) in memory. The read operation 'peekByteIndex'
234+-- deserializes the boxed type from the mutable byte array. The write operation
235+-- 'pokeByteIndex' serializes the boxed type to the mutable byte array.
236236--
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.
238239--
240+-- >>> import GHC.Generics (Generic)
239241-- >>> :{
240242-- data Object = Object
241243-- { _int0 :: Int
242244-- , _int1 :: Int
243−-- }
245+-- } deriving Generic
244246-- :}
245247--
246248-- >>> import Streamly.Data.Array (Unbox(..))
249+-- >>> instance Unbox Object
250+--
251+-- If you want to write the instance manually:
252+--
247253-- >>> import Streamly.Internal.Data.Unboxed (castContents)
248254-- >>> :{
249255-- instance Unbox Object where