Modulevinyl-0.14.3Haskell2010
Data.Vinyl.SRec
Storable records offer an efficient flat, packed representation
in memory. In particular, field access is constant time (i.e. it
doesn't depend on where in the record the field is) and as fast as
possible, but updating fields may not be as efficient. The
requirement is that all fields of a record have Storable
instances.
The implementation leaks into the usual vinyl lens API: the
requirement of Storable instances necessitates specialization on
the functor argument of the record so that GHC can find all
required instances at compile time (this is required for
constant-time field access). What we do is allow ourselves to write
instances of the RecElem and RecSubset classes (that provide
the main vinyl lens API) that are restricted to particular choices
of the record functor. This is why the SRec2 type that implements
records here takes two functor arguments: they will usually be the
same; we fix one when writing instances and write instance contexts
that reference that type, and then require that the methods
(e.g. rget) are called on records whose functor argument is equal
to the one we picked. For usability, we provide an SRec type
whose lens API is fixed to ElField as the functor. Other
specializations are possible, and the work of those instances can
always be passed along to the SRec2 functions.
Note that the lens field accessors for SRec do not support
changing the types of the fields as they do for Rec and
ARec.
Contents
- Main record lens API
- Lens API specialized to SRec2
- Internals
Synopsis