on master help sign in
Update documentation of Unbox for sum types
commitad84b443b08e3a78994897bbe662c0723029caa5 authorHarendra Kumar <harendra@composewell.com> dateMon 21 Aug 2023, 08:42 (3 years ago) parent43e25a1
1 file changed+22
core/src/Streamly/Internal/Data/Unbox.hs+22
core/src/Streamly/Internal/Data/Unbox.hs+22
@@ -275,10 +275,32 @@ unpin arr@(MutableByteArray marr#) =
275275-- anymore, see
276276-- https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/
277277--
278+-- = Unboxed Records =
279+--
280+-- Unboxed types can be treated as unboxed records. We can provide a more
281+-- convenient API to access different parts from the Unboxed representation
282+-- without having to unbox the entire type. The type can have nested parts
283+-- therefore, we will need a general way (some sort of lenses) to address the
284+-- parts.
285+--
286+-- = Lazy Boxing =
287+--
288+-- When converting an unboxed representation to a boxed representation we can
289+-- use lazy construction. Each constructor of the constructed computation may
290+-- just hold a lazy computation to actually construct it on demand. This could
291+-- be useful for larger structures where we may need only small parts of it.
292+--
293+-- Same thing can be done for serialize type class as well but it will require
294+-- size fields at each nesting level, aggregating the size upwards.
278295
279296-- | The 'Unbox' type class provides operations for serialization (unboxing)
280297-- and deserialization (boxing) of a fixed-length, non-recursive Haskell data
281298-- type to and from its unboxed byte representation in a mutable byte array.
299+-- Unbox uses fixed size encoding, therefore, size is independent of the value,
300+-- it can be determined solely by the type. This makes types with 'Unbox'
301+-- instances suitable for storing in arrays. Note that sum types may have
302+-- multiple constructors of different sizes, the size of the sum type is
303+-- computed as the maximum required by any constructor.
282304--
283305-- The 'peekByteIndex' read operation converts a Haskell type from its unboxed
284306-- representation stored in a mutable byte array, while the 'pokeByteIndex'