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

Modulecomposite-base-0.8.3.0Haskell2010

Composite.Record

  • 5 types
  • 2 classes
  • 15 values
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

Instances27RecSubset, RecElem, MonadContext, TestCoercion, TestEquality, Eq, …
patternpattern (:*:) :: a -> Rec Identity rs -> Rec Identity ((s :-> a) ': rs)
#

Bidirectional pattern matching the first field of a record using :-> values and the Identity functor.

This pattern is bidirectional meaning you can use it either as a pattern or a constructor, e.g.

  let rec = 123 :*: Just "foo" :*: RNil
      foo :*: bar :*: RNil = rec

Mnemonic: * for products.

patternpattern (:^:) :: Functor f => f a -> Rec f rs -> Rec f ((s :-> a) ': rs)
#

Bidirectional pattern matching the first field of a record using :-> values and any functor.

This pattern is bidirectional meaning you can use it either as a pattern or a constructor, e.g.

  let rec = Just 123 :^: Just "foo" :^: RNil
      Just foo :^: Just bar :^: RNil = rec

Mnemonic: ^ for products (record) of products (functor).

newtypenewtype (:->) (s :: Symbol) a
#

Some value of type a tagged with a symbol indicating its field name or label. Used as the usual type of elements in a Rec or Record.

Recommended pronunciation: record val.

Constructors

Instances28IsoHKD, Monad, Functor, Applicative, Foldable, Traversable, …
  • KnownSymbol s => IsoHKD Identity (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Monad ((:->) s)Defined in composite-base-0.8.3.0 · Composite.Record
  • Functor ((:->) s)Defined in composite-base-0.8.3.0 · Composite.Record
  • Applicative ((:->) s)Defined in composite-base-0.8.3.0 · Composite.Record
  • Foldable ((:->) s)Defined in composite-base-0.8.3.0 · Composite.Record
  • Traversable ((:->) s)Defined in composite-base-0.8.3.0 · Composite.Record
  • Bounded a => Bounded (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Enum a => Enum (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Eq a => Eq (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Floating a => Floating (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Fractional a => Fractional (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Integral a => Integral (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Num a => Num (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Ord a => Ord (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Real a => Real (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • RealFloat a => RealFloat (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • RealFrac a => RealFrac (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • (KnownSymbol s, Show a) => Show (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • IsString a => IsString (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Semigroup a => Semigroup (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Monoid a => Monoid (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Storable a => Storable (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • NFData a => NFData (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • Wrapped (s :-> a)Defined in composite-base-0.8.3.0 · Composite.Record
  • (s1 :-> a1) ~ t => Rewrapped (s2 :-> a2) tDefined in composite-base-0.8.3.0 · Composite.Record
  • (KnownSymbol s, ReifyNames rs) => ReifyNames ((s :-> a) ': rs)Defined in composite-base-0.8.3.0 · Composite.Record
  • type Unwrapped (s :-> a) = aDefined in composite-base-0.8.3.0 · Composite.Record
  • type HKD Identity (s :-> a) = aDefined in composite-base-0.8.3.0 · Composite.Record
valueval :: a -> Identity (s :-> a)
#

Convenience function to make an Identity (s :-> a) with a particular symbol, used for named field construction.

For example:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  type FBaz = "baz" :-> Double
  type MyRecord = [FFoo, FBar, FBaz]

  myRecord1 :: Record MyRecord
  myRecord1
    =  val @"foo" 123
    :& val @"bar" "foobar"
    :& val @"baz" 3.21
    :& RNil

  myRecord2 :: Record MyRecord
  myRecord2 = rcast
    $  val @"baz" 3.21
    :& val @"foo" 123
    :& val @"bar" "foobar"
    :& RNil

In this example, both myRecord1 and myRecord2 have the same value, since rcast can reorder records.

valuevalName :: KnownSymbol s => s :-> a -> Text
#

Reflect the type level name of a named value s :-> a to a Text. For example, given "foo" :-> Int, yields "foo" :: Text

typetype RElem (r :: k) (rs :: [k]) = RElem r rs (RIndex r rs)
#

Constraint expressing that r is in rs and providing the index of r in rs. Equal to RElem rs (RIndex r rs).

valuerlens
  1. :: (Functor g, RElem (s :-> a) rs, Functor g)
  2. => proxy (s :-> a)
  3. -> a -> g a
  4. -> Rec Identity rs
  5. -> g (Rec Identity rs)
#

Lens to a particular field of a record using the Identity functor.

For example, given:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  fBar_ :: Proxy FBar
  fBar_ = Proxy

  rec :: Rec Identity '[FFoo, FBar]
  rec = 123 :*: "hello!" :*: Nil

Then:

  view (rlens fBar_)               rec == "hello!"
  set  (rlens fBar_) "goodbye!"    rec == 123 :*: "goodbye!" :*: Nil
  over (rlens fBar_) (map toUpper) rec == 123 :*: "HELLO!"   :*: Nil
valuerlensCo
  1. :: (Functor f, Functor g, RElem (s :-> a) rs)
  2. => proxy (s :-> a)
  3. -> f a -> g (f a)
  4. -> Rec f rs
  5. -> g (Rec f rs)
#

Lens to a particular field of a record using any functor.

For example, given:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  fBar_ :: Proxy FBar
  fBar_ = Proxy

  rec :: Rec Maybe '[FFoo, FBar]
  rec = Just 123 :^: Just "hello!" :^: Nil

Then:

  view (rlensCo fBar_)                      rec == Just "hello!"
  set  (rlensCo fBar_) Nothing              rec == Just 123 :^: Nothing       :^: Nil
  over (rlensCo fBar_) (fmap (map toUpper)) rec == Just 123 :^: Just "HELLO!" :^: Nil
valuerlensContra
  1. :: (Contravariant f, Functor g, RElem (s :-> a) rs)
  2. => proxy (s :-> a)
  3. -> f a -> g (f a)
  4. -> Rec f rs
  5. -> g (Rec f rs)
#

Lens to a particular field of a record using a contravariant functor.

For example, given:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  fBar_ :: Proxy FBar
  fBar_ = Proxy

  rec :: Rec Predicate '[FFoo, FBar]
  rec = Predicate even :!: Predicate (even . length) :!: Nil

Then:

  view (rlensContra fBar_)                           rec == Predicate even
  set  (rlensContra fBar_) Predicate (odd . length)  rec == Predicate even :!: Predicate (odd . length) :!: Nil
  over (rlensContra fBar_) (contramap show)          rec == Predicate even :!: Predicate (odd . length . show) :!: Nil
familytype family AllHave (cs :: [u -> Constraint]) (as :: [u]) :: Constraint where
#

Type function which produces the cross product of constraints cs and types as.

For example, AllHave '[Eq, Ord] '[Int, Text] is equivalent to (Eq Int, Ord Int, Eq Text, Ord Text)

Equations

valuereifyDicts
  1. :: (AllHave cs rs, RecApplicative rs)
  2. => proxy cs
  3. -> forall (proxy' :: u -> Type) (a :: u). HasInstances a cs => proxy' a -> f a
  4. -> Rec f rs
#

Given a list of constraints cs, apply some function for each r in the target record type rs with proof that those constraints hold for r, generating a record with the result of each application.

classclass RecWithContext (ss :: [Type]) (ts :: [Type]) where
#

Class with rmap but which gives the natural transformation evidence that the value its working over is contained within the overall record ss.

Methods

  • rmapWithContext :: proxy ss -> (forall r. r ∈ ss => f r -> g r) -> Rec f ts -> Rec g ts

    Apply a natural transformation from f to g to each field of the given record, except that the natural transformation can be mildly unnatural by having evidence that r is in ss.

Instances2RecWithContext
familytype family RDelete (r :: u) (rs :: [u]) :: [u] where
#

Type function which removes the first element r from a list rs, and doesn't expand if r is not present in rs.

Equations

typetype RDeletable (r :: k) (rs :: [k]) = (r ∈ rs, RDelete r rs ⊆ rs)
#

Constraint which reflects that an element r can be removed from rs using rdelete.