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

Core vinyl definitions. The Rec data type is defined here, but also of interest are definitions commonly used functions like rmap, rapply, and rtraverse.

The definitions in this module are written in terms of type classes so that the definitions may be specialized to each record type at which they are used. This usually helps with runtime performance, but can slow down compilation time. If you are experiencing poor compile times, you may wish to try the semantically equivalent definitions in the Data.Vinyl.Recursive module: they should produce the same results given the same inputs as functions defined in this module, but they will not be specialized to your record type. Instead, they treat the record as a list of fields, so will have performance linear in the size of the record.

  • 4 types
  • 8 classes
  • 14 values
  • Packagevinyl-0.14.3
  • Exports29
  • LanguageHaskell2010
  • LicenceMIT
  • SourceCore.hs
datadata Rec (a :: u -> Type) (b :: [u]) where
#

A record is parameterized by a universe u, an interpretation f and a list of rows rs. The labels or indices of the record are given by inhabitants of the kind u; the type of values at any label r :: u is given by its interpretation f r :: *.

Constructors

Instances26RecSubset, RecElem, TestCoercion, TestEquality, Eq, Ord, …
valuerappend :: Rec f as -> Rec f bs -> Rec f (as ++ bs)
#

Two records may be pasted together.

valuercombine
  1. :: (RMap rs, RApply rs)
  2. => forall (a :: u). m a -> m a -> m a
  3. -> forall (a :: u). f a -> m a
  4. -> forall (a :: u). m a -> g a
  5. -> Rec f rs
  6. -> Rec f rs
  7. -> Rec g rs
#

Combine two records by combining their fields using the given function. The first argument is a binary operation for combining two values (e.g. (<>)), the second argument takes a record field into the type equipped with the desired operation, the third argument takes the combined value back to a result type.

classclass RMap (rs :: [u]) where
#

Rec _ rs with labels in kind u gives rise to a functor Hask^u -> Hask; that is, a natural transformation between two interpretation functors f,g may be used to transport a value from Rec f rs to Rec g rs.

Methods

  • rmap :: (forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
Instances2RMap
  • RMap '[]Defined in vinyl-0.14.3 · Data.Vinyl.Core
  • RMap xs => RMap (x ': xs)Defined in vinyl-0.14.3 · Data.Vinyl.Core
value(<<$>>) :: RMap rs => (forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
#

A shorthand for rmap.

value(<<&>>) :: RMap rs => Rec f rs -> (forall (x :: u). f x -> g x) -> Rec g rs
#

An inverted shorthand for rmap.

classclass RApply (rs :: [u]) where
#

A record of components f r -> g r may be applied to a record of f to get a record of g.

Methods

Instances2RApply
  • RApply '[]Defined in vinyl-0.14.3 · Data.Vinyl.Core
  • RApply xs => RApply (x ': xs)Defined in vinyl-0.14.3 · Data.Vinyl.Core
classclass RecApplicative (rs :: [u]) where
#

Given a section of some functor, records in that functor of any size are inhabited.

Methods

  • rpure :: (forall (x :: u). f x) -> Rec f rs
Instances2RecApplicative
valuertraverse
  1. :: Applicative h
  2. => forall (x :: u). f x -> h (g x)
  3. -> Rec f rs
  4. -> h (Rec g rs)
#

A record may be traversed with respect to its interpretation functor. This can be used to yank (some or all) effects from the fields of the record to the outside of the record.

valuertraverseIn
  1. :: forall (a :: u). f a -> g (ApplyToField h a)
  2. -> Rec f rs
  3. -> Rec g (MapTyCon h rs)
#

While rtraverse pulls the interpretation functor out of the record, rtraverseIn pushes the interpretation functor in to each field type. This is particularly useful when you wish to discharge that interpretation on a per-field basis. For instance, rather than a Rec IO '[a,b], you may wish to have a Rec Identity '[IO a, IO b] so that you can evaluate a single field to obtain a value of type Rec Identity '[a, IO b].

valuerzipWith
  1. :: (RMap xs, RApply xs)
  2. => forall (x :: u). f x -> g x -> h x
  3. -> Rec f xs
  4. -> Rec g xs
  5. -> Rec h xs
#

Given a natural transformation from the product of f and g to h, we have a natural transformation from the product of Rec f and Rec g to Rec h. You can also think about this operation as zipping two records with the same element types but different interpretations.

classclass RFoldMap (rs :: [u]) where
#

Map each element of a record to a monoid and combine the results.

Methods

Instances2RFoldMap
  • RFoldMap '[]Defined in vinyl-0.14.3 · Data.Vinyl.Core
  • RFoldMap xs => RFoldMap (x ': xs)Defined in vinyl-0.14.3 · Data.Vinyl.Core
datadata Dict (c :: Type -> Constraint) a where
#

Wrap up a value with a capability given by its type

Constructors

classclass ReifyConstraint (c :: Type -> Constraint) (f :: u -> Type) (rs :: [u]) where
#

Sometimes we may know something for all fields of a record, but when you expect to be able to each of the fields, you are then out of luck. Surely given ∀x:u.φ(x) we should be able to recover x:u ⊢ φ(x)! Sadly, the constraint solver is not quite smart enough to realize this and we must make it patently obvious by reifying the constraint pointwise with proof.

Methods

Instances2ReifyConstraint
valuewithPairedDict :: (c a => f a -> r) -> Product (DictOnly c) f a -> r
#

A useful technique is to use 'rmap (Pair (DictOnly MyClass))' on a Rec to pair each field with a type class dictionary for MyClass@. This helper can then be used to eliminate the original.

familytype family Head (xs :: [k]) :: k where
#

Equations

familytype family Tail (xs :: [a]) :: [a] where
#

Equations

  • Tail (_1 ': xs) = xs
typetype AllRepsMatch (f :: k -> Type) (xs :: [k]) (g :: j -> Type) (ys :: [j]) = (AllRepsMatch_ f xs g ys, AllRepsMatch_ g ys f xs)
#

AllRepsMatch f xs g ys means that xs and ys have the same lengths, and that mapping f over xs and g over ys produces lists whose corresponding elements are Coercible with each other. For example, the following hold:

AllRepsMatch Proxy '[1,2,3] Proxy '[4,5,6] AllRepsMatch Sum '[Int,Word] Identity '[Min Int, Max Word]