HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

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.

  • 3 types
  • 2 classes
  • 11 values
  • Packagevinyl-0.14.3
  • Exports16
  • LanguageHaskell2010
  • LicenceMIT
  • SourceSRec.hs

Main record lens API

3 declarations
newtypenewtype SRec (f :: k -> Type) (ts :: [k])
#

A simpler type for SRec2 whose RecElem and RecSubset instances are specialized to the ElField functor.

Constructors

Instances4RecElem, RecSubset, RecElemFCtx, RecSubsetFCtx

Lens API specialized to SRec2

5 declarations

Internals

8 declarations
newtypenewtype SRec2 (g :: k -> Type) (f :: k -> Type) (ts :: [k])
#

A Storable-backed Rec. Each field of such a value has statically known size, allowing for a very efficient representation and very fast field access. The 2 suffix is due to apparently taking two functor arguments, but the first type parameter is phantom and exists so that we can write multiple instances of RecElem and RecSubset for different functors. The first functor argument will typically be identical to the second argument. We currently provide instances for the ElField functor; if you wish to use it at a different type, consider using sget, sput, and slens which work with any functor given that the necessary Storable instances exist.

Constructors

Instances4RecElem, RecSubset, RecElemFCtx, RecSubsetFCtx
classclass (RIndex t ts ~ i, RecAll f ts Storable) => FieldOffsetAux (f :: k -> Type) (ts :: [k]) (t :: k) (i :: Nat) where
#

The ability to work with a particular field of a Rec stored at a Ptr.

Methods

Instances2FieldOffsetAux
valuepokeField :: FieldOffset f ts t => ForeignPtr (Rec f ts) -> f t -> IO ()
#

Set a field in a record stored at a ForeignPtr.