Skip to content

Commit

Permalink
Add documentation on Unbox about Template Haskell deriving
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Jul 28, 2023
1 parent 28db76c commit 1300a87
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions core/src/Streamly/Internal/Data/Unbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ unpin arr@(MutableByteArray marr#) =
-- deserializes the boxed type from the mutable byte array. The write operation
-- 'pokeByteIndex' serializes the boxed type to the mutable byte array.
--
-- Instances can be derived via 'Generic'. Note that the data type must be
-- non-recursive. Here is an example, for deriving an instance of this type
-- class.
-- Instances can be derived via Generics or Template Haskell. Note that the data
-- type must be non-recursive.
--
-- Here is an example, for deriving an instance of this type class using
-- generics:
--
-- >>> import GHC.Generics (Generic)
-- >>> :{
Expand All @@ -273,7 +275,18 @@ unpin arr@(MutableByteArray marr#) =
-- } deriving Generic
-- :}
--
-- WARNING! Generic deriving hangs for recursive data types.
-- See 'Streamly.Data.Unbox.deriveUnbox' and
-- 'Streamly.Data.Unbox.deriveUnboxWith' for deriving 'Unbox' instances using
-- Template Haskell.
--
-- Note that instances derived via Template Haskell are preferred as they are
-- more performant compared to the instances derived via Generics.
--
-- Template Haskell deriving can handle (maxBound :: Word64) number of
-- constructors whereas the Generic deriving can only handle 256.
--
-- WARNING! Generic and Template Haskell deriving, both hang for recursive data
-- types.
--
-- >>> import Streamly.Data.Array (Unbox(..))
-- >>> instance Unbox Object
Expand Down

0 comments on commit 1300a87

Please sign in to comment.