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.XRec

A variant of Rec whose values have eliminated common syntactic clutter due to Identity, Compose, and ElField type constructors.

A common pain point with using Rec is the mandatory context of each value. A basic record might look like this, Identity "joe" :& Identity 23 :& RNil :: Rec Identity '[String, Int]. The Identity constructors are a nuisance, so we offer a way of avoiding them: "joe" ::& 23 ::& XRNil :: XRec Identity '[String,Int]. Facilities are provided for converting between XRec and Rec so that the Rec API is available even if you choose to use XRec for construction or pattern matching.

  • 2 types
  • 4 classes
  • 4 values
  • Packagevinyl-0.14.3
  • Exports12
  • LanguageHaskell2010
  • LicenceMIT
  • SourceXRec.hs
valuermapXEndo
  1. :: (XRMap f f rs, IsoXRec f rs)
  2. => forall (a :: u). HKD f a -> HKD f a
  3. -> Rec f rs
  4. -> Rec f rs
#

This is rmapX specialized to a type at which it does not change interpretation functor. This can help with type inference.

valuexrmap
  1. :: XRMap f g rs
  2. => forall (a :: u). HKD f a -> HKD g a
  3. -> XRec f rs
  4. -> XRec g rs
#

This is rmap for XRec. We apply a natural transformation between interpretation functors to transport a record value between interpretations.

newtypenewtype XData (t :: k -> Type) (a :: k)
#

A wrapper for an HKD-simplified value. That is, noisy value constructors like Identity and Compose are ellided. This is used in the xrmapAux type class method, but may be ignored by users whose needs are met by xrmap and rmapX.

Constructors

classclass XRMap (f :: u -> Type) (g :: u -> Type) (rs :: [u]) where
#

The implementation of xrmap is broken into a type class to permit unrolling of the recursion across a record. The function mapped across the vector hides the HKD type family under a newtype constructor to help the type checker.

Methods

Instances2XRMap
  • XRMap f g '[]Defined in vinyl-0.14.3 · Data.Vinyl.XRec
  • (XRMap f g rs, IsoHKD f r, IsoHKD g r) => XRMap f g (r ': rs)Defined in vinyl-0.14.3 · Data.Vinyl.XRec
classclass XRApply (f :: u -> Type) (g :: u -> Type) (rs :: [u]) where
#

Like rapply: record of components f r -> g r may be applied to a record of f to get a record of g.

Methods

Instances2XRApply
  • XRApply f g '[]Defined in vinyl-0.14.3 · Data.Vinyl.XRec
  • XRApply f g rs => XRApply f g (r ': rs)Defined in vinyl-0.14.3 · Data.Vinyl.XRec
classclass IsoXRec (f :: u -> Type) (ts :: [u]) where
#

Conversion between XRec and Rec. It is convenient to build and consume XRec values to reduce syntactic noise, but Rec has a richer API that is difficult to build around the HKD type family.

Methods

Instances2IsoXRec
  • IsoXRec f '[]Defined in vinyl-0.14.3 · Data.Vinyl.XRec
  • (IsoXRec f ts, IsoHKD f t) => IsoXRec f (t ': ts)Defined in vinyl-0.14.3 · Data.Vinyl.XRec
classclass IsoHKD (f :: k -> Type) (a :: k) where
#

Isomorphism between a syntactically noisy value and a concise one. For types like, Identity, we prefer to work with values of the underlying type without writing out the Identity constructor. For Compose f g a, aka (f :. g) a, we prefer to work directly with values of type f (g a).

This involves the so-called higher-kinded data type family. See http://reasonablypolymorphic.com/blog/higher-kinded-data for more discussion.

Associated types

  • type family HKD (f :: k -> Type) (a :: k)

Methods

Instances12IsoHKD, …
  • IsoHKD First aDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • IsoHKD Last aDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • IsoHKD Product aDefined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type Product a as if they were of type a.

  • IsoHKD Sum aDefined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type Sum a as if they were of type a.

  • IsoHKD Maybe aDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • IsoHKD IO aDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • IsoHKD Identity aDefined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type Identity a as if they were simple of type a.

  • IsoHKD (Either a) bDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • IsoHKD (Tuple2 a) bDefined in vinyl-0.14.3 · Data.Vinyl.XRec
  • (IsoHKD f (HKD g a), IsoHKD g a, Functor f) => IsoHKD (Compose f g) aDefined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type Compose f g a as if they were of type f (g a).

  • (IsoHKD f a, IsoHKD g a) => IsoHKD (Lift (->) f g) aDefined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type Lift (->) f g a as if they were of type f a -> g a.

  • KnownSymbol s => IsoHKD ElField '(s, a)Defined in vinyl-0.14.3 · Data.Vinyl.XRec

    Work with values of type ElField '(s,a) as if they were of type a.

valuergetX
  1. :: (RecElem record a a rs rs (RIndex a rs), RecElemFCtx record f, IsoHKD f a)
  2. => record f rs
  3. -> HKD f a
#

Record field getter that pipes the field value through HKD to eliminate redundant newtype wrappings. Usage will typically involve a visible type application to the field type. The definition is similar to, getHKD = toHKD . rget.