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

Module containing the sum formulation companion to Composite.Records product formulation. Values of type CoRec f rs represent a single value f r for one of the rs in rs. Heavily based on the great work by Anthony Cowley in Frames.

  • 10 types
  • 1 class
  • 33 values
datadata CoRec (a :: u -> Type) (b :: [u]) where
#

CoRef f rs represents a single value of type f r for some r in rs.

Constructors

Instances3Eq, Show, NFData
valuecoRec :: r ∈ rs => f r -> CoRec f rs
#

Inject a value f r into a CoRec f rs given that r is one of the valid rs.

Equivalent to CoVal the constructor, but exists to parallel field.

valuefoldCoVal
  1. :: forall (r :: u). RElem r rs (RIndex r rs) => f r -> b
  2. -> CoRec f rs
  3. -> b
#

Apply an extraction to whatever f r is contained in the given CoRec.

For example foldCoVal getConst :: CoRec (Const a) rs -> a.

valuemapCoRec :: (forall (x :: u). f x -> g x) -> CoRec f rs -> CoRec g rs
#

Map a CoRec f to a CoRec g using a natural transform from f to g (forall x. f x -> g x).

classclass FoldRec (ss :: [u]) (ts :: [u]) where
#

Typeclass which allows folding ala foldMap over a Rec, using a CoRec as the accumulator.

Methods

  • foldRec :: (CoRec f ss -> CoRec f ss -> CoRec f ss) -> CoRec f ss -> Rec f ts -> CoRec f ss

    Given some combining function, an initial value, and a record, visit each field of the record using the combining function to accumulate the initial value or previous accumulation with the field of the record.

Instances2FoldRec
  • FoldRec ss '[]Defined in composite-base-0.8.3.0 · Composite.CoRecord
  • (t ∈ ss, FoldRec ss ts) => FoldRec ss (t ': ts)Defined in composite-base-0.8.3.0 · Composite.CoRecord
newtypenewtype Op b a
#

Helper newtype containing a function a -> b but with the type parameters flipped so Op b has a consistent codomain for a varying domain.

Constructors

valueasA :: (r ∈ rs, RMap rs, RecApplicative rs) => Field rs -> Maybe r
#

Given some target type r that's a possible value of Field rs, yield Just if that is indeed the value being stored by the Field, or Nothing if not.

newtypenewtype Case' (f :: k -> Type) b (a :: k)
#

An extractor function f a -> b which can be passed to foldCoRec to eliminate one possible alternative of a CoRec.

Constructors

Instances1Contravariant
typetype Cases' (f :: u -> Type) (rs :: [u]) b = Rec (Case' f b) rs
#

A record of Case' eliminators for each r in rs representing the pieces of a total function from CoRec f to b.

valuefoldCoRec
  1. :: RecApplicative (r ': rs)
  2. => Cases' f (r ': rs) b
  3. -> CoRec f (r ': rs)
  4. -> b
#

Fold a CoRec f using Cases' which eliminate each possible value held by the CoRec, yielding the b produced by whichever case matches.

valuematchCoRec
  1. :: RecApplicative (r ': rs)
  2. => CoRec f (r ': rs)
  3. -> Cases' f (r ': rs) b
  4. -> b
#

Fold a CoRec f using Cases' which eliminate each possible value held by the CoRec, yielding the b produced by whichever case matches.

Equivalent to foldCoRec but with its arguments flipped so it can be written matchCoRec coRec $ cases.

newtypenewtype Case b a
#

Constructors

Instances1Contravariant
valuematchField
  1. :: (RMap rs, RecApplicative (r ': rs))
  2. => Field (r ': rs)
  3. -> Cases (r ': rs) b
  4. -> b
#

Fold a Field using Cases which eliminate each possible value held by the Field, yielding the b produced by whichever case matches.

Equivalent to foldCoRec but with its arguments flipped so it can be written matchCoRec coRec $ cases.

valuevalCase :: (a -> b) -> Case b (s :-> a)
#

Specialized type of Case for Val, with the type parameters in a convenient order for type application, e.g.:

  valCase "foo" ( a -> ...)
    :& valCase "bar" ( b -> ...)
    :& RNil
valuevalCase' :: Functor f => (f a -> b) -> Case' f b (s :-> a)
#

Specialized type of Case' for Val, with the type parameters in a convenient order for type application, e.g.:

  valCase' "foo" ( fa -> ...)
    :& valCase' "bar" ( fb -> ...)
    :& RNil
valuekeywordCase' :: KnownSymbol s => (Text -> a) -> Case a (s :-> ())
#

Make a Case' which yields the symbol text for a field s :-> () as projected through the given function. E.g.:

  keywordCase @"foo" (<> "bar") (Identity (Val ())) == "foobar"